| @@ 15-47 (lines=33) @@ | ||
| 12 | * |
|
| 13 | * @author gbprod <[email protected]> |
|
| 14 | */ |
|
| 15 | class AndXBuilder implements Builder |
|
| 16 | { |
|
| 17 | /** |
|
| 18 | * @var Registry |
|
| 19 | */ |
|
| 20 | private $registry; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param Registry $registry |
|
| 24 | */ |
|
| 25 | public function __construct(Registry $registry) |
|
| 26 | { |
|
| 27 | $this->registry = $registry; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * {inheritdoc} |
|
| 32 | */ |
|
| 33 | public function build(Specification $spec, QueryBuilder $qb) |
|
| 34 | { |
|
| 35 | if (!$spec instanceof AndX) { |
|
| 36 | throw new \InvalidArgumentException(); |
|
| 37 | } |
|
| 38 | ||
| 39 | $firstPartBuilder = $this->registry->getBuilder($spec->getFirstPart()); |
|
| 40 | $secondPartBuilder = $this->registry->getBuilder($spec->getFirstPart()); |
|
| 41 | ||
| 42 | return $qb->query()->bool() |
|
| 43 | ->addMust($firstPartBuilder->build($spec->getFirstPart(), $qb)) |
|
| 44 | ->addMust($secondPartBuilder->build($spec->getSecondPart(), $qb)) |
|
| 45 | ; |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| @@ 15-47 (lines=33) @@ | ||
| 12 | * |
|
| 13 | * @author gbprod <[email protected]> |
|
| 14 | */ |
|
| 15 | class OrXBuilder implements Builder |
|
| 16 | { |
|
| 17 | /** |
|
| 18 | * @var Registry |
|
| 19 | */ |
|
| 20 | private $registry; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param Registry $registry |
|
| 24 | */ |
|
| 25 | public function __construct(Registry $registry) |
|
| 26 | { |
|
| 27 | $this->registry = $registry; |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * {inheritdoc} |
|
| 32 | */ |
|
| 33 | public function build(Specification $spec, QueryBuilder $qb) |
|
| 34 | { |
|
| 35 | if (!$spec instanceof OrX) { |
|
| 36 | throw new \InvalidArgumentException(); |
|
| 37 | } |
|
| 38 | ||
| 39 | $firstPartBuilder = $this->registry->getBuilder($spec->getFirstPart()); |
|
| 40 | $secondPartBuilder = $this->registry->getBuilder($spec->getFirstPart()); |
|
| 41 | ||
| 42 | return $qb->query()->bool() |
|
| 43 | ->addShould($firstPartBuilder->build($spec->getFirstPart(), $qb)) |
|
| 44 | ->addShould($secondPartBuilder->build($spec->getSecondPart(), $qb)) |
|
| 45 | ; |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||