/**
  * {@inheritdoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $locator = new FileLocator(__DIR__ . '/../Resources/config');
     $resolver = new LoaderResolver(array(new YamlFileLoader($container, $locator)));
     $loader = new DelegatingLoader($resolver);
     $loader->load('parameters.yml');
     $loader->load('services.yml');
 }
Esempio n. 2
0
 /**
  * Get configuration
  *
  * @return array
  */
 public function getConfiguration()
 {
     $configurationFiles = $this->locator->locate('config.yml', null, false);
     $configurations = [];
     foreach ($configurationFiles as $path) {
         $configurations[] = $this->loader->load($path);
     }
     return $this->processor->processConfiguration($this->configuration, $configurations);
 }
Esempio n. 3
0
    /**
     * 
     * @param string $configDirectories
     * @param string $configFiles
     * @param string $cachePath
     * @param bool $debug
     */
    public function __construct($configDirectories, $configFiles, $cachePath, $debug = false)
    {
        $this->configDirectories = (array) $configDirectories;
        $this->configFiles = (array) $configFiles;
        $this->cachePath = $cachePath . '/faker_config.php';
        $configCache = new ConfigCache($this->cachePath, $debug);
        if (!$configCache->isFresh()) {
            $locator = new FileLocator($this->configDirectories);
            $loaderResolver = new LoaderResolver([new YamlLoader($locator)]);
            $delegatingLoader = new DelegatingLoader($loaderResolver);
            $resources = [];
            $config = [];
            foreach ($this->configFiles as $configFile) {
                $path = $locator->locate($configFile);
                $config = array_merge($config, $delegatingLoader->load($path));
                $resources[] = new FileResource($path);
            }
            $exportConfig = var_export($this->parseRawConfig(isset($config['faker']) ? $config['faker'] : []), true);
            $code = <<<PHP
<?php
return {$exportConfig};
PHP;
            $configCache->write($code, $resources);
        }
        if (file_exists($this->cachePath)) {
            $this->config = (include $this->cachePath);
        }
    }
 public function register(Container $app)
 {
     $app['router.options'] = [];
     $app['router.loader_resolver'] = function () {
         $fileLocator = new FileLocator();
         $loaderResolver = new LoaderResolver([new XmlFileLoader($fileLocator), new PhpFileLoader($fileLocator), new ClosureLoader()]);
         if (class_exists('Symfony\\Component\\Yaml\\Parser')) {
             $loaderResolver->addLoader(new YamlFileLoader($fileLocator));
         }
         return $loaderResolver;
     };
     $app['router'] = function (Application $app) {
         $router = new Router(new ClosureLoader(), function () use($app) {
             if (isset($app['router.resource'])) {
                 $userLoader = new DelegatingLoader($app['router.loader_resolver']);
                 $userRoutes = $userLoader->load($app['router.resource']);
                 $app['routes']->addCollection($userRoutes);
             }
             $app->flush();
             return $app['routes'];
         }, $app['router.options'] + ['debug' => isset($app['debug']) ? $app['debug'] : false, 'matcher_base_class' => 'Silex\\Provider\\Routing\\RedirectableUrlMatcher', 'matcher_class' => 'Silex\\Provider\\Routing\\RedirectableUrlMatcher'], $app['request_context'], $app['logger']);
         return $router;
     };
     $app['request_matcher'] = function (Application $app) {
         return $app['router'];
     };
     $app['url_generator'] = function (Application $app) {
         return $app['router'];
     };
 }
