DrupalKernel.php 45.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Definition of Drupal\Core\DrupalKernel.
 */

namespace Drupal\Core;

10
use Drupal\Component\FileCache\FileCacheFactory;
11
use Drupal\Component\ProxyBuilder\ProxyDumper;
12
13
14
15
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Timer;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\UrlHelper;
16
use Drupal\Core\Config\BootstrapConfigStorageFactory;
17
use Drupal\Core\Config\NullStorage;
18
use Drupal\Core\Database\Database;
19
use Drupal\Core\DependencyInjection\ContainerBuilder;
20
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
21
use Drupal\Core\DependencyInjection\YamlFileLoader;
22
use Drupal\Core\Extension\ExtensionDiscovery;
23
use Drupal\Core\File\MimeType\MimeTypeGuesser;
24
use Drupal\Core\Http\TrustedHostsRequestFactory;
25
use Drupal\Core\Language\Language;
26
use Drupal\Core\PageCache\RequestPolicyInterface;
27
use Drupal\Core\PhpStorage\PhpStorageFactory;
28
use Drupal\Core\ProxyBuilder\ProxyBuilder;
29
use Drupal\Core\Site\Settings;
30
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
31
use Symfony\Component\DependencyInjection\ContainerInterface;
32
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
33
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
34
use Symfony\Component\HttpFoundation\RedirectResponse;
35
use Symfony\Component\HttpFoundation\Request;
36
use Symfony\Component\HttpFoundation\RequestStack;
37
use Symfony\Component\HttpFoundation\Response;
38
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
39
use Symfony\Component\HttpKernel\TerminableInterface;
40
use Symfony\Component\Routing\Route;
41
42
43

/**
 * The DrupalKernel class is the core of Drupal itself.
44
45
 *
 * This class is responsible for building the Dependency Injection Container and
46
47
48
49
50
51
52
53
 * also deals with the registration of service providers. It allows registered
 * service providers to add their services to the container. Core provides the
 * CoreServiceProvider, which, in addition to registering any core services that
 * cannot be registered in the core.services.yaml file, adds any compiler passes
 * needed by core, e.g. for processing tagged services. Each module can add its
 * own service provider, i.e. a class implementing
 * Drupal\Core\DependencyInjection\ServiceProvider, to register services to the
 * container, or modify existing services.
54
 */
55
56
class DrupalKernel implements DrupalKernelInterface, TerminableInterface {

57
  const CONTAINER_BASE_CLASS = '\Drupal\Core\DependencyInjection\Container';
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

  /**
   * Holds the container instance.
   *
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * The environment, e.g. 'testing', 'install'.
   *
   * @var string
   */
  protected $environment;

  /**
   * Whether the kernel has been booted.
   *
   * @var bool
   */
78
  protected $booted = FALSE;
79

80
81
82
83
84
85
86
  /**
   * Whether essential services have been set up properly by preHandle().
   *
   * @var bool
   */
  protected $prepared = FALSE;

87
88
89
90
  /**
   * Holds the list of enabled modules.
   *
   * @var array
91
92
   *   An associative array whose keys are module names and whose values are
   *   ignored.
93
94
95
   */
  protected $moduleList;

96
  /**
97
   * List of available modules and installation profiles.
98
   *
99
   * @var \Drupal\Core\Extension\Extension[]
100
   */
101
  protected $moduleData = array();
102
103
104
105
106
107
108
109

  /**
   * PHP code storage object to use for the compiled container.
   *
   * @var \Drupal\Component\PhpStorage\PhpStorageInterface
   */
  protected $storage;

110
  /**
111
   * The class loader object.
112
   *
113
   * @var \Composer\Autoload\ClassLoader
114
115
116
   */
  protected $classLoader;

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  /**
   * Config storage object used for reading enabled modules configuration.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $configStorage;

  /**
   * Whether the container can be dumped.
   *
   * @var bool
   */
  protected $allowDumping;

  /**
   * Whether the container needs to be dumped once booting is complete.
   *
   * @var bool
   */
  protected $containerNeedsDumping;

138
  /**
139
140
141
142
143
144
   * List of discovered services.yml pathnames.
   *
   * This is a nested array whose top-level keys are 'app' and 'site', denoting
   * the origin of a service provider. Site-specific providers have to be
   * collected separately, because they need to be processed last, so as to be
   * able to override services from application service providers.
145
146
147
148
149
   *
   * @var array
   */
  protected $serviceYamls;

150
  /**
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
   * List of discovered service provider class names.
   *
   * This is a nested array whose top-level keys are 'app' and 'site', denoting
   * the origin of a service provider. Site-specific providers have to be
   * collected separately, because they need to be processed last, so as to be
   * able to override services from application service providers.
   *
   * @var array
   */
  protected $serviceProviderClasses;

  /**
   * List of instantiated service provider classes.
   *
   * @see \Drupal\Core\DrupalKernel::$serviceProviderClasses
166
167
168
169
170
   *
   * @var array
   */
  protected $serviceProviders;

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  /**
   * Whether the PHP environment has been initialized.
   *
   * This legacy phase can only be booted once because it sets session INI
   * settings. If a session has already been started, re-generating these
   * settings would break the session.
   *
   * @var bool
   */
  protected static $isEnvironmentInitialized = FALSE;

