Drupal 8  8.0.2
DrupalKernel Class Reference
Inheritance diagram for DrupalKernel:

Public Member Functions

 __construct ($environment, $class_loader, $allow_dumping=TRUE)
 
 setSitePath ($path)
 
 getSitePath ()
 
 getAppRoot ()
 
 boot ()
 
 shutdown ()
 
 getContainer ()
 
 setContainer (ContainerInterface $container=NULL)
 
 getCachedContainerDefinition ()
 
 loadLegacyIncludes ()
 
 preHandle (Request $request)
 
 discoverServiceProviders ()
 
 getServiceProviders ($origin)
 
 terminate (Request $request, Response $response)
 
 handle (Request $request, $type=self::MASTER_REQUEST, $catch=TRUE)
 
 prepareLegacyRequest (Request $request)
 
 updateModules (array $module_list, array $module_filenames=array())
 
 rebuildContainer ()
 
 invalidateContainer ()
 

Static Public Member Functions

static createFromRequest (Request $request, $class_loader, $environment, $allow_dumping=TRUE)
 
static findSitePath (Request $request, $require_settings=TRUE)
 
static bootEnvironment ()
 
static validateHostname (Request $request)
 

Protected Member Functions

 handleException (\Exception $e, $request, $type)
 
 moduleData ($module)
 
 getContainerCacheKey ()
 
 getKernelParameters ()
 
 initializeContainer ()
 
 initializeSettings (Request $request)
 
 initializeRequestGlobals (Request $request)
 
 getServicesToPersist (ContainerInterface $container)
 
 persistServices (ContainerInterface $container, array $persist)
 
 attachSynthetic (ContainerInterface $container)
 
 initializeServiceProviders ()
 
 getContainerBuilder ()
 
 cacheDrupalContainer (array $container_definition)
 
 getHttpKernel ()
 
 getConfigStorage ()
 
 getModulesParameter ()
 
 getModuleFileNames ()
 
 getModuleNamespacesPsr4 ($module_file_names)
 
 classLoaderAddMultiplePsr4 (array $namespaces=array())
 
 addServiceFiles (array $service_yamls)
 

Static Protected Member Functions

static validateHostnameLength ($host)
 
static setupTrustedHosts (Request $request, $host_patterns)
 

Protected Attributes

 $phpArrayDumperClass = '\Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper'
 
 $defaultBootstrapContainerDefinition
 
 $bootstrapContainerClass = '\Drupal\Component\DependencyInjection\PhpArrayContainer'
 
 $bootstrapContainer
 
 $container
 
 $environment
 
 $booted = FALSE
 
 $prepared = FALSE
 
 $moduleList
 
 $moduleData = array()
 
 $classLoader
 
 $configStorage
 
 $allowDumping
 
 $containerNeedsRebuild = FALSE
 
 $containerNeedsDumping
 
 $serviceYamls
 
 $serviceProviderClasses
 
 $serviceProviders
 
 $sitePath
 
 $root
 

Static Protected Attributes

static $isEnvironmentInitialized = FALSE
 

Detailed Description

The DrupalKernel class is the core of Drupal itself.

This class is responsible for building the Dependency Injection Container and 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, to register services to the container, or modify existing services.

Constructor & Destructor Documentation

__construct (   $environment,
  $class_loader,
  $allow_dumping = TRUE 
)

Constructs a DrupalKernel object.

Parameters
string$environmentString indicating the environment, e.g. 'prod' or 'dev'.
$class_loaderThe class loader. Normally , as included by the front controller, but may also be decorated; e.g., .
bool$allow_dumping(optional) FALSE to stop the container from being written to or read from disk. Defaults to TRUE.

References Drupal\root().

Here is the call graph for this function:

Member Function Documentation

addServiceFiles ( array  $service_yamls)
protected

Add service files.

Parameters
string[]$service_yamls A list of service files.

Referenced by DrupalKernel\discoverServiceProviders().

Here is the caller graph for this function:

attachSynthetic ( ContainerInterface  $container)
protected

Attach synthetic values on to kernel.

Parameters
ContainerInterface$containerContainer object
Returns
ContainerInterface

References DrupalKernel\classLoaderAddMultiplePsr4(), DrupalKernel\getServicesToPersist(), and DrupalKernel\persistServices().

Referenced by DrupalKernel\initializeContainer().

Here is the call graph for this function:

Here is the caller graph for this function:

boot ( )

{Boots the current kernel.

Returns
$this
}

Implements DrupalKernelInterface.

References Settings\get(), Settings\getApcuPrefix(), DrupalKernel\initializeContainer(), Crypt\randomBytes(), Drupal\root(), FileCacheFactory\setConfiguration(), and FileCacheFactory\setPrefix().

