Adds bundle's templates base directory into application's renderer.

@param Config        $config
@param callable|null $recipe
515362
private function addTemplatesDir(Config $config, callable $recipe = null)
    {
        if (false === $this->runRecipe($config, $recipe)) {
            $directory = realpath(
                dirname($config->getBaseDir()).DIRECTORY_SEPARATOR
                .'Templates'.DIRECTORY_SEPARATOR.'scripts'
            );
            if (false !== $directory) {
                $this->application->getRenderer()->addScriptDir($directory);
            }
        }
    }
1089033
private function _prepareDir($config) {
        $directory = $this->generateDirectoryPath($config);
        if (!is_dir($directory)) {
            $base = $this->generateBaseDirectoryPath($config);
            if (!is_dir($base)) {
                trigger_error('Base directory '.$base.' does not exist,
                    please create or change using %Cache.SerializerPath',
                    E_USER_WARNING);
                return false;
            } elseif (!$this->_testPermissions($base)) {
                return false;
            }
            $old = umask(0022); // disable group and world writes
            mkdir($directory);
            umask($old);
        } elseif (!$this->_testPermissions($directory)) {
            return false;
        }
        return true;
    }
421435
protected function mergeIncludes(&$config, $basePath = null)
    {
        if (!empty($config['includes'])) {
            foreach ($config['includes'] as &$path) {
                // Account for relative paths
                if ($path[0] != DIRECTORY_SEPARATOR && !isset($this->aliases[$path]) && $basePath) {
                    $path = "{$basePath}/{$path}";
                }
                // Don't load the same files more than once
                if (!isset($this->loadedFiles[$path])) {
                    $this->loadedFiles[$path] = true;
                    $config = $this->mergeData($this->loadFile($path), $config);
                }
            }
        }
    }
1130332
protected function _initialize(AnConfig $config)
    {
        $paths[] = dirname($this->getIdentifier()->filepath).'/html';
        $paths[] = implode(DS, array(
                      ANPATH_THEMES,
                      AnService::get('com:application')->getTemplate(),
                      'html',
                      $this->getIdentifier()->type.'_'.$this->getIdentifier()->package,
                      $this->getName(), ));

        $config->append(array(
            'template_paths' => $paths,
        ));

        parent::_initialize($config);
    }
1095558
protected function _initialize(KObjectConfig $config)
    {
        $config->append(array(
            'method'  => self::GET,
            'url'     => '',
            'headers' => array()
        ));

        parent::_initialize($config);
    }
547817
public static function register($bundle, $config = array())
	{
		$defaults = array('handles' => null, 'auto' => false);

		// If the given configuration is actually a string, we will assume it is a
		// location and set the bundle name to match it. This is common for most
		// bundles that simply live in the root bundle directory.
		if (is_string($config))
		{
			$bundle = $config;

			$config = array('location' => $bundle);
		}

		// If no location is set, we will set the location to match the name of
		// the bundle. This is for bundles that are installed on the root of
		// the bundle directory so a location was not set.
		if ( ! isset($config['location']))
		{
			$config['location'] = $bundle;
		}

		static::$bundles[$bundle] = array_merge($defaults, $config);

		// It is possible for the developer to specify auto-loader mappings
		// directly on the bundle registration. This provides a convenient
		// way to register mappings without a bootstrap.
		if (isset($config['autoloads']))
		{
			static::autoloads($bundle, $config);
		}
	}
785535
private function runRecipe(Config $config, callable $recipe = null)
    {
        $done = false;
        if (null !== $recipe) {
            call_user_func_array($recipe, array($this->application, $config));
            $done = true;
        }

        return $done;
    }
647456
public function configureTemplates(ContainerBuilder $container, array $config)
    {
        $templateManager = $container->getDefinition('sonata.page.template_manager');

        // add all templates to manager
        $definitions = [];
        foreach ($config['templates'] as $code => $info) {
            $definition = new Definition(Template::class, [
                $info['name'],
                $info['path'],
                $info['containers'],
            ]);

            $definition->setPublic(false);
            $definitions[$code] = $definition;
        }

        $templateManager->addMethodCall('setAll', [$definitions]);

        // set default template
        $templateManager->addMethodCall('setDefaultTemplateCode', [$config['default_template']]);
    }
1272522
public static function start(&$config) {
		self::$cacheDirectory = self::initialGetCacheDirectory ( $config );
		$cacheDirectory = \ROOT . \DS . self::$cacheDirectory;
		Annotations::$config ['cache'] = new AnnotationCache ( $cacheDirectory . '/annotations' );
		self::register ( Annotations::getManager () );
		self::getCacheInstance ( $config, $cacheDirectory, ".cache" );
	}