  /**
   * The site directory.
   *
   * @var string
   */
  protected $sitePath;

189
190
191
192
193
194
195
  /**
   * The app root.
   *
   * @var string
   */
  protected $root;

196
197
198
199
  /**
   * Create a DrupalKernel object from a request.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
200
201
202
203
204
   *   The request.
   * @param $class_loader
   *   The class loader. Normally Composer's ClassLoader, as included by the
   *   front controller, but may also be decorated; e.g.,
   *   \Symfony\Component\ClassLoader\ApcClassLoader.
205
206
207
208
209
   * @param string $environment
   *   String indicating the environment, e.g. 'prod' or 'dev'.
   * @param bool $allow_dumping
   *   (optional) FALSE to stop the container from being written to or read
   *   from disk. Defaults to TRUE.
210
   *
211
   * @return static
212
213
214
   *
   * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
   *   In case the host name in the request is not trusted.
215
   */
216
  public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE) {
217
    // Include our bootstrap file.
218
219
    $core_root = dirname(dirname(dirname(__DIR__)));
    require_once $core_root . '/includes/bootstrap.inc';
220
    $class_loader_class = get_class($class_loader);
221
222
223
224
225
226
227

    $kernel = new static($environment, $class_loader, $allow_dumping);

    // Ensure sane php environment variables..
    static::bootEnvironment();

    // Get our most basic settings setup.
228
229
230
    $site_path = static::findSitePath($request);
    $kernel->setSitePath($site_path);
    Settings::initialize(dirname($core_root), $site_path, $class_loader);
231

232
233
    // Initialize our list of trusted HTTP Host headers to protect against
    // header attacks.
234
235
236
    $host_patterns = Settings::get('trusted_host_patterns', array());
    if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
      if (static::setupTrustedHosts($request, $host_patterns) === FALSE) {
237
238
239
240
        throw new BadRequestHttpException('The provided host name is not valid for this server.');
      }
    }

241
242
243
    // Redirect the user to the installation script if Drupal has not been
    // installed yet (i.e., if no $databases array has been defined in the
    // settings.php file) and we are not already installing.
244
    if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
245
246
247
248
      $response = new RedirectResponse($request->getBasePath() . '/core/install.php');
      $response->prepare($request)->send();
    }

249
250
251
252
253
254
255
256
257
258
259
260
261
    // If the class loader is still the same, possibly upgrade to the APC class
    // loader.
    if ($class_loader_class == get_class($class_loader)
        && Settings::get('class_loader_auto_detect', TRUE)
        && Settings::get('hash_salt', FALSE)
        && function_exists('apc_fetch')) {
      $prefix = 'drupal.' . hash('sha256', 'drupal.' . Settings::getHashSalt());
      $apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $class_loader);
      $class_loader->unregister();
      $apc_loader->register();
      $class_loader = $apc_loader;
    }

262
263
264
    // Ensure that the class loader reference is up-to-date.
    $kernel->classLoader = $class_loader;

265
266
267
    return $kernel;
  }

268
269
270
271
  /**
   * Constructs a DrupalKernel object.
   *
   * @param string $environment
272
   *   String indicating the environment, e.g. 'prod' or 'dev'.
273
274
275
276
   * @param $class_loader
   *   The class loader. Normally \Composer\Autoload\ClassLoader, as included by
   *   the front controller, but may also be decorated; e.g.,
   *   \Symfony\Component\ClassLoader\ApcClassLoader.
277
278
279
   * @param bool $allow_dumping
   *   (optional) FALSE to stop the container from being written to or read
   *   from disk. Defaults to TRUE.
280
   */
281
  public function __construct($environment, $class_loader, $allow_dumping = TRUE) {
282
    $this->environment = $environment;
283
    $this->classLoader = $class_loader;
284
    $this->allowDumping = $allow_dumping;
285
    $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
  }

  /**
   * Returns the appropriate site directory for a request.
   *
   * Once the kernel has been created DrupalKernelInterface::getSitePath() is
   * preferred since it gets the statically cached result of this method.
   *
   * Site directories contain all site specific code. This includes settings.php
   * for bootstrap level configuration, file configuration stores, public file
   * storage and site specific modules and themes.
   *
   * Finds a matching site directory file by stripping the website's hostname
   * from left to right and pathname from right to left. By default, the
   * directory must contain a 'settings.php' file for it to match. If the
   * parameter $require_settings is set to FALSE, then a directory without a
   * 'settings.php' file will match as well. The first configuration file found
   * will be used and the remaining ones will be ignored. If no configuration
   * file is found, returns a default value 'sites/default'. See
   * default.settings.php for examples on how the URL is converted to a
   * directory.
   *
   * If a file named sites.php is present in the sites directory, it will be
   * loaded prior to scanning for directories. That file can define aliases in
   * an associative array named $sites. The array is written in the format
   * '<port>.<domain>.<path>' => 'directory'. As an example, to create a
   * directory alias for http://www.drupal.org:8080/mysite/test whose
   * configuration file is in sites/example.com, the array should be defined as:
   * @code
   * $sites = array(
   *   '8080.www.drupal.org.mysite.test' => 'example.com',
   * );
   * @endcode
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request.
   * @param bool $require_settings
   *   Only directories with an existing settings.php file will be recognized.
   *   Defaults to TRUE. During initial installation, this is set to FALSE so
   *   that Drupal can detect a matching directory, then create a new
   *   settings.php file in it.
   *
   * @return string
   *   The path of the matching directory.
   *
331
332
333
   * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
   *   In case the host name in the request is invalid.
   *
334
335
336
337
338
339
   * @see \Drupal\Core\DrupalKernelInterface::getSitePath()
   * @see \Drupal\Core\DrupalKernelInterface::setSitePath()
   * @see default.settings.php
   * @see example.sites.php
   */
  public static function findSitePath(Request $request, $require_settings = TRUE) {
340
341
342
343
    if (static::validateHostname($request) === FALSE) {
      throw new BadRequestHttpException();
    }

344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
    // Check for a simpletest override.
    if ($test_prefix = drupal_valid_test_ua()) {
      return 'sites/simpletest/' . substr($test_prefix, 10);
    }

    // Determine whether multi-site functionality is enabled.
    if (!file_exists(DRUPAL_ROOT . '/sites/sites.php')) {
      return 'sites/default';
    }

    // Otherwise, use find the site path using the request.
    $script_name = $request->server->get('SCRIPT_NAME');
    if (!$script_name) {
      $script_name = $request->server->get('SCRIPT_FILENAME');
    }
359
    $http_host = $request->getHost();
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391

    $sites = array();
    include DRUPAL_ROOT . '/sites/sites.php';

    $uri = explode('/', $script_name);
    $server = explode('.', implode('.', array_reverse(explode(':', rtrim($http_host, '.')))));
    for ($i = count($uri) - 1; $i > 0; $i--) {
      for ($j = count($server); $j > 0; $j--) {
        $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
        if (isset($sites[$dir]) && file_exists(DRUPAL_ROOT . '/sites/' . $sites[$dir])) {
          $dir = $sites[$dir];
        }
        if (file_exists(DRUPAL_ROOT . '/sites/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/sites/' . $dir))) {
          return "sites/$dir";
        }
      }
    }
    return 'sites/default';
  }

  /**
   * {@inheritdoc}
   */
  public function setSitePath($path) {
    $this->sitePath = $path;
  }

  /**
   * {@inheritdoc}
   */
  public function getSitePath() {
    return $this->sitePath;
392
393
  }

