Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
229 additions
and
229 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Matiux/DDDStarterPack/Aggregate/Domain/Repository/Filter/FilterApplier.php
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DDDStarterPack\Aggregate\Domain\Repository\Filter; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface FilterApplier | ||
{ | ||
public function key(): string; | ||
|
||
/** | ||
* @param T $target | ||
* @param FilterApplierRegistry $filterApplierRegistry | ||
*/ | ||
public function apply($target, FilterApplierRegistry $filterApplierRegistry): void; | ||
|
||
public function supports(FilterApplierRegistry $filterApplierRegistry): 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
53 changes: 53 additions & 0 deletions
53
src/Matiux/DDDStarterPack/Aggregate/Domain/Repository/Filter/FilterBuilder.php
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DDDStarterPack\Aggregate\Domain\Repository\Filter; | ||
|
||
use InvalidArgumentException; | ||
use LogicException; | ||
use Traversable; | ||
|
||
class FilterBuilder | ||
{ | ||
/** @var FilterApplier[] */ | ||
protected array $filterAppliers = []; | ||
|
||
protected bool $frozen = false; | ||
|
||
/** | ||
* @param FilterApplier[]|Traversable<FilterApplier> $filterAppliers | ||
*/ | ||
public function __construct($filterAppliers = []) | ||
{ | ||
if ($filterAppliers instanceof Traversable) { | ||
$filterAppliers = iterator_to_array($filterAppliers); | ||
} | ||
|
||
foreach ($filterAppliers as $applier) { | ||
$this->addApplier($applier); | ||
} | ||
} | ||
|
||
public function addApplier(FilterApplier $filterApplier): void | ||
{ | ||
if ($this->frozen) { | ||
throw new LogicException('The builder is frozen'); | ||
} | ||
|
||
$key = $filterApplier->key(); | ||
|
||
if (isset($this->filterAppliers[$key])) { | ||
throw new InvalidArgumentException("Applier for key '{$key}' is already set"); | ||
} | ||
|
||
$this->filterAppliers[$key] = $filterApplier; | ||
} | ||
|
||
public function build(array $neededFilters): FilterApplierRegistry | ||
{ | ||
$this->frozen = true; | ||
|
||
return new FilterApplierRegistry(array_values($this->filterAppliers), $neededFilters); | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
src/Matiux/DDDStarterPack/Aggregate/Domain/Repository/Filter/FilterParamsApplier.php
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
src/Matiux/DDDStarterPack/Aggregate/Domain/Repository/Filter/FilterParamsBuilder.php
This file was deleted.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
...StarterPack/Aggregate/Infrastructure/Doctrine/Repository/Filter/DoctrineFilterApplier.php
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DDDStarterPack\Aggregate\Infrastructure\Doctrine\Repository\Filter; | ||
|
||
use DDDStarterPack\Aggregate\Domain\Repository\Filter\FilterApplier; | ||
use DDDStarterPack\Aggregate\Domain\Repository\Filter\FilterApplierRegistry; | ||
use Doctrine\ORM\QueryBuilder; | ||
|
||
/** | ||
* @implements FilterApplier<QueryBuilder> | ||
*/ | ||
abstract class DoctrineFilterApplier implements FilterApplier | ||
{ | ||
/** | ||
* @param QueryBuilder $target | ||
* @param FilterApplierRegistry $filterApplierRegistry | ||
*/ | ||
abstract public function apply($target, FilterApplierRegistry $filterApplierRegistry): void; | ||
} |
Oops, something went wrong.