1 | <?php |
||
36 | 1 | final class DoctrineBlameableExtension extends DI\CompilerExtension |
|
37 | { |
||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public function getConfigSchema() : Schema\Schema |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function loadConfiguration() : void |
||
55 | { |
||
56 | 1 | $builder = $this->getContainerBuilder(); |
|
57 | 1 | $configuration = $this->getConfig(); |
|
58 | |||
59 | 1 | $builder->addDefinition($this->prefix('configuration')) |
|
60 | 1 | ->setType(DoctrineBlameable\Configuration::class) |
|
61 | 1 | ->setArguments([ |
|
62 | 1 | $configuration->userEntity, |
|
63 | 1 | $configuration->lazyAssociation, |
|
64 | 1 | $configuration->automapField, |
|
65 | ]); |
||
66 | |||
67 | 1 | $userCallable = NULL; |
|
68 | |||
69 | 1 | if ($configuration->userCallable !== NULL) { |
|
70 | 1 | $definition = $builder->addDefinition($this->prefix(md5($configuration->userCallable))); |
|
71 | |||
72 | 1 | [$factory] = DI\Helpers::filterArguments([ |
|
|
|||
73 | 1 | is_string($configuration->userCallable) ? new DI\Definitions\Statement($configuration->userCallable) : $configuration->userCallable, |
|
74 | ]); |
||
75 | |||
76 | 1 | $definition->setFactory($factory); |
|
77 | |||
78 | 1 | [$resolverClass] = (array) $this->normalizeEntity($definition->getFactory()); |
|
79 | |||
80 | if (class_exists($resolverClass)) { |
||
81 | $definition->setType($resolverClass); |
||
82 | } |
||
83 | |||
84 | $userCallable = $definition; |
||
85 | } |
||
86 | |||
87 | $builder->addDefinition($this->prefix('driver')) |
||
88 | ->setType(Mapping\Driver\Blameable::class); |
||
89 | |||
90 | $builder->addDefinition($this->prefix('subscriber')) |
||
91 | ->setType(Events\BlameableSubscriber::class) |
||
92 | ->setArguments([$userCallable instanceof DI\Definitions\ServiceDefinition ? '@' . $userCallable->getType() : NULL]); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function beforeCompile() : void |
||
107 | |||
108 | /** |
||
109 | * @param Nette\Configurator $config |
||
110 | * @param string $extensionName |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | public static function register( |
||
122 | |||
123 | /** |
||
124 | * @param $entity |
||
125 | * |
||
126 | * @return string|array Class, @service, [Class, member], [@service, member], [, globalFunc], [Statement, member] |
||
127 | */ |
||
128 | private function normalizeEntity($entity) |
||
163 | } |
||
164 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.