Direct access to service utilities

@return \ValuSetup\Setup\SetupUtils
432087
protected function utils()
    {
        if(!$this->utils){
            $this->utils = $this->getServiceLocator()->get('valu_setup.setup_utils');
        }
        
        return $this->utils;
    }
689594
private function initLoaders()
    {
        $namespace = sprintf('%s\\ServiceLoader', __NAMESPACE__);
        $classes = ['MetadataCache', 'MetadataDrivers', 'MetadataFactory', 'Persisters', 'Rest', 'SearchClients'];

        foreach ($classes as $class) {
            $fqcn = sprintf('%s\\%s', $namespace, $class);
            $this->addLoader(new $fqcn);
        }
        return $this;
    }
124994
private function setup()
    {
        $this['licenser'] = function () {
            return new Licenser(new Finder());
        };

        $this['command.licenser'] = function ($c) {
            return new LicenserCommand($c['licenser'], $c['license_header_factory']);
        };

        $this['command.check'] = function ($c) {
            return new CheckCommand($c['licenser'], $c['license_header_factory']);
        };

        $this['twig.templating'] = function () {
            $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../licenses');
            return new \Twig_Environment($loader);
        };

        $this['license_header_factory'] = function ($c) {
            return new LicenseHeaderFactory($c['twig.templating']);
        };
    }
739281
public function getUtils()
    {
        if (!isset($this->utils)) {
            $utils = new Utils;
            $this->utils = $utils;
        }
        return $this->utils;
    }
1016491
protected function registerConfiguredServiceProviders()
    {
        $providers = $this->core->apiConfig('providers', []);

        foreach ($providers as $provider) {
            $this->app->register($provider);
        }

        return $this;
    }
942523
public function getService()
    {
        // Get real arguments values
        $arguments = [];
        foreach ($this->config->getArguments() as $arg) {
            $arguments[] = $arg->value();
        }

        $service = $this->getServiceInstance($arguments);

        // Call methods
        foreach ($this->config->getCalls() as $call) {
            $arguments = [];
            foreach ($call[1] as $arg) {
                $arguments[] = $arg->value();
            }
            call_user_func_array([
                                     $service,
                                     $call[0]
                                 ], $arguments
            );
        }

        return $service;
    }
34974
public function setupServices()
    {
        $settings = $this->getApp()->container->get('settings');

        if (!empty($settings['services'])) {
            if (!is_array($settings['services'])) {
                throw InvalidServiceConfigException::build([], ['serviceConfig' => $settings['services']]);
            }

            foreach ($settings['services'] as $service => $config) {
                $this->setupService($service, $config);
            }
        }
    }
283622
private function loadApplicationServices()
    {
        // setting default services
        $this->container->set('bbapp', $this->application);
        $this->container->set('container.builder', $this);

        $services_directory = $this->application->getBBDir().'/Config/services';
        foreach (scandir($services_directory) as $file) {
            if (1 === preg_match('#(\w+)\.(yml|xml)$#', $file, $matches)) {
                if ('yml' === $matches[2]) {
                    ServiceLoader::loadServicesFromYamlFile($this->container, $services_directory, $matches[1]);
                } else {
                    ServiceLoader::loadServicesFromXmlFile($this->container, $services_directory, $matches[1]);
                }
            }
        }

        // define in which directory we have to looking for services yml or xml
        $directories = ConfigDirectory::getDirectories(
            null, $this->repository_directory, $this->context, $this->environment
        );

        // Loop into every directory where we can potentially found a services.yml or services.xml
        foreach ($directories as $directory) {
            if (true === is_readable($directory.DIRECTORY_SEPARATOR.self::SERVICE_FILENAME.'.yml')) {
                ServiceLoader::loadServicesFromYamlFile($this->container, $directory);
            }

            if (true === is_readable($directory.DIRECTORY_SEPARATOR.self::SERVICE_FILENAME.'.xml')) {
                ServiceLoader::loadServicesFromXmlFile($this->container, $directory);
            }
        }

        $this->loadLoggerDefinition();
    }
