DrupalKernel.php 23 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\Core\PhpStorage\PhpStorageFactory;
11
use Drupal\Core\Config\BootstrapConfigStorageFactory;
12
use Drupal\Core\Config\NullStorage;
13
use Drupal\Core\CoreServiceProvider;
14
use Drupal\Core\DependencyInjection\ContainerBuilder;
15
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
16
use Drupal\Core\DependencyInjection\YamlFileLoader;
17
use Drupal\Core\Extension\ExtensionDiscovery;
18
use Drupal\Core\Language\Language;
19 20
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
21
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
22 23 24 25
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
26
use Composer\Autoload\ClassLoader;
27 28 29

/**
 * The DrupalKernel class is the core of Drupal itself.
30 31
 *
 * This class is responsible for building the Dependency Injection Container and
32 33 34 35 36 37 38 39
 * 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.
40
 */
41 42
class DrupalKernel implements DrupalKernelInterface, TerminableInterface {

43
  const CONTAINER_BASE_CLASS = '\Drupal\Core\DependencyInjection\Container';
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

  /**
   * 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
   */
  protected $booted;
65

66 67 68 69
  /**
   * Holds the list of enabled modules.
   *
   * @var array
70 71
   *   An associative array whose keys are module names and whose values are
   *   ignored.
72 73 74 75
   */
  protected $moduleList;

  /**
76
   * Holds an updated list of enabled modules.
77
   *
78 79 80 81 82 83 84
   * @var array
   *   An associative array whose keys are module names and whose values are
   *   ignored.
   */
  protected $newModuleList;

  /**
85
   * List of available modules and installation profiles.
86
   *
87
   * @var \Drupal\Core\Extension\Extension[]
88
   */
89
  protected $moduleData = array();
90 91 92 93 94 95 96 97

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

98 99 100
  /**
   * The classloader object.
   *
101
   * @var \Composer\Autoload\ClassLoader
102 103 104
   */
  protected $classLoader;

105 106 107 108 109 110 111
  /**
   * Config storage object used for reading enabled modules configuration.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $configStorage;

112
  /**
113
   * The list of the classnames of the service providers in this kernel.
114 115 116
   *
   * @var array
   */
117
  protected $serviceProviderClasses;
118

119 120 121 122 123 124 125 126 127 128 129 130 131 132
  /**
   * 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;

133 134 135 136 137 138 139
  /**
   * Holds the list of YAML files containing service definitions.
   *
   * @var array
   */
  protected $serviceYamls;

140 141 142 143 144 145 146
  /**
   * The array of registered service providers.
   *
   * @var array
   */
  protected $serviceProviders;

147 148 149 150 151 152 153
  /**
   * Constructs a DrupalKernel object.
   *
   * @param string $environment
   *   String indicating the environment, e.g. 'prod' or 'dev'. Used by
   *   Symfony\Component\HttpKernel\Kernel::__construct(). Drupal does not use
   *   this value currently. Pass 'prod'.
154
   * @param \Composer\Autoload\ClassLoader $class_loader
155 156 157
   *   (optional) The classloader is only used if $storage is not given or
   *   the load from storage fails and a container rebuild is required. In
   *   this case, the loaded modules will be registered with this loader in
158
   *   order to be able to find the module serviceProviders.
159 160 161
   * @param bool $allow_dumping
   *   (optional) FALSE to stop the container from being written to or read
   *   from disk. Defaults to TRUE.
162
   */
163 164
  public function __construct($environment, ClassLoader $class_loader, $allow_dumping = TRUE) {
    $this->environment = $environment;
165
    $this->booted = FALSE;
166
    $this->classLoader = $class_loader;
167
    $this->allowDumping = $allow_dumping;
168 169
  }

170
  /**
171
   * {@inheritdoc}
172 173 174 175 176 177 178
   */
  public function boot() {
    if ($this->booted) {
      return;
    }
    $this->initializeContainer();
    $this->booted = TRUE;
179
    if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) {
180 181
      watchdog('DrupalKernel', 'Container cannot be written to disk');
    }
182 183
  }

