public function make($className)
    {
        // Create a reflection to access the class properties
        $reflection = new \ReflectionClass($className);

        // If the class has no constructor, just return a new instance
        $constructor = $reflection->getConstructor();
        if (is_null($constructor)) {
            return new $className;
        }

        // Or get the constructor parameters and instance dependencies
        $dependencies = [];
        $parameters = $reflection->getConstructor()->getParameters();
        foreach ($parameters as $param) {
            $class = $param->getClass();
            if ($class && $class->getName() === 'Laito\App') {

                // If the dependency is the app itself, inject the current instance
                $dependencies[] = $this;
            } else {

                // Otherwise, inject the instantiated dependency or a null value
                $dependencies[] = $class? $this->make($class->name) : 'NULL';
            }
        }

        // Return the class instance
        $instance = $reflection->newInstanceArgs($dependencies);

        // If the class has a boot method, run it
        if (method_exists($instance, 'boot')) {
            $instance->boot();
        }

        // Return instance
        return $instance;
    }
public function make($className)
    {
        // Create a reflection to access the class properties
        $reflection = new \ReflectionClass($className);

        // If the class has no constructor, just return a new instance
        $constructor = $reflection->getConstructor();
        if (is_null($constructor)) {
            return new $className;
        }

        // Or get the constructor parameters and instance dependencies
        $dependencies = [];
        $parameters = $reflection->getConstructor()->getParameters();
        foreach ($parameters as $param) {
            $class = $param->getClass();
            if ($class && $class->getName() === 'Laito\App') {

                // If the dependency is the app itself, inject the current instance
                $dependencies[] = $this;
            } else {

                // Otherwise, inject the instantiated dependency or a null value
                $dependencies[] = $class? $this->make($class->name) : 'NULL';
            }
        }

        // Return the class instance
        $instance = $reflection->newInstanceArgs($dependencies);

        // If the class has a boot method, run it
        if (method_exists($instance, 'boot')) {
            $instance->boot();
        }

        // Return instance
        return $instance;
    }
public function make ( $ className ) { // Create a reflection to access the class properties $ reflection = new \ ReflectionClass ( $ className ) ; // If the class has no constructor, just return a new instance $ constructor = $ reflection -> getConstructor ( ) ; if ( is_null ( $ constructor ) ) { return new $ className ; } // Or get the constructor parameters and instance dependencies $ dependencies = [ ] ; $ parameters = $ reflection -> getConstructor ( ) -> getParameters ( ) ; foreach ( $ parameters as $ param ) { $ class = $ param -> getClass ( ) ; if ( $ class && $ class -> getName ( ) === 'Laito\App' ) { // If the dependency is the app itself, inject the current instance $ dependencies [ ] = $ this ; } else { // Otherwise, inject the instantiated dependency or a null value $ dependencies [ ] = $ class ? $ this -> make ( $ class -> name ) : 'NULL' ; } } // Return the class instance $ instance = $ reflection -> newInstanceArgs ( $ dependencies ) ; // If the class has a boot method, run it if ( method_exists ( $ instance , 'boot' ) ) { $ instance -> boot ( ) ; } // Return instance return $ instance ; }
Makes an instance of a class

@param string $className Class name
@return object Class instance
Makes an instance of a class