394
395
396
397
398
399
400
  /**
   * {@inheritdoc}
   */
  public function getAppRoot() {
    return $this->root;
  }

401
  /**
402
   * {@inheritdoc}
403
404
405
   */
  public function boot() {
    if ($this->booted) {
406
407
408
409
410
411
412
413
414
      return $this;
    }

    // Start a page timer:
    Timer::start('page');

    // Ensure that findSitePath is set.
    if (!$this->sitePath) {
      throw new \Exception('Kernel does not have site path set before calling boot()');
415
    }
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435

    // Initialize the FileCacheFactory component. We have to do it here instead
    // of in \Drupal\Component\FileCache\FileCacheFactory because we can not use
    // the Settings object in a component.
    $configuration = Settings::get('file_cache');

    // Provide a default configuration, if not set.
    if (!isset($configuration['default'])) {
      $configuration['default'] = [
        'class' => '\Drupal\Component\FileCache\FileCache',
        'cache_backend_class' => NULL,
        'cache_backend_configuration' => [],
      ];
      // @todo Use extension_loaded('apcu') for non-testbot
      //  https://www.drupal.org/node/2447753.
      if (function_exists('apc_fetch')) {
        $configuration['default']['cache_backend_class'] = '\Drupal\Component\FileCache\ApcuFileCacheBackend';
      }
    }
    FileCacheFactory::setConfiguration($configuration);
436
    FileCacheFactory::setPrefix(hash('sha256', Settings::get('hash_salt')));
437

438
    // Initialize the container.
439
    $this->initializeContainer();
440
441
442
443
444
445

    // Ensure mt_rand() is reseeded to prevent random values from one page load
    // being exploited to predict random values in subsequent page loads.
    $seed = unpack("L", Crypt::randomBytes(4));
    mt_srand($seed[1]);

446
    $this->booted = TRUE;
447
448

    return $this;
449
450
  }

451
  /**
452
   * {@inheritdoc}
453
   */
454
455
456
457
  public function shutdown() {
    if (FALSE === $this->booted) {
      return;
    }
458
    $this->container->get('stream_wrapper_manager')->unregister();
459
    $this->booted = FALSE;
460
    $this->container = NULL;
461
462
    $this->moduleList = NULL;
    $this->moduleData = array();
463
464
465
466
467
468
469
470
471
  }

  /**
   * {@inheritdoc}
   */
  public function getContainer() {
    return $this->container;
  }

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
  /**
   * {@inheritdoc}
   */
  public function loadLegacyIncludes() {
    require_once $this->root . '/core/includes/common.inc';
    require_once $this->root . '/core/includes/database.inc';
    require_once $this->root . '/core/includes/module.inc';
    require_once $this->root . '/core/includes/theme.inc';
    require_once $this->root . '/core/includes/pager.inc';
    require_once $this->root . '/core/includes/menu.inc';
    require_once $this->root . '/core/includes/tablesort.inc';
    require_once $this->root . '/core/includes/file.inc';
    require_once $this->root . '/core/includes/unicode.inc';
    require_once $this->root . '/core/includes/form.inc';
    require_once $this->root . '/core/includes/errors.inc';
    require_once $this->root . '/core/includes/schema.inc';
    require_once $this->root . '/core/includes/entity.inc';
  }

491
  /**
492
   * {@inheritdoc}
493
   */
494
  public function preHandle(Request $request) {
495
496
497

    $this->loadLegacyIncludes();

498
499
500
    // Load all enabled modules.
    $this->container->get('module_handler')->loadAll();

501
502
503
    // Register stream wrappers.
    $this->container->get('stream_wrapper_manager')->register();

504
505
506
    // Initialize legacy request globals.
    $this->initializeRequestGlobals($request);

507
508
    // Put the request on the stack.
    $this->container->get('request_stack')->push($request);
509
510
511
512
513
514
515
516
517
518
519

    // Set the allowed protocols once we have the config available.
    $allowed_protocols = $this->container->get('config.factory')->get('system.filter')->get('protocols');
    if (!isset($allowed_protocols)) {
      // \Drupal\Component\Utility\UrlHelper::filterBadProtocol() is called by
      // the installer and update.php, in which case the configuration may not
      // exist (yet). Provide a minimal default set of allowed protocols for
      // these cases.
      $allowed_protocols = array('http', 'https');
    }
    UrlHelper::setAllowedProtocols($allowed_protocols);
520
521
522

    // Override of Symfony's mime type guesser singleton.
    MimeTypeGuesser::registerWithSymfonyGuesser($this->container);
523

524
    $this->prepared = TRUE;
525
526
  }