184
  /**
185
   * {@inheritdoc}
186
   */
187 188 189 190 191
  public function shutdown() {
    if (FALSE === $this->booted) {
      return;
    }
    $this->booted = FALSE;
192
    $this->container = NULL;
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
  }

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

  /**
   * {@inheritdoc}
   */
  public function discoverServiceProviders() {
    $serviceProviders = array(
      'CoreServiceProvider' => new CoreServiceProvider(),
208
    );
209 210 211
    $this->serviceYamls = array(
      'core/core.services.yml'
    );
212
    $this->serviceProviderClasses = array('Drupal\Core\CoreServiceProvider');
213 214 215

    // Ensure we know what modules are enabled and that their namespaces are
    // registered.
216
    if (!isset($this->moduleList)) {
217 218
      $extensions = $this->getConfigStorage()->read('core.extension');
      $this->moduleList = isset($extensions['module']) ? $extensions['module'] : array();
219
    }
220 221
    $module_filenames = $this->getModuleFileNames();
    $this->registerNamespaces($this->getModuleNamespaces($module_filenames));
222

223
    // Load each module's serviceProvider class.
224
    foreach ($this->moduleList as $module => $weight) {
katbailey's avatar
katbailey committed
225
      $camelized = ContainerBuilder::camelize($module);
226 227
      $name = "{$camelized}ServiceProvider";
      $class = "Drupal\\{$module}\\{$name}";
228
      if (class_exists($class)) {
229 230
        $serviceProviders[$name] = new $class();
        $this->serviceProviderClasses[] = $class;
231
      }
232 233 234 235
      $filename = dirname($module_filenames[$module]) . "/$module.services.yml";
      if (file_exists($filename)) {
        $this->serviceYamls[] = $filename;
      }
236
    }
237

238 239 240 241 242
    // Add site specific or test service providers.
    if (!empty($GLOBALS['conf']['container_service_providers'])) {
      foreach ($GLOBALS['conf']['container_service_providers'] as $name => $class) {
        $serviceProviders[$name] = new $class();
        $this->serviceProviderClasses[] = $class;
243 244
      }
    }
245 246 247 248
    // Add site specific or test YAMLs.
    if (!empty($GLOBALS['conf']['container_yamls'])) {
      $this->serviceYamls = array_merge($this->serviceYamls, $GLOBALS['conf']['container_yamls']);
    }
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    return $serviceProviders;
  }


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

  /**
   * {@inheritdoc}
   */
  public function terminate(Request $request, Response $response) {
    if (FALSE === $this->booted) {
      return;
    }

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

  /**
   * {@inheritdoc}
   */
276
  public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = TRUE) {
277 278 279 280 281
    if (FALSE === $this->booted) {
      $this->boot();
    }

    return $this->getHttpKernel()->handle($request, $type, $catch);
282
  }
283

284 285 286 287 288 289
  /**
   * Returns module data on the filesystem.
   *
   * @param $module
   *   The name of the module.
   *
290 291
   * @return \Drupal\Core\Extension\Extension|bool
   *   Returns an Extension object if the module is found, FALSE otherwise.
292 293 294
   */
  protected function moduleData($module) {
    if (!$this->moduleData) {
295
      // First, find profiles.
296 297 298 299 300
      $listing = new ExtensionDiscovery();
      $listing->setProfileDirectories(array());
      $all_profiles = $listing->scan('profile');
      $profiles = array_intersect_key($all_profiles, $this->moduleList);

301 302
      // If a module is within a profile directory but specifies another
      // profile for testing, it needs to be found in the parent profile.
303
      $settings = $this->getConfigStorage()->read('simpletest.settings');
304 305
      $parent_profile = !empty($settings['parent_profile']) ? $settings['parent_profile'] : NULL;
      if ($parent_profile && !isset($profiles[$parent_profile])) {
306 307
        // In case both profile directories contain the same extension, the
        // actual profile always has precedence.
308
        $profiles = array($parent_profile => $all_profiles[$parent_profile]) + $profiles;
309
      }
310 311 312 313 314 315

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

316
      // Now find modules.
317
      $this->moduleData = $profiles + $listing->scan('module');
318 319 320 321
    }
    return isset($this->moduleData[$module]) ? $this->moduleData[$module] : FALSE;
  }

