discoverServiceProviders example


  public function testDiscoverServiceCustom() {
    new Settings([
      'container_yamls' => [
        __DIR__ . '/fixtures/custom.yml',
      ],
    ]);

    $kernel = new DrupalKernel('prod', new ClassLoader());
    $kernel->discoverServiceProviders();

    $reflected_yamls = (new \ReflectionObject($kernel))->getProperty('serviceYamls');

    $expect = [
      'app' => [
        'core' => 'core/core.services.yml',
      ],
      'site' => [
        __DIR__ . '/fixtures/custom.yml',
      ],
    ];
    
$container->compile();
    return $container;
  }

  /** * Registers all service providers to the kernel. * * @throws \LogicException */
  protected function initializeServiceProviders() {
    $this->discoverServiceProviders();
    $this->serviceProviders = [
      'app' => [],
      'site' => [],
    ];
    foreach ($this->serviceProviderClasses as $origin => $classes) {
      foreach ($classes as $name => $class) {
        if (!is_object($class)) {
          $this->serviceProviders[$origin][$name] = new $class();
        }
        else {
          $this->serviceProviders[$origin][$name] = $class;
        }

class UpdateKernel extends DrupalKernel {

  /** * {@inheritdoc} */
  public function discoverServiceProviders() {
    parent::discoverServiceProviders();

    $this->serviceProviderClasses['app']['update_kernel'] = 'Drupal\Core\Update\UpdateServiceProvider';
  }

  /** * {@inheritdoc} */
  protected function initializeContainer() {
    // Always force a container rebuild, in order to be able to override some     // services, see \Drupal\Core\Update\UpdateServiceProvider.     $this->containerNeedsRebuild = TRUE;
    
    if (!is_dir('public://simpletest') && !@mkdir('public://simpletest', 0777, TRUE) && !is_dir('public://simpletest')) {
      throw new \RuntimeException('Unable to create directory: public://simpletest');
    }

    return $this;
  }

  /** * {@inheritdoc} */
  public function discoverServiceProviders() {
    parent::discoverServiceProviders();
    // The test runner does not require an installed Drupal site to exist.     // Therefore, its environment is identical to that of the early installer.     $this->serviceProviderClasses['app']['Test'] = 'Drupal\Core\Installer\InstallerServiceProvider';
    return $this->serviceProviderClasses;
  }

}
Home | Imprint | This part of the site doesn't use cookies.