527
528
529
530
  /**
   * {@inheritdoc}
   */
  public function discoverServiceProviders() {
531
    $this->serviceYamls = array(
532
533
      'app' => array(),
      'site' => array(),
534
    );
535
536
537
538
539
540
    $this->serviceProviderClasses = array(
      'app' => array(),
      'site' => array(),
    );
    $this->serviceYamls['app']['core'] = 'core/core.services.yml';
    $this->serviceProviderClasses['app']['core'] = 'Drupal\Core\CoreServiceProvider';
541

542
    // Retrieve enabled modules and register their namespaces.
543
    if (!isset($this->moduleList)) {
544
545
      $extensions = $this->getConfigStorage()->read('core.extension');
      $this->moduleList = isset($extensions['module']) ? $extensions['module'] : array();
546
    }
547
    $module_filenames = $this->getModuleFileNames();
548
    $this->classLoaderAddMultiplePsr4($this->getModuleNamespacesPsr4($module_filenames));
549

550
    // Load each module's serviceProvider class.
551
    foreach ($module_filenames as $module => $filename) {
katbailey's avatar
katbailey committed
552
      $camelized = ContainerBuilder::camelize($module);
553
554
      $name = "{$camelized}ServiceProvider";
      $class = "Drupal\\{$module}\\{$name}";
555
      if (class_exists($class)) {
556
        $this->serviceProviderClasses['app'][$module] = $class;
557
      }
558
      $filename = dirname($filename) . "/$module.services.yml";
559
      if (file_exists($filename)) {
560
        $this->serviceYamls['app'][$module] = $filename;
561
      }
562
    }
563

564
    // Add site-specific service providers.
565
    if (!empty($GLOBALS['conf']['container_service_providers'])) {
566
567
568
569
      foreach ($GLOBALS['conf']['container_service_providers'] as $class) {
        if (class_exists($class)) {
          $this->serviceProviderClasses['site'][] = $class;
        }
570
571
      }
    }
572
573
    if (!$this->addServiceFiles(Settings::get('container_yamls'))) {
      throw new \Exception('The container_yamls setting is missing from settings.php');
574
    }
575
576
577
578
579
  }

  /**
   * {@inheritdoc}
   */
580
581
  public function getServiceProviders($origin) {
    return $this->serviceProviders[$origin];
582
583
584
585
586
587
  }

  /**
   * {@inheritdoc}
   */
  public function terminate(Request $request, Response $response) {
588
589
590
    // Only run terminate() when essential services have been set up properly
    // by preHandle() before.
    if (FALSE === $this->prepared) {
591
592
593
594
595
596
597
598
599
600
601
      return;
    }

    if ($this->getHttpKernel() instanceof TerminableInterface) {
      $this->getHttpKernel()->terminate($request, $response);
    }
  }

  /**
   * {@inheritdoc}
   */
602
603
  public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
    $this->boot();
604
    return $this->getHttpKernel()->handle($request, $type, $catch);
605
606
  }

607
608
609
610
611
612
  /**
   * {@inheritdoc}
   */
  public function prepareLegacyRequest(Request $request) {
    $this->boot();
    $this->preHandle($request);
613
614
615
616
617
    // Setup services which are normally initialized from within stack
    // middleware or during the request kernel event.
    if (PHP_SAPI !== 'cli') {
      $request->setSession($this->container->get('session'));
    }
618
619
    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
620
621
622
623
624
    $this->container->get('request_stack')->push($request);
    $this->container->get('router.request_context')->fromRequest($request);
    return $this;
  }

625
626
627
628
629
630
  /**
   * Returns module data on the filesystem.
   *
   * @param $module
   *   The name of the module.
   *
631
632
   * @return \Drupal\Core\Extension\Extension|bool
   *   Returns an Extension object if the module is found, FALSE otherwise.
633
634
635
   */
  protected function moduleData($module) {
    if (!$this->moduleData) {
636
      // First, find profiles.
637
      $listing = new ExtensionDiscovery($this->root);
638
639
640
641
      $listing->setProfileDirectories(array());
      $all_profiles = $listing->scan('profile');
      $profiles = array_intersect_key($all_profiles, $this->moduleList);

642
643
      // If a module is within a profile directory but specifies another
      // profile for testing, it needs to be found in the parent profile.
644
      $settings = $this->getConfigStorage()->read('simpletest.settings');
645
646
      $parent_profile = !empty($settings['parent_profile']) ? $settings['parent_profile'] : NULL;
      if ($parent_profile && !isset($profiles[$parent_profile])) {
647
648
        // In case both profile directories contain the same extension, the
        // actual profile always has precedence.
649
        $profiles = array($parent_profile => $all_profiles[$parent_profile]) + $profiles;
650
      }
651
652
653
654
655
656

      $profile_directories = array_map(function ($profile) {
        return $profile->getPath();
      }, $profiles);
      $listing->setProfileDirectories($profile_directories);

657
      // Now find modules.
658
      $this->moduleData = $profiles + $listing->scan('module');
659
660
661
662
    }
    return isset($this->moduleData[$module]) ? $this->moduleData[$module] : FALSE;
  }

663
664
  /**
   * Implements Drupal\Core\DrupalKernelInterface::updateModules().
665
666
667
   *
   * @todo Remove obsolete $module_list parameter. Only $module_filenames is
   *   needed.
668
   */
669
  public function updateModules(array $module_list, array $module_filenames = array()) {
670
    $this->moduleList = $module_list;
671
672
    foreach ($module_filenames as $name => $extension) {
      $this->moduleData[$name] = $extension;
673
    }
674

675
676
    // If we haven't yet booted, we don't need to do anything: the new module
    // list will take effect when boot() is called. If we have already booted,
677
678
    // then rebuild the container in order to refresh the serviceProvider list
    // and container.
679
    if ($this->booted) {
680
      $this->initializeContainer(TRUE);
681
682
    }
  }
