1 | <?php |
||
19 | final class FiltersExtension extends CompilerExtension |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @var DefinitionFinder |
||
24 | */ |
||
25 | private $definitionFinder; |
||
26 | |||
27 | |||
28 | 3 | public function loadConfiguration() |
|
29 | { |
||
30 | 3 | $containerBuilder = $this->getContainerBuilder(); |
|
31 | 3 | $services = $this->loadFromFile(__DIR__ . '/../config/services.neon'); |
|
32 | 3 | $this->compiler->parseServices($containerBuilder, $services); |
|
33 | |||
34 | 3 | $this->definitionFinder = new DefinitionFinder($containerBuilder); |
|
35 | 3 | } |
|
36 | |||
37 | |||
38 | 2 | public function beforeCompile() |
|
39 | { |
||
40 | 2 | $containerBuilder = $this->getContainerBuilder(); |
|
41 | |||
42 | 2 | $definitionFinder = new DefinitionFinder($containerBuilder); |
|
43 | 2 | $filterManagerDefinition = $definitionFinder->getDefinitionByType(FilterManagerInterface::class); |
|
44 | 2 | $ormConfigurationDefinition = $definitionFinder->getDefinitionByType(Configuration::class); |
|
45 | |||
46 | 2 | foreach ($containerBuilder->findByType(FilterInterface::class) as $name => $filterDefinition) { |
|
47 | // 1) to filter manager to run conditions and enable allowed only |
||
48 | 2 | $filterManagerDefinition->addSetup('addFilter', [$name, '@' . $name]); |
|
49 | // 2) to Doctrine itself |
||
50 | 2 | $ormConfigurationDefinition->addSetup('addFilter', [$name, $filterDefinition->getClass()]); |
|
51 | } |
||
52 | |||
53 | 2 | $this->passFilterManagerToListener(); |
|
54 | 2 | } |
|
55 | |||
56 | |||
57 | /** |
||
58 | * Prevents circular reference. |
||
59 | */ |
||
60 | 2 | private function passFilterManagerToListener() |
|
72 | |||
73 | } |
||
74 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.