1226716
function(userConf, template, callback) {

        var content = userConf,
        //if nothing to merge.
            newContent = JSON.parse( JSON.stringify(content) );

        var isStandalone = true,
            env = self.Env.get(),
            appsPath = "",
            modelsPath = "";


        //Pushing default app first.
        self.bundles.push(self.startingApp);//This is a JSON.push.
        var root = new _(self.executionPath).toUnixStyle();
        try {
            var pkg = require(_(root + '/project.json')).bundles;
        } catch (err) {
            callback(err);
        } //bundlesPath will be default.


        //For each app.
        for (var app in content) {
            //Checking if genuine app.
            console.debug('Checking if application [ '+ app +' ]is registered ');

            if ( typeof(content[app][env]) != "undefined" ) {

                if (
                    pkg[app] != 'undefined' && pkg[app]['src'] != 'undefined' && env == 'dev'
                    || pkg[app] != 'undefined' && pkg[app]['src'] != 'undefined' && env == 'debug'
                ) {
                    var p = _(pkg[app].src);
                    content[app][env]['bundlesPath'] = "{executionPath}/"+ p.replace('/' + app, '');
                } else {
                    var p = ( typeof(pkg[app].release.link) != 'undefined' ) ? _(pkg[app].release.link) : _(pkg[app].release.target);
                    content[app][env]['bundlesPath'] = "{executionPath}/"+ p.replace('/' + app, '');
                }

                appsPath = (typeof(content[app][env]['bundlesPath']) != "undefined")
                    ? content[app][env].bundlesPath
                    : template["{bundle}"]["{env}"].bundlesPath;



                modelsPath = (typeof(content[app][env]['modelsPath']) != "undefined")
                    ?  content[app][env].modelsPath
                    :  template["{bundle}"]["{env}"].modelsPath;

                //I had to for this one...
                appsPath = appsPath.replace(/\{executionPath\}/g, root);
                //modelsPath = modelsPath.replace(/\{executionPath\}/g, mPath);

                //console.log("My env ", env, self.executionPath, JSON.stringify(template, null, '\t') );
                //Existing app and port sharing => != standalone.
                if ( !fs.existsSync(appsPath) ) {
                    new _(appsPath).mkdirSync()
                }
                var masterPort = content[self.startingApp][env].port.http;
                //Check if standalone or shared instance
                if (content[app][env].port.http != masterPort) {
                    isStandalone = false;
                    self.Host.standaloneMode = isStandalone
                } else if (app != self.startingApp) {
                    self.bundles.push(app)
                }
                self.allBundles.push(app);

                //Mergin user's & template.
                newContent[app][env] = merge(
                    newContent[app][env],
                    JSON.parse( JSON.stringify(template["{bundle}"]["{env}"]))//only copy of it.
                );


                //Variables replace. Compare with gina/core/template/conf/env.json.
                var version = undefined, middleware = undefined;
                try {
                    self.version    = version = require(_(getPath('gina').root +'/package.json' )).version;
                    self.middleware = middleware = fs.readFileSync(_(getPath('gina').root + '/MIDDLEWARE')).toString() || 'none';

                    setContext('gina.version', version);
                    setContext('gina.middleware', middleware);

                } catch (err) {
                    console.debug(err.stack)
                }

                var reps = {
                    "executionPath" : root,
                    "bundlesPath" : appsPath,
                    "modelsPath" : modelsPath,
                    "env" : env,
                    "bundle" : app,
                    "version": version
                };


                //console.error("reps ", reps);
                newContent = whisper(reps, newContent);


            }
            //Else not in the scenario.

        }//EO for.


        console.debug('Env configuration loaded \n');

        // TRUE means that all apps sharing the same process will merge into one.
        if (!isStandalone) self.Host.standaloneMode = isStandalone;

        console.debug('Is server running as a standalone instance ? ' + isStandalone);

        callback(false, newContent)
    }
222731
protected function setup(array $config = [])
    {
        if (isset($config['renderer']) && (!($config['renderer'] instanceof \Closure) && !is_callable($config['renderer']))) {
            throw new Exception(translate('{renderer} must be callable'), 500, Exception::BADARGUMENTS);
        }

        if (isset($config['template']) && !is_string($config['template'])) {
            throw new Exception(translate('{template} must be a string'), 500, Exception::BADARGUMENTS);
        }

        if (isset($config['html_options']) && !is_array($config['html_options'])) {
            throw new Exception(translate('{html_options} must be an array'), 500, Exception::BADARGUMENTS);
        }

        foreach ($config as $property => $data) {
            if (property_exists($this, $property)) {
                $this->{$property} = $data;
            } elseif (property_exists($this, '_'.$property)) {
                $this->{'_'.$property} = $data;
            }
        }

        if (!$this->id) {
            $this->id = 'widget_'.static::$_counter;
        }

        if (isset($this->_html_options['id'])) {
            $this->id = $this->_html_options['id'];
        } else {
            $this->_html_options['id'] = $this->id;
        }
    }
