public function autoload($inputDirectory, $outputDirectory)
    {
        if (!file_exists($outputDirectory . self::SERVICES_STATIC_FILE)
                || $this->di->get('environment') != Constants::DEFAULT_ENV) {
            $services = self::dump($inputDirectory, $outputDirectory);
        } else {
            $services = require($outputDirectory . self::SERVICES_STATIC_FILE);
        }

        self::setupServiceProvidersAutoloader($inputDirectory, $services);

        //resolves services dependencies
        $dependencies = array();
        $servicesProviders = array();
        foreach ($services as $serviceProviderName => $path) {
            $reflectionClass = new \ReflectionClass($serviceProviderName);
            $serviceProviderInstance = $reflectionClass->newInstance();
            //fetches services dependencies
            $serviceDependencies = $serviceProviderInstance->getDependencies();

            //fetches name of service
            $serviceName = $reflectionClass->getConstant('SERVICE_NAME');

            //all services are in dependencies
            if (!isset($dependencies[$serviceName])) {
                $dependencies[$serviceName] = 0;
            }

            /**
             * Creates array of ordered dependencies
             */
            array_walk($serviceDependencies, function($dependency, $key) use (&$dependencies) {
                if (!isset($dependencies[$dependency])) {
                    $dependencies[$dependency] = 0;
                }
                $dependencies[$dependency]++;
            });
            $servicesProviders[$serviceName] = $serviceProviderInstance;
        }
        uasort($dependencies, function($a, $b) { return $b-$a; });

        //registers ordered dependencies
        foreach ($dependencies as $serviceProviderName => $dependency) {
            $servicesProviders[$serviceProviderName]->register($this->di);
        }
    }
public function autoload($inputDirectory, $outputDirectory)
    {
        if (!file_exists($outputDirectory . self::SERVICES_STATIC_FILE)
                || $this->di->get('environment') != Constants::DEFAULT_ENV) {
            $services = self::dump($inputDirectory, $outputDirectory);
        } else {
            $services = require($outputDirectory . self::SERVICES_STATIC_FILE);
        }

        self::setupServiceProvidersAutoloader($inputDirectory, $services);

        //resolves services dependencies
        $dependencies = array();
        $servicesProviders = array();
        foreach ($services as $serviceProviderName => $path) {
            $reflectionClass = new \ReflectionClass($serviceProviderName);
            $serviceProviderInstance = $reflectionClass->newInstance();
            //fetches services dependencies
            $serviceDependencies = $serviceProviderInstance->getDependencies();

            //fetches name of service
            $serviceName = $reflectionClass->getConstant('SERVICE_NAME');

            //all services are in dependencies
            if (!isset($dependencies[$serviceName])) {
                $dependencies[$serviceName] = 0;
            }

            /**
             * Creates array of ordered dependencies
             */
            array_walk($serviceDependencies, function($dependency, $key) use (&$dependencies) {
                if (!isset($dependencies[$dependency])) {
                    $dependencies[$dependency] = 0;
                }
                $dependencies[$dependency]++;
            });
            $servicesProviders[$serviceName] = $serviceProviderInstance;
        }
        uasort($dependencies, function($a, $b) { return $b-$a; });

        //registers ordered dependencies
        foreach ($dependencies as $serviceProviderName => $dependency) {
            $servicesProviders[$serviceProviderName]->register($this->di);
        }
    }
public function autoload ( $ inputDirectory , $ outputDirectory ) { if ( ! file_exists ( $ outputDirectory . self :: SERVICES_STATIC_FILE ) || $ this -> di -> get ( 'environment' ) != Constants :: DEFAULT_ENV ) { $ services = self :: dump ( $ inputDirectory , $ outputDirectory ) ; } else { $ services = require ( $ outputDirectory . self :: SERVICES_STATIC_FILE ) ; } self :: setupServiceProvidersAutoloader ( $ inputDirectory , $ services ) ; //resolves services dependencies $ dependencies = array ( ) ; $ servicesProviders = array ( ) ; foreach ( $ services as $ serviceProviderName => $ path ) { $ reflectionClass = new \ ReflectionClass ( $ serviceProviderName ) ; $ serviceProviderInstance = $ reflectionClass -> newInstance ( ) ; //fetches services dependencies $ serviceDependencies = $ serviceProviderInstance -> getDependencies ( ) ; //fetches name of service $ serviceName = $ reflectionClass -> getConstant ( 'SERVICE_NAME' ) ; //all services are in dependencies if ( ! isset ( $ dependencies [ $ serviceName ] ) ) { $ dependencies [ $ serviceName ] = 0 ; } /**
             * Creates array of ordered dependencies
             */ array_walk ( $ serviceDependencies , function ( $ dependency , $ key ) use ( & $ dependencies ) { if ( ! isset ( $ dependencies [ $ dependency ] ) ) { $ dependencies [ $ dependency ] = 0 ; } $ dependencies [ $ dependency ] ++ ; } ) ; $ servicesProviders [ $ serviceName ] = $ serviceProviderInstance ; } uasort ( $ dependencies , function ( $ a , $ b ) { return $ b - $ a ; } ) ; //registers ordered dependencies foreach ( $ dependencies as $ serviceProviderName => $ dependency ) { $ servicesProviders [ $ serviceProviderName ] -> register ( $ this -> di ) ; } }
Creates services autoloader
Creates services autoloader