798676
public static function setup(): void
    {
        $aComponents          = Components::available();
        self::$aContainers    = [];
        self::$aLoadedHelpers = [];
        $aDiscoveredServices  = [
            'nails/common' => self::findServicesForComponent('nails/common'),
        ];

        foreach ($aComponents as $oComponent) {
            $aDiscoveredServices[$oComponent->slug] = self::findServicesForComponent($oComponent->slug);
        }

        $aDiscoveredServices['app'] = self::findServicesForApp();
        $aDiscoveredServices        = array_filter($aDiscoveredServices);

        foreach ($aDiscoveredServices as $sComponentName => $aComponentServices) {

            //  Properties
            if (!empty($aComponentServices['properties'])) {
                if (empty(self::$aContainers[$sComponentName]['properties'])) {
                    self::$aContainers[$sComponentName]['properties'] = new Container();
                }
                foreach ($aComponentServices['properties'] as $sKey => $mValue) {
                    self::$aContainers[$sComponentName]['properties'][$sKey] = $mValue;
                }
            }

            // --------------------------------------------------------------------------

            /**
             * SERVICES
             * All services are wrapped in a closure, this is so that on fetch we can
             * pass in any additional arguments as parameters which can be used in the
             * item's constructor
             */
            if (!empty($aComponentServices['services'])) {
                if (empty(self::$aContainers[$sComponentName]['services'])) {
                    self::$aContainers[$sComponentName]['services'] = new Container();
                }
                foreach ($aComponentServices['services'] as $sKey => $cCallable) {
                    self::$aContainers[$sComponentName]['services'][$sKey] = function () use ($sKey, $cCallable) {
                        return $cCallable;
                    };;
                }
            }

            // --------------------------------------------------------------------------

            /**
             * MODELS
             * All models are wrapped in a closure, this is so that on fetch we can
             * pass in any additional arguments as parameters which can be used in the
             * item's constructor
             */
            if (!empty($aComponentServices['models'])) {
                if (empty(self::$aContainers[$sComponentName]['models'])) {
                    self::$aContainers[$sComponentName]['models'] = new Container();
                }
                foreach ($aComponentServices['models'] as $sKey => $cCallable) {
                    self::$aContainers[$sComponentName]['models'][$sKey] = function () use ($cCallable) {
                        return $cCallable;
                    };
                }
            }

            // --------------------------------------------------------------------------

            /**
             * FACTORIES
             * All factories are wrapped in a closure, this is so that on fetch we can
             * pass in any additional arguments as parameters which can be used in the
             * item's constructor
             */
            if (!empty($aComponentServices['factories'])) {
                if (empty(self::$aContainers[$sComponentName]['factories'])) {
                    self::$aContainers[$sComponentName]['factories'] = new Container();
                }
                foreach ($aComponentServices['factories'] as $sKey => $cCallable) {

                    $cWrapper = function () use ($cCallable) {
                        return $cCallable;
                    };

                    self::$aContainers[$sComponentName]['factories'][$sKey] = self::$aContainers[$sComponentName]['factories']
                        ->factory($cWrapper);
                }
            }

            // --------------------------------------------------------------------------

            /**
             * FACTORIES
             * All factories are wrapped in a closure, this is so that on fetch we can
             * pass in any additional arguments as parameters which can be used in the
             * item's constructor
             */
            if (!empty($aComponentServices['resources'])) {
                if (empty(self::$aContainers[$sComponentName]['resources'])) {
                    self::$aContainers[$sComponentName]['resources'] = new Container();
                }
                foreach ($aComponentServices['resources'] as $sKey => $cCallable) {

                    $cWrapper = function () use ($cCallable) {
                        return $cCallable;
                    };

                    self::$aContainers[$sComponentName]['resources'][$sKey] = self::$aContainers[$sComponentName]['resources']
                        ->factory($cWrapper);
                }
            }
        }
    }
743791
public function getServices()
    {
        $mergedModuleServices = array();

        foreach ($this->services as $services) {
            $mergedModuleServices = ArrayUtils::merge($mergedModuleServices, $services);
        }

        return $mergedModuleServices;
    }
689797
private function fetchFixtures()
    {
        $this->loader = $this->getFixtureLoader();

        $bundleDirectories = $this->autoload ? $this->getBundleFixtureDirectories() : array();

        $this->fetchFixturesFromDirectories($bundleDirectories);
        $this->fetchFixturesFromDirectories($this->directories ?: array());
        $this->fetchFixturesFromClasses($this->fixtures ?: array());

        return $this->loader->getFixtures();
    }
