1 | <?php |
||
36 | 1 | final class DoctrineBlameableExtension extends DI\CompilerExtension |
|
37 | { |
||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $defaults = [ |
||
42 | 'lazyAssociation' => FALSE, |
||
43 | 'userEntity' => NULL, |
||
44 | 'automapField' => TRUE, |
||
45 | 'userCallable' => Security\UserCallable::class, |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * @return void |
||
50 | * |
||
51 | * @throws Utils\AssertionException |
||
52 | */ |
||
53 | public function loadConfiguration() : void |
||
54 | { |
||
55 | // Get container builder |
||
56 | 1 | $builder = $this->getContainerBuilder(); |
|
57 | |||
58 | // Merge extension default config |
||
59 | 1 | $this->setConfig(DI\Config\Helpers::merge($this->config, DI\Helpers::expand($this->defaults, $builder->parameters))); |
|
60 | |||
61 | // Get extension configuration |
||
62 | 1 | $configuration = $this->getConfig(); |
|
63 | |||
64 | 1 | Utils\Validators::assert($configuration['userEntity'], 'type|null', 'userEntity'); |
|
65 | 1 | Utils\Validators::assert($configuration['lazyAssociation'], 'bool', 'lazyAssociation'); |
|
66 | 1 | Utils\Validators::assert($configuration['automapField'], 'bool', 'automapField'); |
|
67 | |||
68 | 1 | $builder->addDefinition($this->prefix('configuration')) |
|
69 | 1 | ->setType(DoctrineBlameable\Configuration::class) |
|
70 | 1 | ->setArguments([ |
|
71 | 1 | $configuration['userEntity'], |
|
72 | 1 | $configuration['lazyAssociation'], |
|
73 | 1 | $configuration['automapField'] |
|
74 | ]); |
||
75 | |||
76 | 1 | $userCallable = NULL; |
|
77 | |||
78 | 1 | if ($configuration['userCallable'] !== NULL) { |
|
79 | 1 | $definition = $builder->addDefinition($this->prefix(md5($configuration['userCallable']))); |
|
80 | |||
81 | 1 | list($factory) = DI\Helpers::filterArguments([ |
|
82 | 1 | is_string($configuration['userCallable']) ? new DI\Statement($configuration['userCallable']) : $configuration['userCallable'] |
|
83 | ]); |
||
84 | |||
85 | 1 | $definition->setFactory($factory); |
|
86 | |||
87 | 1 | list($resolverClass) = (array) $this->normalizeEntity($definition->getFactory()->getEntity()); |
|
88 | |||
89 | 1 | if (class_exists($resolverClass)) { |
|
90 | 1 | $definition->setType($resolverClass); |
|
91 | } |
||
92 | |||
93 | 1 | $userCallable = $definition; |
|
94 | } |
||
95 | |||
96 | 1 | $builder->addDefinition($this->prefix('driver')) |
|
97 | 1 | ->setType(Mapping\Driver\Blameable::class); |
|
98 | |||
99 | 1 | $builder->addDefinition($this->prefix('subscriber')) |
|
100 | 1 | ->setType(Events\BlameableSubscriber::class) |
|
101 | 1 | ->setArguments([$userCallable instanceof DI\ServiceDefinition ? '@' . $userCallable->getType() : NULL]); |
|
|
|||
102 | 1 | } |
|
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function beforeCompile() : void |
||
108 | { |
||
109 | 1 | parent::beforeCompile(); |
|
110 | |||
111 | 1 | $builder = $this->getContainerBuilder(); |
|
112 | |||
113 | 1 | $builder->getDefinition($builder->getByType('Doctrine\ORM\EntityManagerInterface', TRUE)) |
|
114 | 1 | ->addSetup('?->getEventManager()->addEventSubscriber(?)', ['@self', $builder->getDefinition($this->prefix('subscriber'))]); |
|
115 | 1 | } |
|
116 | |||
117 | /** |
||
118 | * @param Nette\Configurator $config |
||
119 | * @param string $extensionName |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | public static function register(Nette\Configurator $config, string $extensionName = 'doctrineBlameable') : void |
||
129 | |||
130 | /** |
||
131 | * @return string|array Class, @service, [Class, member], [@service, member], [, globalFunc], [Statement, member] |
||
132 | */ |
||
133 | private function normalizeEntity($entity) |
||
156 | } |
||
157 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.