Referenced by DrupalKernel\handle(), and DrupalKernel\prepareLegacyRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

static bootEnvironment ( )
static

Setup a consistent PHP environment.

This method sets PHP environment options we want to be sure are set correctly for security or just saneness.

References Unicode\check(), and Handle\register().

Here is the call graph for this function:

cacheDrupalContainer ( array  $container_definition)
protected

Stores the container definition in a cache.

Parameters
array$container_definitionThe container definition to cache.
Returns
bool TRUE if the container was successfully cached.

References DrupalKernel\getContainerCacheKey().

Referenced by DrupalKernel\initializeContainer().

Here is the call graph for this function:

Here is the caller graph for this function:

classLoaderAddMultiplePsr4 ( array  $namespaces = array())
protected

Registers a list of namespaces with PSR-4 directories for class loading.

Parameters
array$namespacesArray where each key is a namespace like 'Drupal', and each value is either a PSR-4 base directory, or an array of PSR-4 base directories associated with this namespace.

References Drupal\root().

Referenced by DrupalKernel\attachSynthetic(), and DrupalKernel\discoverServiceProviders().

Here is the call graph for this function:

Here is the caller graph for this function:

static createFromRequest ( Request  $request,
  $class_loader,
  $environment,
  $allow_dumping = TRUE 
)
static

Create a DrupalKernel object from a request.

Parameters
\Symfony\Component\HttpFoundation\Request$requestThe request.
$class_loaderThe class loader. Normally Composer's ClassLoader, as included by the front controller, but may also be decorated; e.g., .
string$environmentString indicating the environment, e.g. 'prod' or 'dev'.
bool$allow_dumping(optional) FALSE to stop the container from being written to or read from disk. Defaults to TRUE.
Returns
static
Exceptions
\Symfony\Component\HttpKernel\Exception\BadRequestHttpExceptionIn case the host name in the request is not trusted.

Referenced by DrupalKernelTest\getTestKernel(), WebTestBase\initKernel(), BrowserTestBase\installDrupal(), InstallerTestBase\setUp(), and DrupalKernelTest\testRepeatedBootWithDifferentEnvironment().

Here is the caller graph for this function:

discoverServiceProviders ( )

{Discovers available serviceProviders.

Returns
array The available serviceProviders.
}

Implements DrupalKernelInterface.

References DrupalKernel\addServiceFiles(), DrupalKernel\classLoaderAddMultiplePsr4(), Settings\get(), DrupalKernel\getConfigStorage(), DrupalKernel\getModuleFileNames(), and DrupalKernel\getModuleNamespacesPsr4().

Referenced by DrupalKernel\initializeServiceProviders().

Here is the call graph for this function:

Here is the caller graph for this function:

static findSitePath ( Request  $request,
  $require_settings = TRUE 
)
static

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 https://www.drupal.org:8080/mysite/test whose configuration file is in sites/example.com, the array should be defined as:

$sites = array(
'8080.www.drupal.org.mysite.test' => 'example.com',
);
Parameters
\Symfony\Component\HttpFoundation\Request$requestThe current request.
bool$require_settingsOnly 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.
Returns
string The path of the matching directory.
Exceptions
\Symfony\Component\HttpKernel\Exception\BadRequestHttpExceptionIn case the host name in the request is invalid.
See Also
::getSitePath()
::setSitePath()
default.settings.php
example.sites.php

Referenced by PublicStream\basePath(), InstallerExistingSettingsTest\setUp(), InstallerExistingSettingsNoProfileTest\setUp(), InstallerTestBase\setUp(), and DrupalKernelTest\testFindSitePath().

Here is the caller graph for this function:

getAppRoot ( )

{Gets the app root.

Returns
string
}

Implements DrupalKernelInterface.

getCachedContainerDefinition ( )

{Returns the cached container definition - if any.This also allows inspecting a built container for debugging purposes.

Returns
array|NULL The cached container definition or NULL if not found in cache.
}

Implements DrupalKernelInterface.

References DrupalKernel\getContainerCacheKey().

Referenced by DrupalKernel\initializeContainer().

Here is the call graph for this function:

Here is the caller graph for this function:

getConfigStorage ( )
protected

Returns the active configuration storage to use during building the container.

Returns

References BootstrapConfigStorageFactory\get().

Referenced by DrupalKernel\discoverServiceProviders(), and DrupalKernel\moduleData().

Here is the call graph for this function:

Here is the caller graph for this function:

getContainer ( )

{Gets the current container.

Returns
A ContainerInterface instance.
}

Implements DrupalKernelInterface.

Referenced by TestRunnerKernel\boot(), and UpdateKernel\setupRequestMatch().