322 323
  /**
   * Implements Drupal\Core\DrupalKernelInterface::updateModules().
324 325 326
   *
   * @todo Remove obsolete $module_list parameter. Only $module_filenames is
   *   needed.
327
   */
328
  public function updateModules(array $module_list, array $module_filenames = array()) {
329
    $this->newModuleList = $module_list;
330 331
    foreach ($module_filenames as $name => $extension) {
      $this->moduleData[$name] = $extension;
332
    }
333 334
    // 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,
335
    // then reboot in order to refresh the serviceProvider list and container.
336 337 338 339 340
    if ($this->booted) {
      $this->booted = FALSE;
      $this->boot();
    }
  }
341

342
  /**
343
   * Returns the classname based on environment.
344 345 346 347 348
   *
   * @return string
   *   The class name.
   */
  protected function getClassName() {
349
    $parts = array('service_container', $this->environment);
350 351 352
    return implode('_', $parts);
  }

353 354 355 356 357 358 359 360 361 362 363 364

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

365 366 367
  /**
   * Initializes the service container.
   */
368
  protected function initializeContainer() {
369
    $this->containerNeedsDumping = FALSE;
370
    $persist = $this->getServicesToPersist();
371
    // The request service requires custom persisting logic, since it is also
372
    // potentially scoped.
373 374 375 376 377 378 379 380
    $request_scope = FALSE;
    if (isset($this->container)) {
      if ($this->container->isScopeActive('request')) {
        $request_scope = TRUE;
      }
      if ($this->container->initialized('request')) {
        $request = $this->container->get('request');
      }
381
    }
382
    $this->container = NULL;
383 384 385
    $class = $this->getClassName();
    $cache_file = $class . '.php';

386
    if ($this->allowDumping) {
387 388
      // First, try to load.
      if (!class_exists($class, FALSE)) {
389
        $this->storage()->load($cache_file);
390 391 392 393 394
      }
      // If the load succeeded or the class already existed, use it.
      if (class_exists($class, FALSE)) {
        $fully_qualified_class_name = '\\' . $class;
        $this->container = new $fully_qualified_class_name;
395
        $this->persistServices($persist);
396 397
      }
    }
398 399 400 401 402 403 404 405
    // First check whether the list of modules changed in this request.
    if (isset($this->newModuleList)) {
      if (isset($this->container) && isset($this->moduleList) && array_keys($this->moduleList) !== array_keys($this->newModuleList)) {
        unset($this->container);
      }
      $this->moduleList = $this->newModuleList;
      unset($this->newModuleList);
    }
406 407
    // Second, check if some other request -- for example on another web
    // frontend or during the installer -- changed the list of enabled modules.
408
    if (isset($this->container)) {
409 410
      // All namespaces must be registered before we attempt to use any service
      // from the container.
411
      $container_modules = $this->container->getParameter('container.modules');
412
      $namespaces_before = $this->classLoader->getPrefixes();
413
      $this->registerNamespaces($this->container->getParameter('container.namespaces'));
414 415 416

      // If 'container.modules' is wrong, the container must be rebuilt.
      if (!isset($this->moduleList)) {
417
        $this->moduleList = $this->container->get('config.factory')->get('core.extension')->get('module') ?: array();
418
      }
419
      if (array_keys($this->moduleList) !== array_keys($container_modules)) {
420
        $persist = $this->getServicesToPersist();
421
        unset($this->container);
422 423 424 425
        // Revert the class loader to its prior state. However,
        // registerNamespaces() performs a merge rather than replace, so to
        // effectively remove erroneous registrations, we must replace them with
        // empty arrays.
426
        $namespaces_after = $this->classLoader->getPrefixes();
427
        $namespaces_before += array_fill_keys(array_diff(array_keys($namespaces_after), array_keys($namespaces_before)), array());
428
        $this->registerNamespaces($namespaces_before);
429 430 431
      }
    }

432 433
    if (!isset($this->container)) {
      $this->container = $this->buildContainer();
434
      $this->persistServices($persist);
435 436 437 438 439 440 441 442

      // The namespaces are marked as persistent, so objects like the annotated
      // class discovery still has the right object. We may have updated the
      // list of modules, so set it.
      if ($this->container->initialized('container.namespaces')) {
        $this->container->get('container.namespaces')->exchangeArray($this->container->getParameter('container.namespaces'));
      }

443 444
      if ($this->allowDumping) {
        $this->containerNeedsDumping = TRUE;
445 446 447
      }
    }

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

450 451
    // Set the class loader which was registered as a synthetic service.
    $this->container->set('class_loader', $this->classLoader);
452
    // If we have a request set it back to the new container.
453
    if ($request_scope) {
454
      $this->container->enterScope('request');
455 456
    }
    if (isset($request)) {
457 458
      $this->container->set('request', $request);
    }
459
    \Drupal::setContainer($this->container);
460
  }