Esempio n. 5
0
 /**
  * @param ContainerBuilder $container
  *
  * @throws Exception\ConfigurationFileNotFoundException
  * @throws \Exception
  */
 public static function read(ContainerBuilder $container)
 {
     /** @var InputInterface $input */
     $input = $container->get('input');
     $locations = [getcwd(), getcwd() . '/.bldr/'];
     if ($input->hasParameterOption('--global')) {
         $locations = array_merge($locations, [getenv('HOME'), getenv('HOME') . '/.bldr/']);
     }
     $locator = new FileLocator($locations);
     $resolver = new LoaderResolver([new Loader\YamlFileLoader($container, $locator), new Loader\XmlFileLoader($container, $locator), new Loader\PhpFileLoader($container, $locator), new Loader\IniFileLoader($container, $locator), new Loader\JsonFileLoader($container, $locator), new Loader\TomlFileLoader($container, $locator)]);
     $loader = new DelegatingLoader($resolver);
     $files = static::findFiles($input);
     $foundConfig = false;
     foreach ($files as $file) {
         try {
             $loader->load($file);
             $foundConfig = true;
         } catch (\Exception $e) {
             if (get_class($e) !== 'InvalidArgumentException') {
                 throw $e;
             }
         }
     }
     if (!$foundConfig) {
         throw new ConfigurationFileNotFoundException(sprintf("Either couldn't find the configuration file, or couldn't read it. " . "Make sure the extension is valid (%s). Tried: %s", implode(', ', static::$TYPES), implode(', ', $files)));
     }
 }
Esempio n. 6
0
 public function __construct()
 {
     parent::__construct();
     $fileLocator = new FileLocator(__DIR__ . '/../../config/');
     $resolver = new LoaderResolver(array(new XmlFileLoader($this, $fileLocator), new YamlFileLoader($this, $fileLocator)));
     $loader = new DelegatingLoader($resolver);
     $loader->load('services.yml');
 }
 /**
  * @expectedException \Symfony\Component\Config\Exception\FileLoaderLoadException
  */
 public function testLoadThrowsAnExceptionIfTheResourceCannotBeLoaded()
 {
     $loader = $this->getMock('Symfony\\Component\\Config\\Loader\\LoaderInterface');
     $loader->expects($this->once())->method('supports')->will($this->returnValue(false));
     $resolver = new LoaderResolver(array($loader));
     $loader = new DelegatingLoader($resolver);
     $loader->load('foo');
 }
Esempio n. 8
0
 protected function loadConfigurations($configFile)
 {
     $locator = new FileLocator('.');
     $yaml = new YamlFileLoader($this->container, $locator);
     $xml = new XmlFileLoader($this->container, $locator);
     $delegatingLoader = new DelegatingLoader(new LoaderResolver(array($yaml, $xml)));
     $delegatingLoader->load($configFile);
     $this->container->compile();
 }
Esempio n. 9
0
 /**
  * Loads the configuration file
  *
  * @param string $configFile
  *
  * @throws FileLoaderLoadException
  *
  * @return array The loaded configuration
  */
 public function load($configFile)
 {
     $configDirectories = array(dirname($configFile));
     $locator = new FileLocator($configDirectories);
     $loaderResolver = new LoaderResolver(array(new Yaml($locator)));
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     $config = $delegatingLoader->load($configFile);
     return $config;
 }
Esempio n. 10
0
 public function setUp()
 {
     parent::setUp();
     $this->confContainer = new ConfContainer();
     $yfl = new YamlFileLoader($this->confContainer, new FileLocator(__DIR__ . '/../../Resources/config/'));
     $loaderResolver = new LoaderResolver(array($yfl));
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     $delegatingLoader->load('config.yml');
 }
Esempio n. 11
0
 /**
  * @return mixed
  */
 public function load()
 {
     $rev = new LoaderResolver($this->loaders);
     $dloader = new DelegatingLoader($rev);
     foreach ($this->confFiles as $confFile) {
         $conf = $dloader->load($confFile);
         $this->conf = array_merge($this->conf, $conf);
     }
     return $this->conf;
 }
Esempio n. 12
0
 public function __construct(EntityManager $em, \Twig_Environment $twig, $themeDir)
 {
     $this->em = $em;
     $this->twig = $twig;
     $this->themeDir = $themeDir;
     $locator = new FileLocator($this->themeDir);
     $loaderResolver = new LoaderResolver([new YamlFileLoader($locator)]);
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     $themeConfig = $delegatingLoader->load('theme.yml');
     $this->templates = $themeConfig['templates'];
 }