Here is the caller graph for this function:

getContainerBuilder ( )
protected

Gets a new ContainerBuilder instance used to build the service container.

Returns
ContainerBuilder

References DrupalKernel\getKernelParameters().

Here is the call graph for this function:

getContainerCacheKey ( )
protected

Returns the container cache key based on the environment.

Returns
string The cache key used for the service container.

References Settings\get(), and Drupal\VERSION.

Referenced by DrupalKernel\cacheDrupalContainer(), and DrupalKernel\getCachedContainerDefinition().

Here is the call graph for this function:

Here is the caller graph for this function:

getHttpKernel ( )
protected

Gets a http kernel from the container

Returns

Referenced by DrupalKernel\handle(), and DrupalKernel\terminate().

Here is the caller graph for this function:

getKernelParameters ( )
protected

Returns the kernel parameters.

Returns
array An array of kernel parameters

Referenced by DrupalKernel\getContainerBuilder().

Here is the caller graph for this function:

getModuleFileNames ( )
protected

Gets the file name for each enabled module.

Returns
array Array where each key is a module name, and each value is a path to the respective *.info.yml file.

References DrupalKernel\moduleData().

Referenced by DrupalKernel\discoverServiceProviders().

Here is the call graph for this function:

Here is the caller graph for this function:

getModuleNamespacesPsr4 (   $module_file_names)
protected

Gets the PSR-4 base directories for module namespaces.

Parameters
string[]$module_file_names Array where each key is a module name, and each value is a path to the respective *.info.yml file.
Returns
string[] Array where each key is a module namespace like 'Drupal', and each value is the PSR-4 base directory associated with the module namespace.

Referenced by DrupalKernel\discoverServiceProviders().

Here is the caller graph for this function:

getModulesParameter ( )
protected

Returns an array of Extension class parameters for all enabled modules.

Returns
array

References DrupalKernel\moduleData().

Here is the call graph for this function:

getServiceProviders (   $origin)

{Returns all registered service providers.

Parameters
string$originThe origin for which to return service providers; one of 'app' or 'site'.
Returns
array An associative array of ServiceProvider objects, keyed by name.
}

Implements DrupalKernelInterface.

getServicesToPersist ( ContainerInterface  $container)
protected

Returns service instances to persist from an old container to a new one.

Referenced by DrupalKernel\attachSynthetic().

Here is the caller graph for this function:

getSitePath ( )

{Get the site path.

Returns
string The current site path.
}

Implements DrupalKernelInterface.

handle ( Request  $request,
  $type = self::MASTER_REQUEST,
  $catch = TRUE 
)

{}

References DrupalKernel\boot(), Database\getConnectionInfo(), DrupalKernel\getHttpKernel(), DrupalKernel\handleException(), and DrupalKernel\initializeSettings().

Here is the call graph for this function:

handleException ( \Exception  $e,
  $request,
  $type 
)
protected

Converts an exception into a response.

Parameters
\Exception$eAn exception
Request$requestA Request instance
int$typeThe type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
Returns
Response A Response instance
Exceptions
\ExceptionIf the passed in exception cannot be turned into a response.

Referenced by DrupalKernel\handle().

Here is the caller graph for this function:

initializeContainer ( )
protected

Initializes the service container.

Returns

References DrupalKernel\attachSynthetic(), DrupalKernel\cacheDrupalContainer(), Settings\get(), DrupalKernel\getCachedContainerDefinition(), and Drupal\setContainer().

Referenced by DrupalKernel\boot(), DrupalKernel\rebuildContainer(), and DrupalKernel\updateModules().

Here is the call graph for this function:

Here is the caller graph for this function:

initializeRequestGlobals ( Request  $request)
protected

Bootstraps the legacy global request variables.

Parameters
\Symfony\Component\HttpFoundation\Request$requestThe current request.
Todo:
D8: Eliminate this entirely in favor of Request object.

Referenced by DrupalKernel\preHandle().

Here is the caller graph for this function:

initializeServiceProviders ( )
protected

Registers all service providers to the kernel.

Exceptions
\LogicException

References DrupalKernel\discoverServiceProviders().

Here is the call graph for this function:

initializeSettings ( Request  $request)
protected

Locate site path and initialize settings singleton.

Parameters
\Symfony\Component\HttpFoundation\Request$requestThe current request.
Exceptions
\Symfony\Component\HttpKernel\Exception\BadRequestHttpExceptionIn case the host name in the request is not trusted.

References Settings\get(), Settings\getApcuPrefix(), Settings\initialize(), Drupal\root(), and DrupalKernel\setSitePath().

Referenced by DrupalKernel\handle().

