/**
  * Registers Twig services.
  *
  * This method is public and static so that it can be reused in the installer.
  */
 public static function registerTwig(ContainerBuilder $container)
 {
     $container->register('twig.loader.filesystem', 'Twig_Loader_Filesystem')->addArgument(DRUPAL_ROOT);
     $container->setAlias('twig.loader', 'twig.loader.filesystem');
     $twig_extension = new Definition('Drupal\\Core\\Template\\TwigExtension');
     $twig_extension->addMethodCall('setGenerators', array(new Reference('url_generator')));
     $container->register('twig', 'Drupal\\Core\\Template\\TwigEnvironment')->addArgument(new Reference('twig.loader'))->addArgument(array('cache' => drupal_installation_attempted() ? FALSE : Settings::get('twig_cache', TRUE), 'autoescape' => TRUE, 'debug' => Settings::get('twig_debug', FALSE), 'auto_reload' => Settings::get('twig_auto_reload', NULL)))->addArgument(new Reference('module_handler'))->addArgument(new Reference('theme_handler'))->addMethodCall('addExtension', array($twig_extension))->addMethodCall('addExtension', array(new Definition('Twig_Extension_Debug')))->addTag('service_collector', array('tag' => 'twig.extension', 'call' => 'addExtension'));
 }
 /**
  * {@inheritdoc}
  */
 public function register(ContainerBuilder $container)
 {
     if (!empty($GLOBALS['conf']['update_service_provider_overrides'])) {
         // Disable the Lock service.
         $container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
         // Prevent config from being accessed via a cache wrapper by removing
         // any existing definition and setting an alias to the actual storage.
         $container->removeDefinition('config.storage');
         $container->setAlias('config.storage', 'config.storage.active');
         $container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
         $container->register('router.builder', 'Drupal\\Core\\Routing\\RouteBuilderStatic');
         $container->register('theme_handler', 'Drupal\\Core\\Extension\\ThemeHandler')->addArgument(new Reference('config.factory'))->addArgument(new Reference('module_handler'))->addArgument(new Reference('state'))->addArgument(new Reference('info_parser'));
     }
 }
