-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Collection improvements (#94) * Added common AbstractCollection * CR Fixes * Migrating ResultCollection * Improvements in chain searching * CellCollection introduced * Added missing PHPDocs * Added PHPDoc and documentation * Composer improvements * Documentation typo fix * PSR-2 code style fixes. Scrolling Searching Context * Lowest version of ruflin/elastica upgraded to 2.1 * Added example QueryBuilderSearchingContext definition * Added dummy example of KnpPaginatorAdapter configuration and usage * Added warning about changing SearchingContext class
- Loading branch information
1 parent
d14d29d
commit 0e0537e
Showing
51 changed files
with
779 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace KGzocha\Searcher; | ||
|
||
/** | ||
* @author Krzysztof Gzocha <[email protected]> | ||
*/ | ||
abstract class AbstractCollection implements \Countable, \IteratorAggregate | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $items; | ||
|
||
/** | ||
* @param \Traversable|array $items | ||
*/ | ||
public function __construct($items = []) | ||
{ | ||
$this->items = []; | ||
$this->isTraversable($items); | ||
$this->checkItems($items); | ||
|
||
$this->items = $items; | ||
} | ||
|
||
/** | ||
* @param object $item | ||
* | ||
* @return bool | ||
*/ | ||
abstract protected function isItemValid($item); | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIterator() | ||
{ | ||
return new \ArrayIterator($this->items); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function count() | ||
{ | ||
return count($this->items); | ||
} | ||
|
||
/** | ||
* @param mixed $item | ||
* | ||
* @return $this | ||
*/ | ||
protected function addItem($item) | ||
{ | ||
$this->items[] = $item; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $item | ||
* | ||
* @return $this | ||
*/ | ||
protected function addNamedItem($name, $item) | ||
{ | ||
$this->items[$name] = $item; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getItems() | ||
{ | ||
return $this->items; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return mixed|null | ||
*/ | ||
protected function getNamedItem($name) | ||
{ | ||
if (array_key_exists($name, $this->items)) { | ||
return $this->items[$name]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param mixed $items | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
private function isTraversable($items) | ||
{ | ||
if (is_array($items)) { | ||
return; | ||
} | ||
|
||
if ($items instanceof \Traversable) { | ||
return; | ||
} | ||
|
||
throw new \InvalidArgumentException(sprintf( | ||
'Argument passed to collection %s needs to be an array or traversable object', | ||
get_class($this) | ||
)); | ||
} | ||
|
||
/** | ||
* @param array|\Traversable $items | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
private function checkItems($items) | ||
{ | ||
foreach ($items as $item) { | ||
if ($this->isItemValid($item)) { | ||
continue; | ||
} | ||
|
||
throw new \InvalidArgumentException(sprintf( | ||
'At least one item in collection "%s" is invalid.', | ||
get_class($this) | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
* It represents single cell in the chain. It holds sub-searcher and it's transformer, which will | ||
* transform results from it's sub-searcher to CriteriaCollection that can be used in next sub-search. | ||
* Name of the cell will be used as the key of end result collection to allow finding all the results. | ||
* | ||
* | ||
* @author Krzysztof Gzocha <[email protected]> | ||
*/ | ||
class Cell implements CellInterface | ||
|
@@ -23,24 +23,16 @@ class Cell implements CellInterface | |
*/ | ||
private $transformer; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @param SearcherInterface $searcher | ||
* @param TransformerInterface $transformer | ||
* @param string $name | ||
*/ | ||
public function __construct( | ||
SearcherInterface $searcher, | ||
TransformerInterface $transformer, | ||
$name = null | ||
TransformerInterface $transformer | ||
) { | ||
$this->searcher = $searcher; | ||
$this->transformer = $transformer; | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
|
@@ -59,14 +51,6 @@ public function getTransformer() | |
return $this->transformer; | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.