| @@ 19-52 (lines=34) @@ | ||
| 16 | use Doctrine\ORM\QueryBuilder; |
|
| 17 | use Happyr\DoctrineSpecification\Exception\InvalidArgumentException; |
|
| 18 | ||
| 19 | class QueryModifierCollection implements QueryModifier |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @var QueryModifier[] |
|
| 23 | */ |
|
| 24 | private $children; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Construct it with one or more instances of QueryModifier. |
|
| 28 | */ |
|
| 29 | public function __construct() |
|
| 30 | { |
|
| 31 | // NEXT_MAJOR: use variable-length argument lists (...$children) |
|
| 32 | $this->children = func_get_args(); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @param QueryBuilder $qb |
|
| 37 | * @param string $dqlAlias |
|
| 38 | */ |
|
| 39 | public function modify(QueryBuilder $qb, $dqlAlias) |
|
| 40 | { |
|
| 41 | foreach ($this->children as $child) { |
|
| 42 | if (!$child instanceof QueryModifier) { |
|
| 43 | throw new InvalidArgumentException(sprintf( |
|
| 44 | 'Child passed to QueryModifierCollection must be an instance of %s, but instance of %s found', |
|
| 45 | QueryModifier::class, |
|
| 46 | get_class($child) |
|
| 47 | )); |
|
| 48 | } |
|
| 49 | ||
| 50 | $child->modify($qb, $dqlAlias); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 19-51 (lines=33) @@ | ||
| 16 | use Doctrine\ORM\AbstractQuery; |
|
| 17 | use Happyr\DoctrineSpecification\Exception\InvalidArgumentException; |
|
| 18 | ||
| 19 | class ResultModifierCollection implements ResultModifier |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @var ResultModifier[] |
|
| 23 | */ |
|
| 24 | private $children; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * Construct it with one or more instances of ResultModifier. |
|
| 28 | */ |
|
| 29 | public function __construct() |
|
| 30 | { |
|
| 31 | // NEXT_MAJOR: use variable-length argument lists (...$children) |
|
| 32 | $this->children = func_get_args(); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * @param AbstractQuery $query |
|
| 37 | */ |
|
| 38 | public function modify(AbstractQuery $query) |
|
| 39 | { |
|
| 40 | foreach ($this->children as $child) { |
|
| 41 | if (!$child instanceof ResultModifier) { |
|
| 42 | throw new InvalidArgumentException(sprintf( |
|
| 43 | 'Child passed to ResultModifierCollection must be an instance of %s, but instance of %s found', |
|
| 44 | ResultModifier::class, |
|
| 45 | get_class($child) |
|
| 46 | )); |
|
| 47 | } |
|
| 48 | ||
| 49 | $child->modify($query); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||