683

684
  /**
685
   * Returns the classname based on environment.
686
687
688
689
690
   *
   * @return string
   *   The class name.
   */
  protected function getClassName() {
691
    $parts = array('service_container', $this->environment);
692
693
694
    return implode('_', $parts);
  }

695
696
697
698
699
700
701
702
703
  /**
   * Returns the container class namespace based on the environment.
   *
   * @return string
   *   The class name.
   */
  protected function getClassNamespace() {
    return 'Drupal\\Core\\DependencyInjection\\Container\\' . $this->environment;
  }
704
705
706
707
708
709
710
711
712
713
714
715

  /**
   * Returns the kernel parameters.
   *
   * @return array An array of kernel parameters
   */
  protected function getKernelParameters() {
    return array(
      'kernel.environment' => $this->environment,
    );
  }

716
717
  /**
   * Initializes the service container.
718
719
720
721
   *
   * @param bool $rebuild
   *   Force a container rebuild.
   * @return \Symfony\Component\DependencyInjection\ContainerInterface
722
   */
723
  protected function initializeContainer($rebuild = FALSE) {
724
    $this->containerNeedsDumping = FALSE;
725
    $session_manager_started = FALSE;
726
    if (isset($this->container)) {
727
728
729
730
731
      // Save the id of the currently logged in user.
      if ($this->container->initialized('current_user')) {
        $current_user_id = $this->container->get('current_user')->id();
      }

732
733
734
735
      // If there is a session manager, close and save the session.
      if ($this->container->initialized('session_manager')) {
        $session_manager = $this->container->get('session_manager');
        if ($session_manager->isStarted()) {
736
          $session_manager_started = TRUE;
737
          $session_manager->save();
738
739
740
        }
        unset($session_manager);
      }
741
    }
742

743
744
745
    // If the module list hasn't already been set in updateModules and we are
    // not forcing a rebuild, then try and load the container from the disk.
    if (empty($this->moduleList) && !$rebuild) {
746
      $fully_qualified_class_name = '\\' . $this->getClassNamespace() . '\\' . $this->getClassName();
747
748

      // First, try to load from storage.
749
750
      if (!class_exists($fully_qualified_class_name, FALSE)) {
        $this->storage()->load($this->getClassName() . '.php');
751
752
      }
      // If the load succeeded or the class already existed, use it.
753
      if (class_exists($fully_qualified_class_name, FALSE)) {
754
        $container = new $fully_qualified_class_name;
755
756
      }
    }
757
758
759
760
761

    if (!isset($container)) {
      $container = $this->compileContainer();
    }

762
    $this->attachSynthetic($container);
763
764

    $this->container = $container;
765
    if ($session_manager_started) {
766
767
      $this->container->get('session_manager')->start();
    }
768
769
770
771
772
773
774
775
776
777

    // The request stack is preserved across container rebuilds. Reinject the
    // new session into the master request if one was present before.
    if (($request_stack = $this->container->get('request_stack', ContainerInterface::NULL_ON_INVALID_REFERENCE))) {
      if ($request = $request_stack->getMasterRequest()) {
        if ($request->hasSession()) {
          $request->setSession($this->container->get('session'));
        }
      }
    }
778
779
780
781
782

    if (!empty($current_user_id)) {
      $this->container->get('current_user')->setInitialAccountId($current_user_id);
    }

783
    \Drupal::setContainer($this->container);
784
785
786
787
788
789

    // If needs dumping flag was set, dump the container.
    if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) {
      $this->container->get('logger.factory')->get('DrupalKernel')->notice('Container cannot be written to disk');
    }

790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
    return $this->container;
  }

  /**
   * Setup a consistent PHP environment.
   *
   * This method sets PHP environment options we want to be sure are set
   * correctly for security or just saneness.
   */
  public static function bootEnvironment() {
    if (static::$isEnvironmentInitialized) {
      return;
    }

    // Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
    error_reporting(E_STRICT | E_ALL);

    // Override PHP settings required for Drupal to work properly.
    // sites/default/default.settings.php contains more runtime settings.
    // The .htaccess file contains settings that cannot be changed at runtime.

    // Use session cookies, not transparent sessions that puts the session id in
    // the query string.
    ini_set('session.use_cookies', '1');
    ini_set('session.use_only_cookies', '1');
    ini_set('session.use_trans_sid', '0');
    // Don't send HTTP headers using PHP's session handler.
    // Send an empty string to disable the cache limiter.
    ini_set('session.cache_limiter', '');
    // Use httponly session cookies.
    ini_set('session.cookie_httponly', '1');

    // Set sane locale settings, to ensure consistent string, dates, times and
    // numbers handling.
    setlocale(LC_ALL, 'C');

    // Detect string handling method.
    Unicode::check();

    // Indicate that code is operating in a test child site.
    if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
      if ($test_prefix = drupal_valid_test_ua()) {
        // Only code that interfaces directly with tests should rely on this
        // constant; e.g., the error/exception handler conditionally adds further
        // error information into HTTP response headers that are consumed by
        // Simpletest's internal browser.
        define('DRUPAL_TEST_IN_CHILD_SITE', TRUE);

        // Log fatal errors to the test site directory.
        ini_set('log_errors', 1);
        ini_set('error_log', DRUPAL_ROOT . '/sites/simpletest/' . substr($test_prefix, 10) . '/error.log');
      }
      else {
        // Ensure that no other code defines this.
        define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
      }
    }

    // Set the Drupal custom error handler.
    set_error_handler('_drupal_error_handler');
    set_exception_handler('_drupal_exception_handler');

    static::$isEnvironmentInitialized = TRUE;
  }

  /**
   * Bootstraps the legacy global request variables.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The current request.
   *
   * @todo D8: Eliminate this entirely in favor of Request object.
   */
  protected function initializeRequestGlobals(Request $request) {
    // Provided by settings.php.
    global $base_url;
    // Set and derived from $base_url by this function.
867
    global $base_path, $base_root;
868
869
870
871
872
873
874
875
876
877
878
879
    global $base_secure_url, $base_insecure_url;

    // @todo Refactor with the Symfony Request object.
    if (isset($base_url)) {
      // Parse fixed base URL from settings.php.
      $parts = parse_url($base_url);
      if (!isset($parts['path'])) {
        $parts['path'] = '';
      }
      $base_path = $parts['path'] . '/';
      // Build $base_root (everything until first slash after "scheme://").
      $base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));