Esempio n. 13
0
 /**
  * Load the services service definitions
  *
  * @param ContainerBuilder $containerBuilder
  * @param string|array     $files
  *
  * @throws FileLoaderLoadException
  */
 protected function loadServiceDefinitions(ContainerBuilder $containerBuilder, $files)
 {
     $locator = new FileLocator($this->getDefinitionPath($containerBuilder));
     $resolver = new LoaderResolver(array(new XmlFileLoader($containerBuilder, $locator), new YamlFileLoader($containerBuilder, $locator)) + $this->getExtraLoaders($containerBuilder));
     $loader = new DelegatingLoader($resolver);
     if (!is_array($files)) {
         $files = array($files);
     }
     foreach ($files as $file) {
         $loader->load($file);
     }
 }
Esempio n. 14
0
 /**
  * @inheritdoc
  * @param mixed $resources
  */
 public function load($resources, $type = null)
 {
     $config = new Config();
     $config->setData($this->vars);
     foreach ((array) $resources as $resource) {
         $config->merge(parent::load($resource, $type));
     }
     foreach ($this->processors as $processor) {
         $processor->process($config);
     }
     return $config;
 }
Esempio n. 15
0
 public function load($path, $filename)
 {
     $configDirectories = array($path);
     $locator = new FileLocator($configDirectories);
     $loaderResolver = new LoaderResolver(array(new YamlConfigLoader($locator)));
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     $config = $delegatingLoader->load($filename);
     if (isset($config['parameters'])) {
         $config = $this->postProcessConfig($config, $config['parameters']);
     }
     return $config;
 }
Esempio n. 16
0
 public function register(Container $container)
 {
     $container['config'] = function () {
         $configDirectories = ['../config/', './config/'];
         $locator = new FileLocator($configDirectories);
         $loaderResolver = new LoaderResolver([new YamlFileLoader($locator)]);
         $delegatingLoader = new DelegatingLoader($loaderResolver);
         $something = $delegatingLoader->load('config.yml');
         $processor = new Processor();
         $configuration = new Configuration();
         $processedConfiguration = $processor->processConfiguration($configuration, [$something]);
         return $processedConfiguration;
     };
 }
Esempio n. 17
0
 /**
  * @param RouteCollection $collection
  *
  * @return RouteCollection
  */
 public function load()
 {
     if ($cachedCollection = $this->cache->fetch('collection.' . $this->type)) {
         $this->collection->addCollection($cachedCollection);
         return $this->collection;
     }
     $loaderResolver = new LoaderResolver($this->loaders);
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     foreach ($this->resources as $resource) {
         $this->collection->addCollection($delegatingLoader->load($resource));
     }
     $this->cache->save('collection.' . $this->type, $this->collection);
     return $this->collection;
 }
/**
 * @return array
 * @throws \Symfony\Component\Config\Exception\FileLoaderLoadException
 */
function loadConfig()
{
    $configCachePath = __DIR__ . '/cache/appConfigCache.php';
    $configCache = new ConfigCache($configCachePath, true);
    $configBag = new ConfigBag(['configs' => []]);
    if (!$configCache->isFresh()) {
        $locator = new FileLocator([__DIR__ . '/config']);
        $yamlLoader = new YamlConfigLoader($configBag, $locator);
        $loaderResolver = new LoaderResolver([$yamlLoader]);
        $delegatingLoader = new DelegatingLoader($loaderResolver);
        $delegatingLoader->load('config.yml');
        $delegatingLoader->load('config_extra.yml');
        $resources = [new FileResource($locator->locate('config.yml', null, true)), new FileResource($locator->locate('config_extra.yml', null, true))];
        $processor = new Processor();
        $configuration = new AppConfiguration();
        $processedConfig = $processor->processConfiguration($configuration, $configBag->get('configs'));
        $configCache->write(json_encode($processedConfig), $resources);
    } else {
        $path = $configCache->getPath();
        $processedConfig = json_decode(file_get_contents($path), true);
    }
    return $processedConfig;
}
Esempio n. 19
0
 /**
  * Loads a resource.
  *
  * @param mixed  $resource A resource
  * @param string $type     The resource type
  *
  * @return RouteCollection A RouteCollection instance
  */
 public function load($resource, $type = null)
 {
     $collection = parent::load($resource, $type);
     foreach ($collection->all() as $route) {
         if ($controller = $route->getDefault('_controller')) {
             try {
                 $controller = $this->parser->parse($controller);
             } catch (\Exception $e) {
                 // unable to optimize unknown notation
             }
             $route->setDefault('_controller', $controller);
         }
     }
     return $collection;
 }
