@@ -45,7 +45,7 @@ class ContainerBuilder
4545 /** @var string[] of classes excluded from auto-wiring */
4646 private $ excludedClasses = [];
4747
48- /** @var array of file names */
48+ /** @var array */
4949 private $ dependencies = [];
5050
5151 /** @var Nette\PhpGenerator\ClassType[] */
@@ -296,7 +296,7 @@ public function autowireArguments($class, $method, array $arguments)
296296 if (!$ rm ->isPublic ()) {
297297 throw new ServiceCreationException ("$ class:: $ method() is not callable. " );
298298 }
299- $ this ->addDependency (( string ) $ rm-> getFileName () );
299+ $ this ->addDependency ($ rm );
300300 return Helpers::autowireArguments ($ rm , $ arguments , $ this );
301301 }
302302
@@ -384,10 +384,6 @@ public function prepareClassList()
384384 }
385385 }
386386 }
387-
388- foreach ($ this ->classList as $ class => $ foo ) {
389- $ this ->addDependency ((string ) (new ReflectionClass ($ class ))->getFileName ());
390- }
391387 }
392388
393389
@@ -399,6 +395,7 @@ private function resolveImplement(ServiceDefinition $def, $name)
399395 }
400396 self ::checkCase ($ interface );
401397 $ rc = new ReflectionClass ($ interface );
398+ $ this ->addDependency ($ rc );
402399 $ method = $ rc ->hasMethod ('create ' )
403400 ? $ rc ->getMethod ('create ' )
404401 : ($ rc ->hasMethod ('get ' ) ? $ rc ->getMethod ('get ' ) : NULL );
@@ -474,13 +471,16 @@ private function resolveServiceClass($name, $recursive = [])
474471 $ recursive [$ name ] = TRUE ;
475472
476473 $ def = $ this ->definitions [$ name ];
477- $ class = $ def ->getFactory () ? $ this ->resolveEntityClass ($ def ->getFactory ()->getEntity (), $ recursive ) : NULL ; // call always to check entities
478- if ($ class = $ def ->getClass () ?: $ class ) {
474+ $ factoryClass = $ def ->getFactory () ? $ this ->resolveEntityClass ($ def ->getFactory ()->getEntity (), $ recursive ) : NULL ; // call always to check entities
475+ if ($ class = $ def ->getClass () ?: $ factoryClass ) {
479476 $ def ->setClass ($ class );
480477 if (!class_exists ($ class ) && !interface_exists ($ class )) {
481478 throw new ServiceCreationException ("Type $ class used in service ' $ name' not found or is not class or interface. " );
482479 }
483480 self ::checkCase ($ class );
481+ if (count ($ recursive ) === 1 ) {
482+ $ this ->addDependency (new ReflectionClass ($ factoryClass ?: $ class ));
483+ }
484484
485485 } elseif ($ def ->getAutowired ()) {
486486 trigger_error ("Type of service ' $ name' is unknown. " , E_USER_NOTICE );
@@ -517,6 +517,7 @@ private function resolveEntityClass($entity, $recursive = [])
517517 throw new ServiceCreationException (sprintf ("Factory '%s' used in service '%s' is not callable. " , Nette \Utils \Callback::toString ($ entity ), $ name [0 ]));
518518 }
519519
520+ $ this ->addDependency ($ reflection );
520521 return PhpReflection::getReturnType ($ reflection );
521522
522523 } elseif ($ service = $ this ->getServiceName ($ entity )) { // alias or factory
@@ -610,7 +611,7 @@ public function completeStatement(Statement $statement)
610611 $ visibility = $ rm ->isProtected () ? 'protected ' : 'private ' ;
611612 throw new ServiceCreationException ("Class $ entity has $ visibility constructor. " );
612613 } elseif ($ constructor = (new ReflectionClass ($ entity ))->getConstructor ()) {
613- $ this ->addDependency (( string ) $ constructor-> getFileName () );
614+ $ this ->addDependency ($ constructor );
614615 $ arguments = Helpers::autowireArguments ($ constructor , $ arguments , $ this );
615616 } elseif ($ arguments ) {
616617 throw new ServiceCreationException ("Unable to pass arguments, class $ entity has no constructor. " );
@@ -630,7 +631,7 @@ public function completeStatement(Statement $statement)
630631 }
631632
632633 $ rf = new \ReflectionFunction ($ entity [1 ]);
633- $ this ->addDependency (( string ) $ rf-> getFileName () );
634+ $ this ->addDependency ($ rf );
634635 $ arguments = Helpers::autowireArguments ($ rf , $ arguments , $ this );
635636
636637 } else {
@@ -704,25 +705,25 @@ public function addExcludedClasses(array $classes)
704705
705706
706707 /**
707- * Adds a file to the list of dependencies.
708+ * Adds item to the list of dependencies.
709+ * @param ReflectionClass|\ReflectionFunctionAbstract|string
708710 * @return self
709711 * @internal
710712 */
711- public function addDependency ($ file )
713+ public function addDependency ($ dep )
712714 {
713- $ this ->dependencies [$ file ] = TRUE ;
715+ $ this ->dependencies [] = $ dep ;
714716 return $ this ;
715717 }
716718
717719
718720 /**
719- * Returns the list of dependent files .
721+ * Returns the list of dependencies .
720722 * @return array
721723 */
722724 public function getDependencies ()
723725 {
724- unset($ this ->dependencies [FALSE ]);
725- return array_keys ($ this ->dependencies );
726+ return $ this ->dependencies ;
726727 }
727728
728729
0 commit comments