1130314
public function loadBundles() {
		if($this->loaded)
			return;

		$this->bundles = $this->doGetBundles();
		$container = $this->getContainer();

		if($this->params['env']) {
			if(file_exists($this->params['root'].'/app/bootstrap_'.strtolower($this->params['env']).'.php'))
				include $this->params['root'].'/app/bootstrap_'.strtolower($this->params['env']).'.php';
		}
		if(file_exists($this->params['root'].'/app/bootstrap_all.php'))
			include $this->params['root'].'/app/bootstrap_all.php';

		$this->runBundles();

		$this->loaded = true;

		return $this;
	}
347407
protected function loadServiceData() {
    if (!isset($this->serviceData)) {
      $this->serviceData = $this->environment->getStorage()->retrieve('services');
    }

    // Populate the keys, in case analysis crashed.
    $this->serviceData += [
      'primary' => [],
      'all' => [],
    ];

    return $this->serviceData;
  }
1210323
protected static function retrieveServiceConfigurationFiles()
    {
        $virtualFile = self::$registry->getPath()->get('configuration').'.service.json';
        $caching     = self::$registry->getParameter('doozr.kernel.caching');
        $files       = null;
        $stale       = false;

        // Try to load service configurations from cache!
        if (true === $caching) {
            try {
                $files = self::$registry->getCache()->getItem($virtualFile)->get();

            } catch (Doozr_Cache_Service_Exception $exception) {
                // Intentionally left empty
            }
        }

        // Could be loaded from cache? otherwise lookup here (PERFORMANCE:IMPACT:HIGH:FILESYSTEM)
        if (null === $files) {
            $stale   = true;
            $pattern = self::$registry->getPath()->get('service').
                       '*'.DIRECTORY_SEPARATOR.'*'.DIRECTORY_SEPARATOR.'.config.json';
            $files   = glob($pattern, GLOB_NOSORT);
        }

        // Cache items found for reuse later
        if (true === $stale && true === $caching) {
            $cacheItem = new CacheItem($virtualFile);
            $cacheItem->set($files);

            self::$registry->getCache()->save($cacheItem);
        }

        // Return collection of service configuration files
        return $files;
    }
880692
public function getServiceInstances()
    {
        $instances = [];

        foreach ($this->getServices() as $name => $info) {
            if (!isset($info['type'])) {
                continue;
            }
            $type = $info['type'];
            unset($info['type']);

            $instances[$name] = [
                'type' => $type,
                'options' => $info,
                'instance' => static::loadService($this, $type, $name),
            ];
        }

        return $instances;
    }
656648
public static function initKernel()
    {
        $configFiles = self::getConfigFiles();

        $fs = new Filesystem();

        if(!$fs->exists($configFiles['bundles'])){
            $fs->copy($configFiles['bundles_dist'], $configFiles['bundles'], true);
        }
        if(!$fs->exists($configFiles['config'])){
            $fs->copy($configFiles['config_dist'], $configFiles['config'], true);
        }
        if(!$fs->exists($configFiles['routing'])){
            $fs->copy($configFiles['routing_dist'], $configFiles['routing'], true);
        }
        if(!$fs->exists($configFiles['security'])){
            $fs->copy($configFiles['security_dist'], $configFiles['security'], true);
        }
    }
1127167
protected function bootFilters()
	{
		if (config('api.cors_enabled', true)) {
			$this->app['router']->before(function ($request) {
				if (Request::header('Origin') && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
					$response = Response::make(null, 204);
					Cors::attachHeaders($response);
					Cors::attachOriginHeader($response, Request::header('Origin'));
					return $response;
				}
			});
			
			$this->app['router']->after(function ($request, $response) {
				if (Request::header('Origin')) {
					Cors::attachHeaders($response);
					Cors::attachOriginHeader($response, Request::header('Origin'));
				}
			});
		}
		
		$this->app['router']->filter('protect', function ($route, $request) {
			Api::protect();
		});
		
		$this->app['router']->filter('checkscope', function ($route, $request, $scope = '') {
			// B/c Laravel uses : as a special character already.
			$scope = str_replace('.', ':', $scope);
			
			Api::checkScope($scope);
		});
	}