985771
public function loadInternal(array $config, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.yml');

        $bundles = $container->getParameter('kernel.bundles');

        $directories = [];
        if ($config['metadata']['auto_detection']) {
            foreach ($bundles as $name => $class) {
                $ref                                   = new \ReflectionClass($class);
                $directories[$ref->getNamespaceName()] = dirname($ref->getFileName()) . '/Resources/config/fixture';
            }
        }

        foreach ($config['metadata']['directories'] as $directory) {
            $directory['path'] = rtrim(str_replace('\\', '/', $directory['path']), '/');
            if ('@' === $directory['path'][0]) {
                preg_match('~^@([a-z0-9_]+)~i', $directory['path'], $match);

                if (isset($match[1])) {
                    list($prefixedBundleName, $bundleName) = $match;
                    if (!isset($bundles[$bundleName])) {
                        throw new RuntimeException(sprintf('The bundle "%s" has not been registered with AppKernel. Available bundles: %s', $bundleName, implode(', ', array_keys($bundles))));
                    }
                    $ref = new \ReflectionClass($bundles[$bundleName]);
                    $directory['path'] = dirname($ref->getFileName()).substr($directory['path'], strlen($prefixedBundleName));
                }
            }
            $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/');
        }

        $container
            ->getDefinition('trappar_alice_generator.metadata.file_locator')
            ->addArgument($directories);

        $container
            ->getDefinition(YamlWriter::class)
            ->addArgument($config['yaml']['inline'])
            ->addArgument($config['yaml']['indent']);

        $container
            ->getDefinition(ValueVisitor::class)
            ->addArgument($config['strictTypeChecking']);
    }
1227839
public function initRoutes(Config $config)
    {
        //setups router
        $routerAdapter = new Standard($this->getDI());
        $router = new Router($this->getDI(), $routerAdapter);

        //adds routes defined in modules
        $modules = $this->getApplication()->getModules();
        foreach ($modules as $module) {
            $router->addModuleRoutes($module);
        }

        //adds routes defined in default file
        $defaultRoutesFile = $config->application->configDir
            . DIRECTORY_SEPARATOR
            . 'routes.php';
        if (file_exists($defaultRoutesFile)) {
            $routes = require $defaultRoutesFile;
            if (is_array($routes)) {
                $router->addRoutes($routes);
            }
        }

        //setup router rules
        $router->setup();

        //registers router into DI
        $this->getDI()->set('router', $router->getRouter());
    }
1114221
private static function includeConfigFile(array &$config, $config_file, File $base_dir, ConfigReader $reader)
    {
        // try relative path
        $file = new File($config_file, $base_dir);
        
        if ( $file->exists() ){
            $included = self::loadConfigFileByFormat( $file, $reader );
            $config = array_merge_recursive($config, $included);
            return;
        }
        
        // try full path
        $file = new File($config_file);
        
        if ( $file->exists() ){
            $included = self::loadConfigFileByFormat( $file, $reader );
            $config = array_merge_recursive($config, $included);
            return;
        }
        
        throw new IncludeConfigFileNotFoundException($config_file);
    }
886030
private function loadServices(Config $config, $serviceId, callable $recipe = null)
    {
        if (false === $this->runRecipe($config, $recipe)) {
            $directories = array_unique(array_merge(
                            BundleConfigDirectory::getDirectories(
                                    $this->application->getBaseRepository(),
                                    $this->application->getContext(),
                                    $this->application->getEnvironment(),
                                    str_replace('bundle.', '', $serviceId)
                            ), BundleConfigDirectory::getDirectories(
                                    $this->application->getBaseRepository(),
                                    $this->application->getContext(),
                                    $this->application->getEnvironment(),
                                    basename(dirname($config->getBaseDir()))
            )));
            array_unshift($directories, $this->getConfigDirByBundleBaseDir(dirname($config->getBaseDir())));

            foreach ($directories as $directory) {
                $filepath = $directory.DIRECTORY_SEPARATOR.'services.xml';
                if (is_file($filepath) && is_readable($filepath)) {
                    try {
                        ServiceLoader::loadServicesFromXmlFile($this->container, $directory);
                    } catch (\Exception $e) {
                        // nothing to do
                    }
                }

                $filepath = $directory.DIRECTORY_SEPARATOR.'services.yml';
                if (is_file($filepath) && is_readable($filepath)) {
                    try {
                        ServiceLoader::loadServicesFromYamlFile($this->container, $directory);
                    } catch (\Exception $e) {
                        // nothing to do
                    }
                }
            }
        }
    }
1099664
protected function run(Config $config): ResultInterface
    {
        $includes = $config->compileIncludes();

        return $this->validator->validate(...$includes);
    }
177580
private function getLoaderRecipesByConfig(Config $config)
    {
        $recipes = null;
        $bundleConfig = $config->getBundleConfig();
        if (null !== $bundleConfig && isset($bundleConfig['bundle_loader_recipes'])) {
            $recipes = $bundleConfig['bundle_loader_recipes'];
        }

        return $recipes;
    }