880
    }
881
    else {
882
      // Create base URL.
883
      $base_root = $request->getSchemeAndHttpHost();
884
885
886
887
888
889

      $base_url = $base_root;

      // For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is
      // '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.
      if ($dir = rtrim(dirname($request->server->get('SCRIPT_NAME')), '\/')) {
890
891
        // Remove "core" directory if present, allowing install.php,
        // authorize.php, and others to auto-detect a base path.
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
        $core_position = strrpos($dir, '/core');
        if ($core_position !== FALSE && strlen($dir) - 5 == $core_position) {
          $base_path = substr($dir, 0, $core_position);
        }
        else {
          $base_path = $dir;
        }
        $base_url .= $base_path;
        $base_path .= '/';
      }
      else {
        $base_path = '/';
      }
    }
    $base_secure_url = str_replace('http://', 'https://', $base_url);
    $base_insecure_url = str_replace('https://', 'http://', $base_url);
  }
909

910
911
912
  /**
   * Returns service instances to persist from an old container to a new one.
   */
913
  protected function getServicesToPersist(ContainerInterface $container) {
914
    $persist = array();
915
916
917
918
    foreach ($container->getParameter('persistIds') as $id) {
      // It's pointless to persist services not yet initialized.
      if ($container->initialized($id)) {
        $persist[$id] = $container->get($id);
919
920
921
922
923
924
925
926
      }
    }
    return $persist;
  }

  /**
   * Moves persistent service instances into a new container.
   */
927
  protected function persistServices(ContainerInterface $container, array $persist) {
928
929
930
    foreach ($persist as $id => $object) {
      // Do not override services already set() on the new container, for
      // example 'service_container'.
931
932
      if (!$container->initialized($id)) {
        $container->set($id, $object);
933
934
935
936
      }
    }
  }

937
  /**
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
   * Force a container rebuild.
   *
   * @return \Symfony\Component\DependencyInjection\ContainerInterface
   */
  public function rebuildContainer() {
    // Empty module properties and for them to be reloaded from scratch.
    $this->moduleList = NULL;
    $this->moduleData = array();
    return $this->initializeContainer(TRUE);
  }

  /**
   * Attach synthetic values on to kernel.
   *
   * @param ContainerInterface $container
   *   Container object
954
   *
955
956
   * @return ContainerInterface
   */
957
  protected function attachSynthetic(ContainerInterface $container) {
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
    $persist = array();
    if (isset($this->container)) {
      $persist = $this->getServicesToPersist($this->container);
    }
    $this->persistServices($container, $persist);

    // All namespaces must be registered before we attempt to use any service
    // from the container.
    $this->classLoaderAddMultiplePsr4($container->getParameter('container.namespaces'));

    $container->set('kernel', $this);

    // Set the class loader which was registered as a synthetic service.
    $container->set('class_loader', $this->classLoader);
    return $container;
  }

  /**
   * Compiles a new service container.
977
978
979
   *
   * @return ContainerBuilder The compiled service container
   */
