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