Esempio n. 3
0
 /**
  * Registers test-specific services.
  *
  * Extend this method in your test to register additional services. This
  * method is called whenever the kernel is rebuilt.
  *
  * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
  *   The service container to enhance.
  *
  * @see \Drupal\Tests\KernelTestBase::bootKernel()
  */
 public function register(ContainerBuilder $container)
 {
     // Keep the container object around for tests.
     $this->container = $container;
     $container->register('flood', 'Drupal\\Core\\Flood\\MemoryBackend')->addArgument(new Reference('request_stack'));
     $container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
     $container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
     $container->register('keyvalue.memory', 'Drupal\\Core\\KeyValueStore\\KeyValueMemoryFactory')->addTag('persist');
     $container->setAlias('keyvalue', 'keyvalue.memory');
     // Set the default language on the minimal container.
     $container->setParameter('language.default_values', Language::$defaultValues);
     if ($this->strictConfigSchema) {
         $container->register('simpletest.config_schema_checker', 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker')->addArgument(new Reference('config.typed'))->addArgument($this->getConfigSchemaExclusions())->addTag('event_subscriber');
     }
     if ($container->hasDefinition('path_processor_alias')) {
         // Prevent the alias-based path processor, which requires a url_alias db
         // table, from being registered to the path processor manager. We do this
         // by removing the tags that the compiler pass looks for. This means the
         // url generator can safely be used within tests.
         $container->getDefinition('path_processor_alias')->clearTag('path_processor_inbound')->clearTag('path_processor_outbound');
     }
     if ($container->hasDefinition('password')) {
         $container->getDefinition('password')->setArguments(array(1));
     }
     TestServiceProvider::addRouteProvider($container);
 }
Esempio n. 4
0
 /**
  * Parses a definition.
  *
  * @param string $id
  * @param array  $service
  * @param string $file
  *
  * @throws InvalidArgumentException When tags are invalid
  */
 private function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     }
     if (!is_array($service)) {
         throw new InvalidArgumentException(sprintf('A service definition must be an array or a string starting with "@" but %s found for service "%s" in %s. Check your YAML syntax.', gettype($service), $id, $file));
     }
     if (isset($service['alias'])) {
         $public = !array_key_exists('public', $service) || (bool) $service['public'];
         $this->container->setAlias($id, new Alias($service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['scope'])) {
         $definition->setScope($service['scope']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['synchronized'])) {
         $definition->setSynchronized($service['synchronized'], 'request' !== $id);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory'])) {
         if (is_string($service['factory'])) {
             if (strpos($service['factory'], ':') !== false && strpos($service['factory'], '::') === false) {
                 $parts = explode(':', $service['factory']);
                 $definition->setFactory(array($this->resolveServices('@' . $parts[0]), $parts[1]));
             } else {
                 $definition->setFactory($service['factory']);
             }
         } else {
             $definition->setFactory(array($this->resolveServices($service['factory'][0]), $service['factory'][1]));
         }
     }
     if (isset($service['factory_class'])) {
         $definition->setFactoryClass($service['factory_class']);
     }
     if (isset($service['factory_method'])) {
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         $definition->setFactoryService($service['factory_service']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         if (is_string($service['configurator'])) {
             $definition->setConfigurator($service['configurator']);
         } else {
             $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
         }
     }
     if (isset($service['calls'])) {
         if (!is_array($service['calls'])) {
             throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['calls'] as $call) {
             if (isset($call['method'])) {
                 $method = $call['method'];
                 $args = isset($call['arguments']) ? $this->resolveServices($call['arguments']) : array();
             } else {
                 $method = $call[0];
                 $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             }
             $definition->addMethodCall($method, $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!is_array($tag)) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
             }
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s. Check your YAML syntax.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     if (isset($service['decorates'])) {
         $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
         $definition->setDecoratedService($service['decorates'], $renameId);
     }
     $this->container->setDefinition($id, $definition);
 }
Esempio n. 5
0
  /**
   * Registers test-specific services.
   *
   * Extend this method in your test to register additional services. This
   * method is called whenever the kernel is rebuilt.
   *
   * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
   *   The service container to enhance.
   *
   * @see \Drupal\Tests\KernelTestBase::bootKernel()
   */
  public function register(ContainerBuilder $container) {
    // Keep the container object around for tests.
    $this->container = $container;

    $container
      ->register('flood', 'Drupal\Core\Flood\MemoryBackend')
      ->addArgument(new Reference('request_stack'));
    $container
      ->register('lock', 'Drupal\Core\Lock\NullLockBackend');
    $container
      ->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory');
    $container
      ->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory')
      // Must persist container rebuilds, or all data would vanish otherwise.
      ->addTag('persist');
    $container
      ->setAlias('keyvalue', 'keyvalue.memory');

    if ($this->strictConfigSchema) {
      $container
        ->register('simpletest.config_schema_checker', 'Drupal\Core\Config\Testing\ConfigSchemaChecker')
        ->addArgument(new Reference('config.typed'))
        ->addTag('event_subscriber');
    }

    if ($container->hasDefinition('path_processor_alias')) {
      // Prevent the alias-based path processor, which requires a url_alias db
      // table, from being registered to the path processor manager. We do this
      // by removing the tags that the compiler pass looks for. This means the
      // url generator can safely be used within tests.
      $container->getDefinition('path_processor_alias')
        ->clearTag('path_processor_inbound')
        ->clearTag('path_processor_outbound');
    }

    if ($container->hasDefinition('password')) {
      $container->getDefinition('password')
        ->setArguments(array(1));
    }
  }
Esempio n. 6
0
 /**
  * Parses a definition.
  *
  * @param string $id
  * @param array  $service
  * @param string $file
  *
  * @throws InvalidArgumentException When tags are invalid
  */
 private function parseDefinition($id, $service, $file)
 {
     if (is_string($service) && 0 === strpos($service, '@')) {
         $this->container->setAlias($id, substr($service, 1));
         return;
     } elseif (isset($service['alias'])) {
         $public = !array_key_exists('public', $service) || (bool) $service['public'];
         $this->container->setAlias($id, new Alias($service['alias'], $public));
         return;
     }
     if (isset($service['parent'])) {
         $definition = new DefinitionDecorator($service['parent']);
     } else {
         $definition = new Definition();
     }
     if (isset($service['class'])) {
         $definition->setClass($service['class']);
     }
     if (isset($service['scope'])) {
         $definition->setScope($service['scope']);
     }
     if (isset($service['synthetic'])) {
         $definition->setSynthetic($service['synthetic']);
     }
     if (isset($service['synchronized'])) {
         $definition->setSynchronized($service['synchronized']);
     }
     if (isset($service['lazy'])) {
         $definition->setLazy($service['lazy']);
     }
     if (isset($service['public'])) {
         $definition->setPublic($service['public']);
     }
     if (isset($service['abstract'])) {
         $definition->setAbstract($service['abstract']);
     }
     if (isset($service['factory_class'])) {
         $definition->setFactoryClass($service['factory_class']);
     }
     if (isset($service['factory_method'])) {
         $definition->setFactoryMethod($service['factory_method']);
     }
     if (isset($service['factory_service'])) {
         $definition->setFactoryService($service['factory_service']);
     }
     if (isset($service['file'])) {
         $definition->setFile($service['file']);
     }
     if (isset($service['arguments'])) {
         $definition->setArguments($this->resolveServices($service['arguments']));
     }
     if (isset($service['properties'])) {
         $definition->setProperties($this->resolveServices($service['properties']));
     }
     if (isset($service['configurator'])) {
         if (is_string($service['configurator'])) {
             $definition->setConfigurator($service['configurator']);
         } else {
             $definition->setConfigurator(array($this->resolveServices($service['configurator'][0]), $service['configurator'][1]));
         }
     }
     if (isset($service['calls'])) {
         foreach ($service['calls'] as $call) {
             $args = isset($call[1]) ? $this->resolveServices($call[1]) : array();
             $definition->addMethodCall($call[0], $args);
         }
     }
     if (isset($service['tags'])) {
         if (!is_array($service['tags'])) {
             throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file));
         }
         foreach ($service['tags'] as $tag) {
             if (!isset($tag['name'])) {
                 throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file));
             }
             $name = $tag['name'];
             unset($tag['name']);
             foreach ($tag as $attribute => $value) {
                 if (!is_scalar($value) && null !== $value) {
                     throw new InvalidArgumentException(sprintf('A "tags" attribute must be of a scalar-type for service "%s", tag "%s", attribute "%s" in %s.', $id, $name, $attribute, $file));
                 }
             }
             $definition->addTag($name, $tag);
         }
     }
     $this->container->setDefinition($id, $definition);
 }