Here is the call graph for this function:

Here is the caller graph for this function:

invalidateContainer ( )

{Invalidate the service container for the next request.}

Implements DrupalKernelInterface.

loadLegacyIncludes ( )

{Helper method that loads legacy Drupal include files.}

Implements DrupalKernelInterface.

References Drupal\root().

Referenced by DrupalKernel\preHandle().

Here is the call graph for this function:

Here is the caller graph for this function:

moduleData (   $module)
protected

Returns module data on the filesystem.

Parameters
$moduleThe name of the module.
Returns
|bool Returns an Extension object if the module is found, FALSE otherwise.

References DrupalKernel\getConfigStorage(), and Drupal\root().

Referenced by TestRunnerKernel\__construct(), DrupalKernel\getModuleFileNames(), DrupalKernel\getModulesParameter(), DrupalKernel\rebuildContainer(), DrupalKernel\shutdown(), and DrupalKernel\updateModules().

Here is the call graph for this function:

Here is the caller graph for this function:

persistServices ( ContainerInterface  $container,
array  $persist 
)
protected

Moves persistent service instances into a new container.

Referenced by DrupalKernel\attachSynthetic().

Here is the caller graph for this function:

preHandle ( Request  $request)

{Helper method that does request related initialization.

Parameters
\Symfony\Component\HttpFoundation\Request$requestThe current request.
}

Implements DrupalKernelInterface.

References DrupalKernel\initializeRequestGlobals(), DrupalKernel\loadLegacyIncludes(), MimeTypeGuesser\registerWithSymfonyGuesser(), and UrlHelper\setAllowedProtocols().

Referenced by DrupalKernel\prepareLegacyRequest().

Here is the call graph for this function:

Here is the caller graph for this function:

prepareLegacyRequest ( Request  $request)

{Prepare the kernel for handling a request without handling the request.

Parameters
\Symfony\Component\HttpFoundation\Request$requestThe current request.
Returns
$this
Deprecated:
in Drupal 8.0.x and will be removed before 9.0.0. Only used by legacy front-controller scripts.
}

Implements DrupalKernelInterface.

References DrupalKernel\boot(), and DrupalKernel\preHandle().

Here is the call graph for this function:

rebuildContainer ( )

{Force a container rebuild.

Returns
}

Implements DrupalKernelInterface.

References DrupalKernel\initializeContainer(), and DrupalKernel\moduleData().

Here is the call graph for this function:

setContainer ( ContainerInterface  $container = NULL)

{}

setSitePath (   $path)

{Set the current site path.

Parameters
string$pathThe current site path.
Exceptions
\LogicExceptionIn case the kernel is already booted.
}

Implements DrupalKernelInterface.

Referenced by DrupalKernel\initializeSettings().

Here is the caller graph for this function:

static setupTrustedHosts ( Request  $request,
  $host_patterns 
)
staticprotected

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 through settings.php for multisite installations, sites using ServerAlias without canonical redirection, or configurations where the site responds to default requests. For example,

$settings['trusted_host_patterns'] = array(
'^example\.com$',
'^*.example\.com$',
);
Parameters
\Symfony\Component\HttpFoundation\Request$requestThe request object.
array$host_patternsThe array of trusted host patterns.
Returns
bool TRUE if the Host header is trusted, FALSE otherwise.
See Also
https://www.drupal.org/node/1992030
shutdown ( )

{Shuts down the kernel.}

Implements DrupalKernelInterface.

References DrupalKernel\moduleData().

Here is the call graph for this function:

terminate ( Request  $request,
Response  $response 
)

{}

References DrupalKernel\getHttpKernel().

Here is the call graph for this function:

updateModules ( array  $module_list,
array  $module_filenames = array() 
)

Implements Drupal::updateModules().

Todo:
Remove obsolete $module_list parameter. Only $module_filenames is needed.

Implements DrupalKernelInterface.

References DrupalKernel\initializeContainer(), and DrupalKernel\moduleData().

Here is the call graph for this function:

static validateHostname ( Request  $request)
static

Validates the hostname supplied from the HTTP request.

Parameters
\Symfony\Component\HttpFoundation\Request$requestThe request object
Returns
bool TRUE if the hostname is valid, or FALSE otherwise.

Referenced by ValidateHostnameTest\testValidateHostname().

Here is the caller graph for this function:

static validateHostnameLength (   $host)
staticprotected

Validates a hostname length.

Parameters
string$hostA hostname.
Returns
bool TRUE if the length is appropriate, or FALSE otherwise.

Field Documentation

$defaultBootstrapContainerDefinition
protected
Initial value:
= [
'parameters' => []

The documentation for this class was generated from the following file: