@@ -161,12 +161,12 @@ public function getAliases(): array
161161 * @param string[]
162162 * @return static
163163 */
164- public function addExcludedClasses (array $ classes )
164+ public function addExcludedClasses (array $ types )
165165 {
166- foreach ($ classes as $ class ) {
167- if (class_exists ($ class ) || interface_exists ($ class )) {
168- $ class = Helpers::normalizeClass ($ class );
169- $ this ->excludedClasses += class_parents ($ class ) + class_implements ($ class ) + [$ class => $ class ];
166+ foreach ($ types as $ type ) {
167+ if (class_exists ($ type ) || interface_exists ($ type )) {
168+ $ type = Helpers::normalizeClass ($ type );
169+ $ this ->excludedClasses += class_parents ($ type ) + class_implements ($ type ) + [$ type => $ type ];
170170 }
171171 }
172172 return $ this ;
@@ -183,56 +183,56 @@ public function addExcludedClasses(array $classes)
183183 * @return string|null service name or null
184184 * @throws ServiceCreationException
185185 */
186- public function getByType (string $ class , bool $ throw = false )
186+ public function getByType (string $ type , bool $ throw = false )
187187 {
188- $ class = Helpers::normalizeClass ($ class );
188+ $ type = Helpers::normalizeClass ($ type );
189189
190190 if ($ this ->currentService !== null
191- && is_a ($ this ->definitions [$ this ->currentService ]->getType (), $ class , true )
191+ && is_a ($ this ->definitions [$ this ->currentService ]->getType (), $ type , true )
192192 ) {
193193 return $ this ->currentService ;
194194 }
195195
196- $ classes = $ this ->getClassList ();
197- if (empty ($ classes [ $ class ][true ])) {
196+ $ types = $ this ->getClassList ();
197+ if (empty ($ types [ $ type ][true ])) {
198198 if ($ throw ) {
199- throw new MissingServiceException ("Service of type ' $ class ' not found. " );
199+ throw new MissingServiceException ("Service of type ' $ type ' not found. " );
200200 }
201201 return ;
202202
203- } elseif (count ($ classes [ $ class ][true ]) === 1 ) {
204- return $ classes [ $ class ][true ][0 ];
203+ } elseif (count ($ types [ $ type ][true ]) === 1 ) {
204+ return $ types [ $ type ][true ][0 ];
205205
206206 } else {
207- $ list = $ classes [ $ class ][true ];
207+ $ list = $ types [ $ type ][true ];
208208 $ hint = count ($ list ) === 2 && ($ tmp = strpos ($ list [0 ], '. ' ) xor strpos ($ list [1 ], '. ' ))
209209 ? '. If you want to overwrite service ' . $ list [$ tmp ? 0 : 1 ] . ', give it proper name. '
210210 : '' ;
211- throw new ServiceCreationException ("Multiple services of type $ class found: " . implode (', ' , $ list ) . $ hint );
211+ throw new ServiceCreationException ("Multiple services of type $ type found: " . implode (', ' , $ list ) . $ hint );
212212 }
213213 }
214214
215215
216216 /**
217217 * Gets the service definition of the specified type.
218218 */
219- public function getDefinitionByType (string $ class ): ServiceDefinition
219+ public function getDefinitionByType (string $ type ): ServiceDefinition
220220 {
221- return $ this ->getDefinition ($ this ->getByType ($ class , true ));
221+ return $ this ->getDefinition ($ this ->getByType ($ type , true ));
222222 }
223223
224224
225225 /**
226226 * Gets the service names and definitions of the specified type.
227227 * @return ServiceDefinition[]
228228 */
229- public function findByType (string $ class ): array
229+ public function findByType (string $ type ): array
230230 {
231- $ class = Helpers::normalizeClass ($ class );
231+ $ type = Helpers::normalizeClass ($ type );
232232 $ found = [];
233- $ classes = $ this ->getClassList ();
234- if (!empty ($ classes [ $ class ])) {
235- foreach (array_merge (...array_values ($ classes [ $ class ])) as $ name ) {
233+ $ types = $ this ->getClassList ();
234+ if (!empty ($ types [ $ type ])) {
235+ foreach (array_merge (...array_values ($ types [ $ type ])) as $ name ) {
236236 $ found [$ name ] = $ this ->definitions [$ name ];
237237 }
238238 }
@@ -270,7 +270,7 @@ public function getClassList(): array
270270
271271
272272 /**
273- * Generates $dependencies, $classes and normalizes class names.
273+ * Generates $dependencies, $classList and normalizes class names.
274274 * @return void
275275 * @internal
276276 */
@@ -314,30 +314,30 @@ public function prepareClassList()
314314
315315 // resolve and check classes
316316 foreach ($ this ->definitions as $ name => $ def ) {
317- $ this ->resolveServiceClass ($ name );
317+ $ this ->resolveServiceType ($ name );
318318 }
319319
320320 // build auto-wiring list
321321 $ this ->classList = $ preferred = [];
322322 foreach ($ this ->definitions as $ name => $ def ) {
323- if ($ class = $ def ->getImplement () ?: $ def ->getType ()) {
323+ if ($ type = $ def ->getImplement () ?: $ def ->getType ()) {
324324 $ defAutowired = $ def ->getAutowired ();
325325 if (is_array ($ defAutowired )) {
326- foreach ($ defAutowired as $ k => $ aclass ) {
327- if ($ aclass === self ::THIS_SERVICE ) {
328- $ defAutowired [$ k ] = $ class ;
329- } elseif (!is_a ($ class , $ aclass , true )) {
330- throw new ServiceCreationException ("Incompatible class $ aclass in autowiring definition of service ' $ name'. " );
326+ foreach ($ defAutowired as $ k => $ autowiredType ) {
327+ if ($ autowiredType === self ::THIS_SERVICE ) {
328+ $ defAutowired [$ k ] = $ type ;
329+ } elseif (!is_a ($ type , $ autowiredType , true )) {
330+ throw new ServiceCreationException ("Incompatible class $ autowiredType in autowiring definition of service ' $ name'. " );
331331 }
332332 }
333333 }
334334
335- foreach (class_parents ($ class ) + class_implements ($ class ) + [$ class ] as $ parent ) {
335+ foreach (class_parents ($ type ) + class_implements ($ type ) + [$ type ] as $ parent ) {
336336 $ autowired = $ defAutowired && empty ($ this ->excludedClasses [$ parent ]);
337337 if ($ autowired && is_array ($ defAutowired )) {
338338 $ autowired = false ;
339- foreach ($ defAutowired as $ aclass ) {
340- if (is_a ($ parent , $ aclass , true )) {
339+ foreach ($ defAutowired as $ autowiredType ) {
340+ if (is_a ($ parent , $ autowiredType , true )) {
341341 if (empty ($ preferred [$ parent ]) && isset ($ this ->classList [$ parent ][true ])) {
342342 $ this ->classList [$ parent ][false ] = array_merge (...$ this ->classList [$ parent ]);
343343 $ this ->classList [$ parent ][true ] = [];
@@ -403,7 +403,7 @@ private function resolveImplement(ServiceDefinition $def, $name)
403403 if (!$ def ->getEntity ()) {
404404 $ def ->setFactory ($ def ->getType (), $ def ->getFactory () ? $ def ->getFactory ()->arguments : []);
405405 }
406- if (($ class = $ this ->resolveEntityClass ($ def ->getFactory (), [$ name => 1 ]))
406+ if (($ class = $ this ->resolveEntityType ($ def ->getFactory (), [$ name => 1 ]))
407407 && ($ ctor = (new ReflectionClass ($ class ))->getConstructor ())
408408 ) {
409409 foreach ($ ctor ->getParameters () as $ param ) {
@@ -436,45 +436,45 @@ private function resolveImplement(ServiceDefinition $def, $name)
436436
437437
438438 /** @return string|null */
439- private function resolveServiceClass ($ name , array $ recursive = [])
439+ private function resolveServiceType ($ name , array $ recursive = [])
440440 {
441441 if (isset ($ recursive [$ name ])) {
442442 throw new ServiceCreationException (sprintf ('Circular reference detected for services: %s. ' , implode (', ' , array_keys ($ recursive ))));
443443 }
444444 $ recursive [$ name ] = true ;
445445
446446 $ def = $ this ->definitions [$ name ];
447- $ factoryClass = $ def ->getFactory () ? $ this ->resolveEntityClass ($ def ->getFactory ()->getEntity (), $ recursive ) : null ; // call always to check entities
448- if ($ class = $ def ->getType () ?: $ factoryClass ) {
449- if (!class_exists ($ class ) && !interface_exists ($ class )) {
450- throw new ServiceCreationException ("Class or interface ' $ class ' used in service ' $ name' not found. " );
447+ $ factoryClass = $ def ->getFactory () ? $ this ->resolveEntityType ($ def ->getFactory ()->getEntity (), $ recursive ) : null ; // call always to check entities
448+ if ($ type = $ def ->getType () ?: $ factoryClass ) {
449+ if (!class_exists ($ type ) && !interface_exists ($ type )) {
450+ throw new ServiceCreationException ("Class or interface ' $ type ' used in service ' $ name' not found. " );
451451 }
452- $ class = Helpers::normalizeClass ($ class );
453- $ def ->setType ($ class );
452+ $ type = Helpers::normalizeClass ($ type );
453+ $ def ->setType ($ type );
454454 if (count ($ recursive ) === 1 ) {
455- $ this ->addDependency (new ReflectionClass ($ factoryClass ?: $ class ));
455+ $ this ->addDependency (new ReflectionClass ($ factoryClass ?: $ type ));
456456 }
457457
458458 } elseif ($ def ->getAutowired ()) {
459459 throw new ServiceCreationException ("Unknown type of service ' $ name', declare return type of factory method (for PHP 5 use annotation @return) " );
460460 }
461- return $ class ;
461+ return $ type ;
462462 }
463463
464464
465465 /** @return string|null */
466- private function resolveEntityClass ($ entity , array $ recursive = [])
466+ private function resolveEntityType ($ entity , array $ recursive = [])
467467 {
468468 $ entity = $ this ->normalizeEntity ($ entity instanceof Statement ? $ entity ->getEntity () : $ entity );
469469 $ serviceName = current (array_slice (array_keys ($ recursive ), -1 ));
470470
471471 if (is_array ($ entity )) {
472472 if (($ service = $ this ->getServiceName ($ entity [0 ])) || $ entity [0 ] instanceof Statement) {
473- $ entity [0 ] = $ this ->resolveEntityClass ($ entity [0 ], $ recursive );
473+ $ entity [0 ] = $ this ->resolveEntityType ($ entity [0 ], $ recursive );
474474 if (!$ entity [0 ]) {
475475 return ;
476476 } elseif (isset ($ this ->definitions [$ service ]) && $ this ->definitions [$ service ]->getImplement ()) { // @Implement::create
477- return $ entity [1 ] === 'create ' ? $ this ->resolveServiceClass ($ service , $ recursive ) : null ;
477+ return $ entity [1 ] === 'create ' ? $ this ->resolveServiceType ($ service , $ recursive ) : null ;
478478 }
479479 }
480480
@@ -503,7 +503,7 @@ private function resolveEntityClass($entity, array $recursive = [])
503503 }
504504 return $ this ->definitions [$ service ]->getImplement ()
505505 ?: $ this ->definitions [$ service ]->getType ()
506- ?: $ this ->resolveServiceClass ($ service , $ recursive );
506+ ?: $ this ->resolveServiceType ($ service , $ recursive );
507507
508508 } elseif (is_string ($ entity )) { // class
509509 if (!class_exists ($ entity )) {
@@ -619,11 +619,11 @@ public function completeStatement(Statement $statement): Statement
619619 if (!$ arguments && substr ($ entity [1 ], -2 ) === '[] ' ) {
620620 throw new ServiceCreationException ("Missing argument for $ entity [1 ]. " );
621621 }
622- } elseif ($ class = empty ($ service ) || $ entity [1 ] === 'create '
623- ? $ this ->resolveEntityClass ($ entity [0 ])
622+ } elseif ($ type = empty ($ service ) || $ entity [1 ] === 'create '
623+ ? $ this ->resolveEntityType ($ entity [0 ])
624624 : $ this ->definitions [$ service ]->getType ()
625625 ) {
626- $ arguments = $ this ->autowireArguments ($ class , $ entity [1 ], $ arguments );
626+ $ arguments = $ this ->autowireArguments ($ type , $ entity [1 ], $ arguments );
627627 }
628628 }
629629
0 commit comments