Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function load(array $config, ContainerBuilder $container)
 {
     $processor = new Processor();
     $config = $processor->processConfiguration(new Configuration(), $config);
     $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $configFiles = ['services.xml', 'controller.xml', 'storage.xml', 'routing.xml', 'twig.xml'];
     foreach ($configFiles as $configFile) {
         $loader->load($configFile);
     }
     foreach ($config['resources'] as $alias => $resourceConfig) {
         $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
         $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : [];
         $resources = array_merge($resources, [$alias => $resourceConfig]);
         $container->setParameter('sylius.resources', $resources);
         DriverProvider::get($metadata)->load($container, $metadata);
         if ($metadata->hasParameter('translation') && class_exists(SyliusTranslationBundle::class)) {
             $alias = $alias . '_translation';
             $resourceConfig = array_merge(['driver' => $resourceConfig['driver']], $resourceConfig['translation']);
             $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : [];
             $resources = array_merge($resources, [$alias => $resourceConfig]);
             $container->setParameter('sylius.resources', $resources);
             $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
             DriverProvider::get($metadata)->load($container, $metadata);
         }
     }
     $container->setParameter('sylius.resource.settings', $config['settings']);
 }
 private function loadResources(array $resources, ContainerBuilder $container)
 {
     foreach ($resources as $alias => $resourceConfig) {
         $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
         $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : [];
         $resources = array_merge($resources, [$alias => $resourceConfig]);
         $container->setParameter('sylius.resources', $resources);
         DriverProvider::get($metadata)->load($container, $metadata);
         if ($metadata->hasParameter('translation')) {
             $alias = $alias . '_translation';
             $resourceConfig = array_merge(['driver' => $resourceConfig['driver']], $resourceConfig['translation']);
             $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : [];
             $resources = array_merge($resources, [$alias => $resourceConfig]);
             $container->setParameter('sylius.resources', $resources);
             $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
             DriverProvider::get($metadata)->load($container, $metadata);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function load(array $config, ContainerBuilder $container)
 {
     $processor = new Processor();
     $config = $processor->processConfiguration(new Configuration(), $config);
     $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $configFiles = ['services.xml', 'controller.xml', 'storage.xml', 'routing.xml', 'twig.xml'];
     foreach ($configFiles as $configFile) {
         $loader->load($configFile);
     }
     $bundles = $container->getParameter('kernel.bundles');
     if (array_key_exists('SyliusGridBundle', $bundles)) {
         $loader->load('grid.xml');
     }
     if ($config['translation']['enabled']) {
         $loader->load('translation.xml');
         $container->setParameter('sylius.translation.default_locale', $config['translation']['default_locale']);
         $container->setAlias('sylius.translation.locale_provider', $config['translation']['locale_provider']);
         $container->setAlias('sylius.translation.available_locales_provider', $config['translation']['available_locales_provider']);
         $container->setParameter('sylius.translation.available_locales', $config['translation']['available_locales']);
     }
     foreach ($config['resources'] as $alias => $resourceConfig) {
         $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
         $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : [];
         $resources = array_merge($resources, [$alias => $resourceConfig]);
         $container->setParameter('sylius.resources', $resources);
         DriverProvider::get($metadata)->load($container, $metadata);
         if ($metadata->hasParameter('translation')) {
             $alias = $alias . '_translation';
             $resourceConfig = array_merge(['driver' => $resourceConfig['driver']], $resourceConfig['translation']);
             $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : [];
             $resources = array_merge($resources, [$alias => $resourceConfig]);
             $container->setParameter('sylius.resources', $resources);
             $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
             DriverProvider::get($metadata)->load($container, $metadata);
         }
     }
     $container->setParameter('sylius.resource.settings', $config['settings']);
     $container->setAlias('sylius.resource_controller.authorization_checker', $config['authorization_checker']);
 }
 /**
  * @param string $applicationName
  * @param string $driver
  * @param array $resources
  * @param ContainerBuilder $container
  */
 protected function registerResources($applicationName, $driver, array $resources, ContainerBuilder $container)
 {
     $container->setParameter(sprintf('%s.driver.%s', $this->getAlias(), $driver), true);
     $container->setParameter(sprintf('%s.driver', $this->getAlias()), $driver);
     foreach ($resources as $resourceName => $resourceConfig) {
         $alias = $applicationName . '.' . $resourceName;
         $resourceConfig = array_merge(array('driver' => $driver), $resourceConfig);
         $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : array();
         $resources = array_merge($resources, array($alias => $resourceConfig));
         $container->setParameter('sylius.resources', $resources);
         $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
         DriverProvider::get($metadata)->load($container, $metadata);
         if ($metadata->hasParameter('translation')) {
             $alias = $alias . '_translation';
             $resourceConfig = array_merge(array('driver' => $driver), $resourceConfig['translation']);
             $resources = $container->hasParameter('sylius.resources') ? $container->getParameter('sylius.resources') : array();
             $resources = array_merge($resources, array($alias => $resourceConfig));
             $container->setParameter('sylius.resources', $resources);
             $metadata = Metadata::fromAliasAndConfiguration($alias, $resourceConfig);
             DriverProvider::get($metadata)->load($container, $metadata);
         }
     }
 }