Esempio n. 20
0
 /** Load configuration from array or file. */
 public static function load($config)
 {
     $loaderResolver = new LoaderResolver(array(new Config\ArrayConfigLoader(), new Config\JsonConfigLoader(), new Config\YamlConfigLoader()));
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     try {
         $config = $delegatingLoader->load($config);
     } catch (FileLoaderLoadException $ex) {
         // Thrown when no loader matches given config
         throw new \Exception("Unsupported configuration format.", 0, $ex);
     }
     $processor = new Processor();
     $tree = self::getConfigTreeBuilder()->buildTree();
     $config = $processor->process($tree, array($config));
     self::$config = self::processConfig($config);
 }
Esempio n. 21
0
 /**
  * @param $fullPath
  * @param $activeFormats
  * @param $globalOptions
  */
 protected function setFormatsFromFile($fullPath, &$activeFormats, $globalOptions)
 {
     $folder = dirname($fullPath);
     $fileName = basename($fullPath);
     $locator = new FileLocator($folder);
     $xmlLoader10 = new XmlFormatLoader10($locator);
     $xmlLoader11 = new XmlFormatLoader11($locator);
     $xmlLoader10->setGlobalOptions($globalOptions);
     $xmlLoader11->setGlobalOptions($globalOptions);
     $resolver = new LoaderResolver([$xmlLoader10, $xmlLoader11]);
     $loader = new DelegatingLoader($resolver);
     $themeFormats = $loader->load($fileName);
     foreach ($themeFormats as $format) {
         $activeFormats[$format['key']] = $format;
     }
 }
 /**
  * @return mixed
  * @throws \Exception
  * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  */
 private function loadConfig()
 {
     $configDir = new FileLocator(static::$configDir);
     $loader = new YamlFileLoader($configDir);
     $loaderResolver = new LoaderResolver([$loader]);
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     try {
         $config = $delegatingLoader->load(static::$configFileName);
         //var_dump($config);
         //$dumper = new YamlReferenceDumper();
         //$dumper->dump(new CursorCleanerConfiguration());
     } catch (InvalidConfigurationException $e) {
         echo $e->getMessage() . PHP_EOL;
         throw $e;
     }
     return $config;
 }
Esempio n. 23
0
 /**
  * {@inheritdoc}
  */
 public function load($resource, $type = null)
 {
     if ($this->loading) {
         // This can happen if a fatal error occurs in parent::load().
         // Here is the scenario:
         // - while routes are being loaded by parent::load() below, a fatal error
         //   occurs (e.g. parse error in a controller while loading annotations);
         // - PHP abruptly empties the stack trace, bypassing all catch blocks;
         //   it then calls the registered shutdown functions;
         // - the ErrorHandler catches the fatal error and re-injects it for rendering
         //   thanks to HttpKernel->terminateWithException() (that calls handleException());
         // - at this stage, if we try to load the routes again, we must prevent
         //   the fatal error from occurring a second time,
         //   otherwise the PHP process would be killed immediately;
         // - while rendering the exception page, the router can be required
         //   (by e.g. the web profiler that needs to generate an URL);
         // - this handles the case and prevents the second fatal error
         //   by triggering an exception beforehand.
         throw new FileLoaderLoadException($resource);
     }
     $this->loading = true;
     try {
         $collection = parent::load($resource, $type);
     } catch (\Exception $e) {
         $this->loading = false;
         throw $e;
     } catch (\Throwable $e) {
         $this->loading = false;
         throw $e;
     }
     $this->loading = false;
     foreach ($collection->all() as $route) {
         if ($controller = $route->getDefault('_controller')) {
             try {
                 $controller = $this->parser->parse($controller);
             } catch (\InvalidArgumentException $e) {
                 // unable to optimize unknown notation
             }
             $route->setDefault('_controller', $controller);
         }
     }
     return $collection;
 }
