src/Container.php
protected function circularDependencyResolver($class)
    {
        if (!is_string($class) && !class_exists($class)) {
            throw Internal\Exception\ReflectionExceptionFactory::invalidArgument(
                sprintf("Parameter 1 of %s must be a string of valid class name.", __METHOD__)
            );
        }

        $reflector = Internal\ReflectionClassFactory::create($class);

        if (!$this->hasConstructor($reflector)) {
            return $this->resolveInstanceWithoutConstructor($reflector);
        } else {
            $param = $this->getMethodParameters($reflector, '__construct');

            if (empty($param)) {
                return $reflector->newInstance();
            } else {
                foreach ($param as $key => $value) {
                    $class = $value->getClass();

                    if ($class instanceof \ReflectionClass) {
                        if ($class->isInterface()) {
                            $param[$key] = $this->getConcreteFromInterface($class->getName());
                        } else {
                            $param[$key] = $this->circularDependencyResolver($class->getName());
                        }
                    }
                }

                return $reflector->newInstanceArgs($param);
            }
        }
    }
protected function circularDependencyResolver($class)
    {
        if (!is_string($class) && !class_exists($class)) {
            throw Internal\Exception\ReflectionExceptionFactory::invalidArgument(
                sprintf("Parameter 1 of %s must be a string of valid class name.", __METHOD__)
            );
        }

        $reflector = Internal\ReflectionClassFactory::create($class);

        if (!$this->hasConstructor($reflector)) {
            return $this->resolveInstanceWithoutConstructor($reflector);
        } else {
            $param = $this->getMethodParameters($reflector, '__construct');

            if (empty($param)) {
                return $reflector->newInstance();
            } else {
                foreach ($param as $key => $value) {
                    $class = $value->getClass();

                    if ($class instanceof \ReflectionClass) {
                        if ($class->isInterface()) {
                            $param[$key] = $this->getConcreteFromInterface($class->getName());
                        } else {
                            $param[$key] = $this->circularDependencyResolver($class->getName());
                        }
                    }
                }

                return $reflector->newInstanceArgs($param);
            }
        }
    }
protected function circularDependencyResolver ( $ class ) { if ( ! is_string ( $ class ) && ! class_exists ( $ class ) ) { throw Internal \ Exception \ ReflectionExceptionFactory :: invalidArgument ( sprintf ( "Parameter 1 of %s must be a string of valid class name." , __METHOD__ ) ) ; } $ reflector = Internal \ ReflectionClassFactory :: create ( $ class ) ; if ( ! $ this -> hasConstructor ( $ reflector ) ) { return $ this -> resolveInstanceWithoutConstructor ( $ reflector ) ; } else { $ param = $ this -> getMethodParameters ( $ reflector , '__construct' ) ; if ( empty ( $ param ) ) { return $ reflector -> newInstance ( ) ; } else { foreach ( $ param as $ key => $ value ) { $ class = $ value -> getClass ( ) ; if ( $ class instanceof \ ReflectionClass ) { if ( $ class -> isInterface ( ) ) { $ param [ $ key ] = $ this -> getConcreteFromInterface ( $ class -> getName ( ) ) ; } else { $ param [ $ key ] = $ this -> circularDependencyResolver ( $ class -> getName ( ) ) ; } } } return $ reflector -> newInstanceArgs ( $ param ) ; } } }
Recursively resolving class dependency.

@param string $class The valid class name.
@return object
Recursively resolving class dependency .