1 | <?php |
||
18 | class ServiceProviderLoader |
||
19 | { |
||
20 | /** |
||
21 | * @var Compiler |
||
22 | */ |
||
23 | private $compiler; |
||
24 | |||
25 | /** |
||
26 | * @var DefinitionConverterInterface |
||
27 | */ |
||
28 | private $converter; |
||
29 | |||
30 | /** |
||
31 | * @param Compiler $compiler |
||
32 | */ |
||
33 | public function __construct(Compiler $compiler, DefinitionConverterInterface $converter) |
||
38 | |||
39 | /** |
||
40 | * Loads the registry into the container. |
||
41 | * |
||
42 | * @param Registry $registry |
||
43 | */ |
||
44 | public function loadFromRegistry(Registry $registry) |
||
50 | |||
51 | /** |
||
52 | * @param ServiceProvider $serviceProvider |
||
53 | * @param int $serviceProviderKey |
||
54 | */ |
||
55 | private function loadServiceProvider(ServiceProvider $serviceProvider, $serviceProviderKey) |
||
63 | |||
64 | /** |
||
65 | * @param string $serviceName |
||
66 | * @param ServiceProvider $serviceProvider |
||
|
|||
67 | * @param int $serviceProviderKey |
||
68 | * @param callable $callable |
||
69 | * |
||
70 | * @throws \TheCodingMachine\Yaco\CompilerException |
||
71 | */ |
||
72 | private function registerService($serviceName, $serviceProviderKey, callable $callable) |
||
73 | { |
||
74 | if (!$this->compiler->has($serviceName)) { |
||
75 | $definition = $this->getServiceDefinitionFromCallable($serviceName, $serviceName, $serviceProviderKey, $callable, new ContainerDefinition()); |
||
76 | |||
77 | $this->compiler->addDumpableDefinition($definition); |
||
78 | } else { |
||
79 | // The new service will be created under the name 'xxx_decorated_y' |
||
80 | // The old service will be moved to the name 'xxx_decorated_y.inner' |
||
81 | // This old service will be accessible through a callback represented by 'xxx_decorated_y.callbackwrapper' |
||
82 | // The $servicename becomes an alias pointing to 'xxx_decorated_y' |
||
83 | |||
84 | $previousDefinition = $this->compiler->getDumpableDefinition($serviceName); |
||
85 | /*while ($previousDefinition instanceof Reference) { |
||
86 | $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias()); |
||
87 | }*/ |
||
88 | |||
89 | while ($previousDefinition instanceof AliasDefinition) { |
||
90 | $previousDefinition = $this->compiler->getDumpableDefinition($previousDefinition->getAlias()); |
||
91 | } |
||
92 | |||
93 | $oldServiceName = $serviceName; |
||
94 | $decoratedServiceName = $this->getDecoratedServiceName($serviceName); |
||
95 | //$innerName = $decoratedServiceName.'.inner'; |
||
96 | //$callbackWrapperName = $decoratedServiceName.'.callbackwrapper'; |
||
97 | |||
98 | // TODO: it would be way easier if we could simply rename a definition!!! |
||
99 | if ($previousDefinition instanceof FactoryCallDefinition) { |
||
100 | $innerDefinition = new FactoryCallDefinition(null /*$innerName*/, $previousDefinition->getFactory(), $previousDefinition->getMethodName(), $previousDefinition->getMethodArguments()); |
||
101 | // @codeCoverageIgnoreStart |
||
102 | } elseif ($previousDefinition instanceof ServiceFromRegistryDefinition) { |
||
103 | // @codeCoverageIgnoreEnd |
||
104 | $innerDefinition = new ServiceFromRegistryDefinition(null /*$innerName*/, $previousDefinition->getServiceName(), $previousDefinition->getServiceProviderKey(), $previousDefinition->getCallbackWrapperDefinition()); |
||
105 | } else { |
||
106 | // @codeCoverageIgnoreStart |
||
107 | throw new CompilerException('Unable to rename definition from class '.get_class($previousDefinition)); |
||
108 | // @codeCoverageIgnoreEnd |
||
109 | } |
||
110 | |||
111 | $callbackWrapperDefinition = new CallbackWrapperDefinition(null /*$callbackWrapperName*/, $innerDefinition); |
||
112 | |||
113 | $definition = $this->getServiceDefinitionFromCallable($decoratedServiceName, $serviceName, $serviceProviderKey, $callable, new ContainerDefinition(), $callbackWrapperDefinition); |
||
114 | |||
115 | $this->compiler->addDumpableDefinition($definition); |
||
116 | //$this->compiler->addDumpableDefinition($innerDefinition); |
||
117 | //$this->compiler->addDumpableDefinition($callbackWrapperDefinition); |
||
118 | $this->compiler->addDumpableDefinition(new AliasDefinition($oldServiceName, $decoratedServiceName)); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param $serviceName |
||
124 | * @param int $serviceProviderKey |
||
125 | * @param callable $callable |
||
126 | * @param ContainerDefinition $containerDefinition |
||
127 | * @param CallbackWrapperDefinition|null $callbackWrapperDefinition |
||
128 | * |
||
129 | * @return DumpableInterface |
||
130 | */ |
||
131 | private function getServiceDefinitionFromCallable($decoratedServiceName, $serviceName, $serviceProviderKey, callable $callable, ContainerDefinition $containerDefinition, CallbackWrapperDefinition $callbackWrapperDefinition = null) |
||
158 | |||
159 | /** |
||
160 | * @param string $serviceName |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | private function getDecoratedServiceName($serviceName) |
||
173 | } |
||
174 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.