Esempio n. 24
0
 public function loadContainer()
 {
     if (empty($this->appDir) || empty($this->configDirectories)) {
         throw new \Exception(__CLASS__ . ': Missing required properties (appDir, configDirectories)');
     }
     $container = new ContainerBuilder();
     $container->setParameter('app_dir', $this->appDir);
     $container->setParameter('amp_src_dir', dirname(__DIR__));
     $container->setParameter('log_dir', $this->appDir . DIRECTORY_SEPARATOR . 'log');
     $container->setParameter('my_cnf_dir', $this->appDir . DIRECTORY_SEPARATOR . 'my.cnf.d');
     $container->setParameter('apache_dir', $this->appDir . DIRECTORY_SEPARATOR . 'apache.d');
     //$container->setParameter('apache24_dir', $this->appDir . DIRECTORY_SEPARATOR . 'apache.d');
     $container->setParameter('apache_tpl', implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Templates', 'apache-vhost.php')));
     $container->setParameter('apache24_tpl', implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Templates', 'apache24-vhost.php')));
     $container->setParameter('nginx_dir', $this->appDir . DIRECTORY_SEPARATOR . 'nginx.d');
     $container->setParameter('nginx_tpl', implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Templates', 'nginx-vhost.php')));
     $container->setParameter('instances_yml', $this->appDir . DIRECTORY_SEPARATOR . 'instances.yml');
     $container->setParameter('config_yml', $this->appDir . DIRECTORY_SEPARATOR . 'services.yml');
     $container->setParameter('ram_disk_dir', $this->appDir . DIRECTORY_SEPARATOR . 'ram_disk');
     $fs = new Filesystem();
     $fs->mkdir(array($this->appDir, $container->getParameter('log_dir'), $container->getParameter('my_cnf_dir'), $container->getParameter('apache_dir'), $container->getParameter('nginx_dir')));
     $locator = new FileLocator($this->configDirectories);
     $loaderResolver = new LoaderResolver(array(new YamlFileLoader($container, $locator)));
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     foreach (array('services.yml') as $file) {
         $yamlUserFiles = $locator->locate($file, NULL, FALSE);
         foreach ($yamlUserFiles as $file) {
             $delegatingLoader->load($file);
         }
     }
     if (getenv('AMP_INSTANCES_TIMEOUT')) {
         $container->setParameter('instances_timeout', getenv('AMP_INSTANCES_TIMEOUT'));
     }
     // TODO: If we load default configuration first, the version paramter will always be here.
     $dbParam = $container->hasParameter('db_type') ? 'db_type' : 'mysql_type';
     $container->setAlias('db', 'db.' . $container->getParameter($dbParam));
     $container->setAlias('httpd', 'httpd.' . $container->getParameter('httpd_type'));
     $container->setAlias('perm', 'perm.' . $container->getParameter('perm_type'));
     $container->setAlias('ram_disk', 'ram_disk.' . $container->getParameter('ram_disk_type'));
     $container->setAlias('hosts', 'hosts.' . $container->getParameter('hosts_type'));
     $this->container = $container;
 }
Esempio n. 25
0
 private function initializeConfig()
 {
     if ($this->loaded) {
         return;
     }
     $this->loaded = true;
     if ([] === ($filenames = (array) $this['config.filenames'])) {
         return;
     }
     $parameterBag = new EnvPlaceholderParameterBag($this['config.replacements']);
     $locator = new FileLocator();
     $loaders = [new PhpFileLoader($this, $locator), new DirectoryLoader($locator)];
     if (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
         $loaders[] = new YamlFileLoader($this, $parameterBag, $locator);
     }
     $loader = new DelegatingLoader(new LoaderResolver($loaders));
     foreach ($filenames as $path) {
         $loader->load($parameterBag->resolveValue($path));
     }
 }
Esempio n. 26
0
 /**
  * Read the config
  *
  * @param string $dir filepath to the package directory
  *
  * @return array the full config
  *
  * @throws \DomainException if the config is invalid
  */
 public function getConfig($dir)
 {
     // load
     try {
         // all this stuff is not really necessary but this component is kewl
         // and I want to use it.
         // A better configuration handling => better programing
         $delegatingLoader = new DelegatingLoader(new LoaderResolver(array(new Loader())));
         $config = $delegatingLoader->load($dir);
     } catch (FileLoaderLoadException $e) {
         $config = array();
     }
     // validates
     $processor = new Processor();
     $configuration = new Validator();
     try {
         $processedConfig = $processor->processConfiguration($configuration, array($config));
     } catch (InvalidConfigurationException $e) {
         throw new \DomainException($e->getMessage());
     }
     return $processedConfig;
 }
Esempio n. 27
0
 public function load()
 {
     $config = array();
     $yamlLoader = new YamlFileLoader($this->locator);
     $loaderResolver = new LoaderResolver(array($yamlLoader));
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     foreach ($this->files as $filename) {
         $values = $delegatingLoader->load($filename);
         $config = array_replace_recursive($config, $values);
     }
     $replacements = $this->parameterBag->all();
     array_walk_recursive($config, function (&$item, $key, $replacements) {
         foreach ($replacements as $needle => $replace) {
             if (false !== strpos($item, '%' . $needle . '%')) {
                 $item = str_replace('%' . $needle . '%', $replace, $item);
             }
         }
     }, $replacements);
     // process configuration
     $processor = new Processor();
     $config = $processor->processConfiguration(new Configuration(), array($config));
     return $config;
 }
Esempio n. 28
0
 /**
  * Constructor
  *
  * @param null $userAgent
  */
 public function __construct($userAgent = null)
 {
     $this->confContainer = new ConfContainer();
     $yfl = new YamlFileLoader($this->confContainer, new FileLocator($this->getConfigPath()));
     $loaderResolver = new LoaderResolver(array($yfl));
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     $delegatingLoader->load($this->getConfigFile());
     $this->parser = new Parser($this->confContainer);
     $this->mapper = new Mapper();
     $this->mapper->setMap(self::MAP_NAME_BROWSER, $this->confContainer->getMappings()->getBrowser());
     $this->mapper->setMap(self::MAP_NAME_BROWSER_FAMILY, $this->confContainer->getMappings()->getBrowserFamily());
     $this->mapper->setMap(self::MAP_NAME_DESKTOP_OS, $this->confContainer->getMappings()->getDesktopOs());
     $this->mapper->setMap(self::MAP_NAME_DEVICE_BRAND, $this->confContainer->getMappings()->getDeviceBrand());
     $this->mapper->setMap(self::MAP_NAME_DEVICE_TYPE, $this->confContainer->getMappings()->getDeviceType());
     $this->mapper->setMap(self::MAP_NAME_OS_FAMILY, $this->confContainer->getMappings()->getOsFamily());
     $this->mapper->setMap(self::MAP_NAME_OS_SHORT, $this->confContainer->getMappings()->getOsShort());
     $this->browser = new Browser();
     $this->device = new Device();
     $this->os = new Os();
     if (!is_null($userAgent)) {
         $this->setUserAgent($userAgent);
     }
 }
Esempio n. 29
0
 private function createListenerFactories(ContainerBuilder $container, $config)
 {
     if (null !== $this->factories) {
         return $this->factories;
     }
     // load service templates
     $c = new ContainerBuilder();
     $parameterBag = $container->getParameterBag();
     $locator = new FileLocator(__DIR__ . '/../Resources/config');
     $resolver = new LoaderResolver(array(new XmlFileLoader($c, $locator), new YamlFileLoader($c, $locator), new PhpFileLoader($c, $locator)));
     $loader = new DelegatingLoader($resolver);
     $loader->load('security_factories.xml');
     // load user-created listener factories
     foreach ($config['factories'] as $factory) {
         $loader->load($parameterBag->resolveValue($factory));
     }
     $tags = $c->findTaggedServiceIds('security.listener.factory');
     $factories = array();
     foreach ($this->listenerPositions as $position) {
         $factories[$position] = array();
     }
     foreach (array_keys($tags) as $tag) {
         $factory = $c->get($tag);
         $factories[$factory->getPosition()][] = $factory;
     }
     return $this->factories = $factories;
 }
Esempio n. 30
0
 public function load($resource, $type = null)
 {
     /** @var RouteCollection $collection */
     $collection = parent::load($resource, null);
     $straightRoutes = [];
     $relativeRoutes = [];
     foreach ($collection as $name => $route) {
         /** @var Route $route */
         if (preg_match('|\\%([a-z_]+)\\.path\\%|ius', $route->getPath(), $matches)) {
             $path = $matches[1];
             $relativeRoutes[$path][$name] = $route;
         } else {
             $route->setDefault('_structure_type', $name);
             $straightRoutes[$name] = $route;
         }
         $collection->remove($name);
     }
     $structureRepository = $this->getEntityManager()->getRepository('OctavaStructureBundle:Structure');
     /** @var Structure[] $structureData */
     $structureData = $structureRepository->getActiveListByTypes(array_keys($straightRoutes));
     foreach ($straightRoutes as $name => $route) {
         if (!isset($structureData[$name]) || $name == 'octava_structure_empty') {
             $controllerFakePath = str_replace(':', '_', $route->getDefault('_controller'));
             $route->setPath('/octava/structure/error404/' . $controllerFakePath)->setDefault('_controller', 'OctavaStructureBundle:Default:error404');
             $collection->add($name, $route);
             continue;
         }
         $counter = 0;
         foreach ($structureData[$name] as $structureItem) {
             /** @var Structure $structureItem */
             $workRoute = clone $route;
             $workRoute->setPath(rtrim($structureItem->getPath(), '/') . '/' . ltrim($workRoute->getPath(), '/'));
             $workRoute->setDefault(Structure::ROUTING_ID_NAME, $structureItem->getId());
             $translatablePath = [];
             foreach ($structureRepository->getTranslatablePath($structureItem) as $l => $p) {
                 $path = rtrim($p, '/') . '/' . ltrim($route->getPath(), '/');
                 $translatablePath[$l] = $path;
             }
             $workRoute->setOption('translatable_path', $translatablePath);
             $saveName = $structureItem->getRouteName();
             $collection->add($saveName, $workRoute);
             if (isset($relativeRoutes[$name])) {
                 foreach ($relativeRoutes[$name] as $relativeName => $relativeRoute) {
                     /** @var Route $workRelativeRoute */
                     $workRelativeRoute = clone $relativeRoute;
                     $workRelativeName = $counter == 0 ? $relativeName : $relativeName . '_' . $counter;
                     $translatablePath = [];
                     foreach ($structureRepository->getTranslatablePath($structureItem) as $l => $p) {
                         $path = ltrim($workRelativeRoute->getPath(), '/');
                         $path = str_replace('%' . $name . '.path%', rtrim($p, '/'), $path);
                         $translatablePath[$l] = $path;
                     }
                     $path = trim($workRelativeRoute->getPath(), '/');
                     $path = str_replace('%' . $name . '.path%', rtrim($structureItem->getPath(), '/'), $path);
                     $workRelativeRoute->setPath($path)->setDefault(Structure::ROUTING_ID_NAME, $structureItem->getId())->setDefault('structureRelative', true)->setOption('translatable_path', $translatablePath);
                     $collection->add($workRelativeName, $workRelativeRoute);
                 }
             }
             $counter++;
         }
     }
     $collection->addResource(new FileResource(__FILE__));
     return $collection;
 }