461

462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
  /**
   * Returns service instances to persist from an old container to a new one.
   */
  protected function getServicesToPersist() {
    $persist = array();
    if (isset($this->container)) {
      foreach ($this->container->getParameter('persistIds') as $id) {
        // It's pointless to persist services not yet initialized.
        if ($this->container->initialized($id)) {
          $persist[$id] = $this->container->get($id);
        }
      }
    }
    return $persist;
  }

  /**
   * Moves persistent service instances into a new container.
   */
  protected function persistServices(array $persist) {
    foreach ($persist as $id => $object) {
      // Do not override services already set() on the new container, for
      // example 'service_container'.
      if (!$this->container->initialized($id)) {
        $this->container->set($id, $object);
      }
    }
  }

491 492 493 494 495
  /**
   * Builds the service container.
   *
   * @return ContainerBuilder The compiled service container
   */
496
  protected function buildContainer() {
497
    $this->initializeServiceProviders();
498
    $container = $this->getContainerBuilder();
499 500
    $container->set('kernel', $this);
    $container->setParameter('container.service_providers', $this->serviceProviderClasses);
501
    $container->setParameter('container.modules', $this->getModulesParameter());
502 503 504

    // Get a list of namespaces and put it onto the container.
    $namespaces = $this->getModuleNamespaces($this->getModuleFileNames());
505 506 507 508 509
    // Add all components in \Drupal\Core and \Drupal\Component that have a
    // Plugin directory.
    foreach (array('Core', 'Component') as $parent_directory) {
      $path = DRUPAL_ROOT . '/core/lib/Drupal/' . $parent_directory;
      foreach (new \DirectoryIterator($path) as $component) {
510
        if (!$component->isDot() && $component->isDir() && is_dir($component->getPathname() . '/Plugin')) {
511
          $namespaces['Drupal\\' . $parent_directory . '\\' . $component->getFilename()] = DRUPAL_ROOT . '/core/lib';
512 513 514
        }
      }
    }
515 516
    $container->setParameter('container.namespaces', $namespaces);

517 518 519 520 521 522
    // 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;
523 524 525 526
    if ($system = $this->getConfigStorage()->read('system.site')) {
      if ($default_language_values['id'] != $system['langcode']) {
        $default_language_values = array('id' => $system['langcode'], 'default' => TRUE);
      }
527 528 529
    }
    $container->setParameter('language.default_values', $default_language_values);

530
    // Register synthetic services.
531
    $container->register('class_loader')->setSynthetic(TRUE);
532 533
    $container->register('kernel', 'Symfony\Component\HttpKernel\KernelInterface')->setSynthetic(TRUE);
    $container->register('service_container', 'Symfony\Component\DependencyInjection\ContainerInterface')->setSynthetic(TRUE);
534 535 536 537
    $yaml_loader = new YamlFileLoader($container);
    foreach ($this->serviceYamls as $filename) {
      $yaml_loader->load($filename);
    }
538
    foreach ($this->serviceProviders as $provider) {
539 540 541
      if ($provider instanceof ServiceProviderInterface) {
        $provider->register($container);
      }
542
    }
543 544 545 546 547 548 549 550 551 552 553 554 555

    // 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);

556
    $container->compile();
557 558
    return $container;
  }
