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
|
21 |
View Code Duplication |
public function __construct(FactoryInterface $factory, |
|
|
|
|
32
|
|
|
DIInvokerInterface $diInvoker, |
33
|
|
|
Cache $cache, |
34
|
|
|
array $annotations = null |
35
|
|
|
) |
36
|
|
|
{ |
37
|
21 |
|
if($annotations){ |
38
|
11 |
|
parent::__construct($annotations, $cache); |
39
|
11 |
|
}else{ |
40
|
10 |
|
parent::__construct(self::$DEFAULT_ANNOTATIONS, $cache); |
41
|
|
|
} |
42
|
21 |
|
$this->factory = $factory; |
43
|
21 |
|
$this->diInvoker = $diInvoker; |
44
|
21 |
|
} |
45
|
|
|
/** |
46
|
|
|
* load from class with local cache |
47
|
|
|
* @param string $className |
48
|
|
|
* @return EntityContainer |
49
|
|
|
*/ |
50
|
18 |
|
public function build($className) |
51
|
|
|
{ |
52
|
18 |
|
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
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.