1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpBoot\Entity; |
4
|
|
|
|
5
|
|
|
use DI\FactoryInterface; |
6
|
|
|
use DI\InvokerInterface as DIInvokerInterface; |
7
|
|
|
use Doctrine\Common\Cache\Cache; |
8
|
|
|
use PhpBoot\Entity\Annotations\ClassAnnotationHandler; |
9
|
|
|
use PhpBoot\Entity\Annotations\PropertyAnnotationHandler; |
10
|
|
|
use PhpBoot\Entity\Annotations\ValidateAnnotationHandler; |
11
|
|
|
use PhpBoot\Entity\Annotations\VarAnnotationHandler; |
12
|
|
|
use PhpBoot\Annotation\ContainerBuilder; |
13
|
|
|
|
14
|
|
|
class EntityContainerBuilder extends ContainerBuilder |
15
|
|
|
{ |
16
|
|
|
static $DEFAULT_ANNOTATIONS=[ |
|
|
|
|
17
|
|
|
[ClassAnnotationHandler::class, 'class'], |
18
|
|
|
[PropertyAnnotationHandler::class, 'properties'], |
19
|
|
|
[VarAnnotationHandler::class, "properties.*.children[?name=='var'][]"], |
20
|
|
|
[ValidateAnnotationHandler::class, "properties.*.children[?name=='v'][]"], |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ControllerContainerBuilder constructor. |
25
|
|
|
* @param FactoryInterface $factory |
26
|
|
|
* @param DIInvokerInterface $diInvoker |
27
|
|
|
* @param Cache $cache |
28
|
|
|
* |
29
|
|
|
* @param array $annotations |
30
|
|
|
*/ |
31
|
19 |
View Code Duplication |
public function __construct(FactoryInterface $factory, |
|
|
|
|
32
|
|
|
DIInvokerInterface $diInvoker, |
33
|
|
|
Cache $cache, |
34
|
|
|
array $annotations = null |
35
|
|
|
) |
36
|
|
|
{ |
37
|
19 |
|
if($annotations){ |
38
|
10 |
|
parent::__construct($annotations, $cache); |
39
|
10 |
|
}else{ |
40
|
9 |
|
parent::__construct(self::$DEFAULT_ANNOTATIONS, $cache); |
41
|
|
|
} |
42
|
19 |
|
$this->factory = $factory; |
43
|
19 |
|
$this->diInvoker = $diInvoker; |
44
|
19 |
|
} |
45
|
|
|
/** |
46
|
|
|
* load from class with local cache |
47
|
|
|
* @param string $className |
48
|
|
|
* @return EntityContainer |
49
|
|
|
*/ |
50
|
17 |
|
public function build($className) |
51
|
|
|
{ |
52
|
17 |
|
return parent::build($className); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param $className |
57
|
|
|
* @return EntityContainer |
58
|
|
|
*/ |
59
|
9 |
|
public function buildWithoutCache($className) |
60
|
|
|
{ |
61
|
9 |
|
return parent::buildWithoutCache($className); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $className |
66
|
|
|
* @return EntityContainer |
67
|
|
|
*/ |
68
|
7 |
|
protected function createContainer($className) |
69
|
|
|
{ |
70
|
7 |
|
return $this->factory->make(EntityContainer::class, ['className'=>$className]); |
71
|
|
|
} |
72
|
|
|
|
73
|
9 |
|
protected function handleAnnotation($handlerName, $container, $ann) |
74
|
|
|
{ |
75
|
9 |
|
$handler = $this->factory->make($handlerName); |
76
|
9 |
|
return $this->diInvoker->call($handler, [$container, $ann]); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var FactoryInterface |
82
|
|
|
*/ |
83
|
|
|
protected $factory; |
84
|
|
|
/** |
85
|
|
|
* @var DIInvokerInterface |
86
|
|
|
*/ |
87
|
|
|
protected $diInvoker; |
88
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.