980
981
982
983
984
985
986
987
  protected function compileContainer() {
    // We are forcing a container build so it is reasonable to assume that the
    // calling method knows something about the system has changed requiring the
    // container to be dumped to the filesystem.
    if ($this->allowDumping) {
      $this->containerNeedsDumping = TRUE;
    }

988
    $this->initializeServiceProviders();
989
    $container = $this->getContainerBuilder();
990
    $container->set('kernel', $this);
991
    $container->setParameter('container.modules', $this->getModulesParameter());
992
993

    // Get a list of namespaces and put it onto the container.
994
    $namespaces = $this->getModuleNamespacesPsr4($this->getModuleFileNames());
995
996
997
998
999
    // Add all components in \Drupal\Core and \Drupal\Component that have one of
    // the following directories:
    // - Element
    // - Entity
    // - Plugin
1000
    foreach (array('Core', 'Component') as $parent_directory) {
1001
      $path = 'core/lib/Drupal/' . $parent_directory;
1002
      $parent_namespace = 'Drupal\\' . $parent_directory;
1003
      foreach (new \DirectoryIterator($this->root . '/' . $path) as $component) {
1004
1005
1006
1007
1008
1009
1010
        /** @var $component \DirectoryIterator */
        $pathname = $component->getPathname();
        if (!$component->isDot() && $component->isDir() && (
          is_dir($pathname . '/Plugin') ||
          is_dir($pathname . '/Entity') ||
          is_dir($pathname . '/Element')
        )) {
1011
          $namespaces[$parent_namespace . '\\' . $component->getFilename()] = $path . '/' . $component->getFilename();
1012
1013
1014
        }
      }
    }
1015
1016
    $container->setParameter('container.namespaces', $namespaces);

1017
1018
1019
1020
1021
1022
    // Store the default language values on the container. This is so that the
    // default language can be configured using the configuration factory. This
    // avoids the circular dependencies that would created by
    // \Drupal\language\LanguageServiceProvider::alter() and allows the default
    // language to not be English in the installer.
    $default_language_values = Language::$defaultValues;
1023
1024
    if ($system = $this->getConfigStorage()->read('system.site')) {
      if ($default_language_values['id'] != $system['langcode']) {
1025
        $default_language_values = array('id' => $system['langcode']);
1026
      }
1027
1028
1029
    }
    $container->setParameter('language.default_values', $default_language_values);

1030
    // Register synthetic services.
1031
    $container->register('class_loader')->setSynthetic(TRUE);
1032
1033
    $container->register('kernel', 'Symfony\Component\HttpKernel\KernelInterface')->setSynthetic(TRUE);
    $container->register('service_container', 'Symfony\Component\DependencyInjection\ContainerInterface')->setSynthetic(TRUE);
1034
1035

    // Register application services.
1036
    $yaml_loader = new YamlFileLoader($container);
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
    foreach ($this->serviceYamls['app'] as $filename) {
      $yaml_loader->load($filename);
    }
    foreach ($this->serviceProviders['app'] as $provider) {
      if ($provider instanceof ServiceProviderInterface) {
        $provider->register($container);
      }
    }
    // Register site-specific service overrides.
    foreach ($this->serviceYamls['site'] as $filename) {
1047
1048
      $yaml_loader->load($filename);
    }
1049
    foreach ($this->serviceProviders['site'] as $provider) {
1050
1051
1052
      if ($provider instanceof ServiceProviderInterface) {
        $provider->register($container);
      }
1053
    }
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066

    // Identify all services whose instances should be persisted when rebuilding
    // the container during the lifetime of the kernel (e.g., during a kernel
    // reboot). Include synthetic services, because by definition, they cannot
    // be automatically reinstantiated. Also include services tagged to persist.
    $persist_ids = array();
    foreach ($container->getDefinitions() as $id => $definition) {
      if ($definition->isSynthetic() || $definition->getTag('persist')) {
        $persist_ids[] = $id;
      }
    }
    $container->setParameter('persistIds', $persist_ids);

1067
    $container->compile();
1068
1069
    return $container;
  }
1070

1071
1072
1073
1074
1075
1076
  /**
   * Registers all service providers to the kernel.
   *
   * @throws \LogicException
   */
  protected function initializeServiceProviders() {
1077
1078
1079
1080
1081
1082
1083
1084
    $this->discoverServiceProviders();
    $this->serviceProviders = array(
      'app' => array(),
      'site' => array(),
    );
    foreach ($this->serviceProviderClasses as $origin => $classes) {
      foreach ($classes as $name => $class) {
        $this->serviceProviders[$origin][$name] = new $class;
1085
1086
1087
1088
      }
    }
  }

1089
1090
1091
1092
1093
  /**
   * Gets a new ContainerBuilder instance used to build the service container.
   *
   * @return ContainerBuilder
   */
1094
  protected function getContainerBuilder() {
1095
1096
1097
    return new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  }

1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
  /**
   * Dumps the service container to PHP code in the config directory.
   *
   * This method is based on the dumpContainer method in the parent class, but
   * that method is reliant on the Config component which we do not use here.
   *
   * @param ContainerBuilder $container
   *   The service container.
   * @param string $baseClass
   *   The name of the container's base class
   *
   * @return bool
   *   TRUE if the container was successfully dumped to disk.
   */
  protected function dumpDrupalContainer(ContainerBuilder $container, $baseClass) {
1113
    if (!$this->storage()->writeable()) {
1114
1115
1116
1117
      return FALSE;
    }
    // Cache the container.
    $dumper = new PhpDumper($container);
1118
    $dumper->setProxyDumper(new ProxyDumper(new ProxyBuilder()));
1119
    $class = $this->getClassName();
1120
1121
1122
1123
1124
1125
    $namespace = $this->getClassNamespace();
    $content = $dumper->dump([
      'class' => $class,
      'base_class' => $baseClass,
      'namespace' => $namespace,
    ]);
1126
    return $this->storage()->save($class . '.php', $content);
1127
1128
  }

1129
1130
1131
1132

  /**
   * Gets a http kernel from the container
   *
1133
   * @return \Symfony\Component\HttpKernel\HttpKernelInterface
1134
1135
1136
1137
1138
   */
  protected function getHttpKernel() {
    return $this->container->get('http_kernel');
  }

1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
  /**
   * Gets the PHP code storage object to use for the compiled container.
   *
   * @return \Drupal\Component\PhpStorage\PhpStorageInterface
   */
  protected function storage() {
    if (!isset($this->storage)) {
      $this->storage = PhpStorageFactory::get('service_container');
    }
    return $this->storage;
  }

1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
  /**
   * Returns the active configuration storage to use during building the container.
   *
   * @return \Drupal\Core\Config\StorageInterface
   */
  protected function getConfigStorage() {
    if (!isset($this->configStorage)) {
      // The active configuration storage may not exist yet; e.g., in the early
      // installer. Catch the exception thrown by config_get_config_directory().
      try {
1161
        $this->configStorage = BootstrapConfigStorageFactory::get($this->classLoader);
1162
1163
1164
1165
1166
1167
1168
1169
      }
      catch (\Exception $e) {
        $this->configStorage = new NullStorage();
      }
    }
    return $this->configStorage;
  }

1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
  /**
   * Returns an array of Extension class parameters for all enabled modules.
   *
   * @return array
   */
  protected function getModulesParameter() {
    $extensions = array();
    foreach ($this->moduleList as $name => $weight) {
      if ($data = $this->moduleData($name)) {
        $extensions[$name] = array(
          'type' => $data->getType(),
          'pathname' => $data->getPathname(),
          'filename' => $data->getExtensionFilename(),
        );
      }
    }
    return $extensions;
  }