559

560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
  /**
   * Registers all service providers to the kernel.
   *
   * @throws \LogicException
   */
  protected function initializeServiceProviders() {
    $this->serviceProviders = array();

    foreach ($this->discoverServiceProviders() as $name => $provider) {
      if (isset($this->serviceProviders[$name])) {
        throw new \LogicException(sprintf('Trying to register two service providers with the same name "%s"', $name));
      }
      $this->serviceProviders[$name] = $provider;
    }
  }

576 577 578 579 580
  /**
   * Gets a new ContainerBuilder instance used to build the service container.
   *
   * @return ContainerBuilder
   */
581
  protected function getContainerBuilder() {
582 583 584
    return new ContainerBuilder(new ParameterBag($this->getKernelParameters()));
  }

585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
  /**
   * 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) {
600
    if (!$this->storage()->writeable()) {
601 602 603 604
      return FALSE;
    }
    // Cache the container.
    $dumper = new PhpDumper($container);
605 606
    $class = $this->getClassName();
    $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass));
607
    return $this->storage()->save($class . '.php', $content);
608 609
  }

610 611 612 613 614 615 616 617 618 619

  /**
   * Gets a http kernel from the container
   *
   * @return HttpKernel
   */
  protected function getHttpKernel() {
    return $this->container->get('http_kernel');
  }

katbailey's avatar
katbailey committed
620
  /**
Crell's avatar
Crell committed
621 622
   * Overrides and eliminates this method from the parent class. Do not use.
   *
katbailey's avatar
katbailey committed
623 624 625 626 627 628 629
   * This method is part of the KernelInterface interface, but takes an object
   * implementing LoaderInterface as its only parameter. This is part of the
   * Config compoment from Symfony, which is not provided by Drupal core.
   *
   * Modules wishing to provide an extension to this class which uses this
   * method are responsible for ensuring the Config component exists.
   */
630
  public function registerContainerConfiguration(LoaderInterface $loader) {
631
  }
632

633 634 635 636 637 638 639 640 641 642 643 644
  /**
   * 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;
  }

645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
  /**
   * 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 {
        $this->configStorage = BootstrapConfigStorageFactory::get();
      }
      catch (\Exception $e) {
        $this->configStorage = new NullStorage();
      }
    }
    return $this->configStorage;
  }

664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
  /**
   * 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;
  }

683 684 685 686 687 688 689
  /**
   * Returns the file name for each enabled module.
   */
  protected function getModuleFileNames() {
    $filenames = array();
    foreach ($this->moduleList as $module => $weight) {
      if ($data = $this->moduleData($module)) {
690
        $filenames[$module] = $data->getPathname();
691 692 693 694 695 696
      }
    }
    return $filenames;
  }

  /**
697
   * Gets the namespaces of each enabled module.
698
   */
699 700
  protected function getModuleNamespaces($moduleFileNames) {
    $namespaces = array();
701
    foreach ($moduleFileNames as $module => $filename) {
702 703 704 705 706 707 708 709 710
      $namespaces["Drupal\\$module"] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib';
    }
    return $namespaces;
  }

  /**
   * Registers a list of namespaces.
   */
  protected function registerNamespaces(array $namespaces = array()) {
711 712 713
    foreach ($namespaces as $prefix => $path) {
      $this->classLoader->add($prefix, $path);
    }
714
  }
715
}