1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GBProd\DoctrineSpecification; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\QueryBuilder; |
8
|
|
|
use Doctrine\ORM\Query\Expr\Base; |
9
|
|
|
use GBProd\DoctrineSpecification\QueryFactory\AndXFactory; |
10
|
|
|
use GBProd\DoctrineSpecification\QueryFactory\Factory; |
11
|
|
|
use GBProd\DoctrineSpecification\QueryFactory\NotFactory; |
12
|
|
|
use GBProd\DoctrineSpecification\QueryFactory\OrXFactory; |
13
|
|
|
use GBProd\Specification\AndX; |
14
|
|
|
use GBProd\Specification\Not; |
15
|
|
|
use GBProd\Specification\OrX; |
16
|
|
|
use GBProd\Specification\Specification; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Handler for doctrine specifications |
20
|
|
|
* |
21
|
|
|
* @author gbprod <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class Handler |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Registry |
27
|
|
|
*/ |
28
|
|
|
private $registry; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var QueryBuilder |
32
|
|
|
*/ |
33
|
|
|
private $qb; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Registry $registry |
37
|
|
|
* @param QueryBuilder $qb |
38
|
|
|
*/ |
39
|
3 |
|
public function __construct(Registry $registry, QueryBuilder $qb) |
40
|
|
|
{ |
41
|
3 |
|
$this->registry = $registry; |
42
|
3 |
|
$this->qb = $qb; |
43
|
|
|
|
44
|
3 |
|
$this->registry->register(AndX::class, new AndXFactory($registry)); |
45
|
3 |
|
$this->registry->register(OrX::class, new OrXFactory($registry)); |
46
|
3 |
|
$this->registry->register(Not::class, new NotFactory($registry)); |
47
|
3 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* handle specification for queryfactory |
51
|
|
|
* |
52
|
|
|
* @param Specification $spec |
53
|
|
|
* |
54
|
|
|
* @return Base |
|
|
|
|
55
|
|
|
*/ |
56
|
1 |
|
public function handle(Specification $spec) |
57
|
|
|
{ |
58
|
1 |
|
$factory = $this->registry->getFactory($spec); |
59
|
|
|
|
60
|
1 |
|
return $factory->create($spec, $this->qb); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Register a factory for specification |
65
|
|
|
* |
66
|
|
|
* @param string $classname specification fully qualified classname |
67
|
|
|
* @param Factory $factory |
68
|
|
|
*/ |
69
|
2 |
|
public function registerFactory($classname, Factory $factory) |
70
|
|
|
{ |
71
|
2 |
|
$this->registry->register($classname, $factory); |
72
|
2 |
|
} |
73
|
|
|
} |
74
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.