1189
  /**
1190
1191
1192
1193
1194
   * Gets the file name for each enabled module.
   *
   * @return array
   *   Array where each key is a module name, and each value is a path to the
   *   respective *.module or *.profile file.
1195
1196
1197
1198
1199
   */
  protected function getModuleFileNames() {
    $filenames = array();
    foreach ($this->moduleList as $module => $weight) {
      if ($data = $this->moduleData($module)) {
1200
        $filenames[$module] = $data->getPathname();
1201
1202
1203
1204
1205
      }
    }
    return $filenames;
  }

1206
1207
1208
  /**
   * Gets the PSR-4 base directories for module namespaces.
   *
1209
   * @param string[] $module_file_names
1210
1211
1212
   *   Array where each key is a module name, and each value is a path to the
   *   respective *.module or *.profile file.
   *
1213
   * @return string[]
1214
   *   Array where each key is a module namespace like 'Drupal\system', and each
1215
   *   value is the PSR-4 base directory associated with the module namespace.
1216
1217
1218
1219
   */
  protected function getModuleNamespacesPsr4($module_file_names) {
    $namespaces = array();
    foreach ($module_file_names as $module => $filename) {
1220
      $namespaces["Drupal\\$module"] = dirname($filename) . '/src';
1221
1222
1223
1224
    }
    return $namespaces;
  }

1225
1226
1227
1228
1229
1230
1231
1232
  /**
   * Registers a list of namespaces with PSR-4 directories for class loading.
   *
   * @param array $namespaces
   *   Array where each key is a namespace like 'Drupal\system', and each value
   *   is either a PSR-4 base directory, or an array of PSR-4 base directories
   *   associated with this namespace.
   */
1233
  protected function classLoaderAddMultiplePsr4(array $namespaces = array()) {
1234
    foreach ($namespaces as $prefix => $paths) {
1235
1236
1237
1238
1239
1240
1241
1242
      if (is_array($paths)) {
        foreach ($paths as $key => $value) {
          $paths[$key] = $this->root . '/' . $value;
        }
      }
      elseif (is_string($paths)) {
        $paths = $this->root . '/' . $paths;
      }
1243
1244
1245
1246
      $this->classLoader->addPsr4($prefix . '\\', $paths);
    }
  }

1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
  /**
   * Validates a hostname length.
   *
   * @param string $host
   *   A hostname.
   *
   * @return bool
   *   TRUE if the length is appropriate, or FALSE otherwise.
   */
  protected static function validateHostnameLength($host) {
    // Limit the length of the host name to 1000 bytes to prevent DoS attacks
    // with long host names.
    return strlen($host) <= 1000
    // Limit the number of subdomains and port separators to prevent DoS attacks
    // in findSitePath().
    && substr_count($host, '.') <= 100
    && substr_count($host, ':') <= 100;
  }

  /**
   * Validates the hostname supplied from the HTTP request.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request object
   *
   * @return bool
   *   TRUE if the hostmame is valid, or FALSE otherwise.
   *
   * @todo Adjust per resolution to https://github.com/symfony/symfony/issues/12349
   */
  public static function validateHostname(Request $request) {
    // $request->getHost() can throw an UnexpectedValueException if it
    // detects a bad hostname, but it does not validate the length.
    try {
      $http_host = $request->getHost();
    }
    catch (\UnexpectedValueException $e) {
      return FALSE;
    }

    if (static::validateHostnameLength($http_host) === FALSE) {
      return FALSE;
    }

    return TRUE;
  }

1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
  /**
   * Sets up the lists of trusted HTTP Host headers.
   *
   * Since the HTTP Host header can be set by the user making the request, it
   * is possible to create an attack vectors against a site by overriding this.
   * Symfony provides a mechanism for creating a list of trusted Host values.
   *
   * Host patterns (as regular expressions) can be configured throught
   * settings.php for multisite installations, sites using ServerAlias without
   * canonical redirection, or configurations where the site responds to default
   * requests. For example,
   *
   * @code
   * $settings['trusted_host_patterns'] = array(
   *   '^example\.com$',
   *   '^*.example\.com$',
   * );
   * @endcode
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The request object.
1315
   * @param array $host_patterns
1316
1317
1318
1319
1320
1321
   *   The array of trusted host patterns.
   *
   * @return boolean
   *   TRUE if the Host header is trusted, FALSE otherwise.
   *
   * @see https://www.drupal.org/node/1992030
1322
   * @see \Drupal\Core\Http\TrustedHostsRequestFactory
1323
   */
1324
1325
  protected static function setupTrustedHosts(Request $request, $host_patterns) {
    $request->setTrustedHosts($host_patterns);
1326
1327
1328

    // Get the host, which will validate the current request.
    try {
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
      $host = $request->getHost();

      // Fake requests created through Request::create() without passing in the
      // server variables from the main request have a default host of
      // 'localhost'. If 'localhost' does not match any of the trusted host
      // patterns these fake requests would fail the host verification. Instead,
      // TrustedHostsRequestFactory makes sure to pass in the server variables
      // from the main request.
      $request_factory = new TrustedHostsRequestFactory($host);
      Request::setFactory([$request_factory, 'createRequest']);

1340
1341
1342
1343
1344
1345
1346
    }
    catch (\UnexpectedValueException $e) {
      return FALSE;
    }

    return TRUE;
  }
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363

  /**
   * Add service files.
   *
   * @param $service_yamls
   *   A list of service files.
   *
   * @return bool
   *   TRUE if the list was an array, FALSE otherwise.
   */
  protected function addServiceFiles($service_yamls) {
    if (is_array($service_yamls)) {
      $this->serviceYamls['site'] = array_filter($service_yamls, 'file_exists');
      return TRUE;
    }
    return FALSE;
  }
1364
}