abstract class Kernel implements KernelInterface, RebootableInterface, TerminableInterface

The Kernel is the heart of the Symfony system.

It manages an environment made of bundles.

Constants

VERSION

VERSION_ID

MAJOR_VERSION

MINOR_VERSION

RELEASE_VERSION

EXTRA_VERSION

END_OF_MAINTENANCE

END_OF_LIFE

Properties

protected BundleInterface[] $bundles
protected $bundleMap
protected $container
protected $rootDir
protected $environment
protected $debug
protected $booted
protected $name
protected $startTime
protected $loadClassCache

Methods

__construct(string $environment, bool $debug)

No description

__clone()

No description

boot()

Boots the current kernel.

reboot(string|null $warmupDir)

Reboots a kernel.

terminate(Request $request, Response $response)

Terminates a request/response cycle.

shutdown()

Shutdowns the kernel.

handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)

Handles a Request to convert it to a Response.

getHttpKernel()

Gets a HTTP kernel from the container.

getBundles()

Gets the registered bundle instances.

getBundle(string $name, bool $first = true)

Returns a bundle and optionally its descendants by its name.

string|array
locateResource(string $name, string $dir = null, bool $first = true)

Returns the file path for a given resource.

string
getName()

Gets the name of the kernel.

string
getEnvironment()

Gets the environment.

bool
isDebug()

Checks if debug mode is enabled.

string
getRootDir()

Gets the application root dir (path of the project's Kernel class).

string
getProjectDir()

Gets the application root dir (path of the project's composer file).

getContainer()

Gets the current container.

loadClassCache(string $name = 'classes', string $extension = '.php') deprecated

Loads the PHP class cache.

setClassCache(array $classes) deprecated

No description

setAnnotatedClassCache(array $annotatedClasses)

No description

int
getStartTime()

Gets the request start time (not available if debug is disabled).

string
getCacheDir()

Gets the cache directory.

string
getLogDir()

Gets the log directory.

string
getCharset()

Gets the charset of the application.

doLoadClassCache($name, $extension) deprecated

No description

initializeBundles()

Initializes the data structures related to the bundle management.

build(ContainerBuilder $container)

The extension point similar to the Bundle::build() method.

string
getContainerClass()

Gets the container class.

string
getContainerBaseClass()

Gets the container's base class.

initializeContainer()

Initializes the service container.

array
getKernelParameters()

Returns the kernel parameters.

array
getEnvParameters() deprecated

Gets the environment parameters.

buildContainer()

Builds the service container.

prepareContainer(ContainerBuilder $container)

Prepares the ContainerBuilder before it is compiled.

getContainerBuilder()

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

dumpContainer(ConfigCache $cache, ContainerBuilder $container, string $class, string $baseClass)

Dumps the service container to PHP code in the cache.

getContainerLoader(ContainerInterface $container)

Returns a loader for the container.

static string
stripComments(string $source)

Removes comments from a PHP source string.

serialize()

No description

unserialize($data)

No description

Details

at line 84
__construct(string $environment, bool $debug)

Parameters

string $environment The environment
bool $debug Whether to enable debugging or not

at line 92
__clone()

at line 103
boot()

Boots the current kernel.

at line 148
reboot(string|null $warmupDir)

Reboots a kernel.

The getCacheDir() method of a rebootable kernel should not be called while building the container. Use the %kernel.cache_dir% parameter instead.

Parameters

string|null $warmupDir pass null to reboot in the regular cache directory

at line 158
terminate(Request $request, Response $response)

Terminates a request/response cycle.

Should be called after sending the response and before shutting down the kernel.

Parameters

Request $request
Response $response

at line 172
shutdown()

Shutdowns the kernel.

This method is mainly useful when doing functional testing.

at line 193
Response handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true)

Handles a Request to convert it to a Response.

When $catch is true, the implementation must catch all exceptions and do its best to convert them to a Response instance.

Parameters

Request $request A Request instance
int $type The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
bool $catch Whether to catch exceptions or not

Return Value

Response A Response instance

Exceptions

Exception When an Exception occurs during processing

at line 211
protected HttpKernel getHttpKernel()

Gets a HTTP kernel from the container.

Return Value

HttpKernel

at line 219
BundleInterface[] getBundles()

Gets the registered bundle instances.

Return Value

BundleInterface[] An array of registered bundle instances

at line 227
BundleInterface|BundleInterface[] getBundle(string $name, bool $first = true)

Returns a bundle and optionally its descendants by its name.

The second argument is deprecated as of 3.4 and will be removed in 4.0. This method will always return an instance of BundleInterface in 4.0.

Parameters

string $name Bundle name
bool $first Whether to return the first bundle only or together with its descendants

Return Value

BundleInterface|BundleInterface[] A BundleInterface instance or an array of BundleInterface instances if $first is false

Exceptions

InvalidArgumentException when the bundle is not enabled

at line 254
string|array locateResource(string $name, string $dir = null, bool $first = true)

Returns the file path for a given resource.

A Resource can be a file or a directory.

The resource name must follow the following pattern:

"@BundleName/path/to/a/file.something"

where BundleName is the name of the bundle and the remaining part is the relative path in the bundle.

If $dir is passed, and the first segment of the path is "Resources", this method will look for a file named:

$dir/<BundleName>/path/without/Resources

before looking in the bundle resource folder.

Parameters

string $name A resource name to locate
string $dir A directory where to look for the resource first
bool $first Whether to return the first path or paths for all matching bundles

Return Value

string|array The absolute path of the resource or an array if $first is false

Exceptions

InvalidArgumentException if the file cannot be found or the name is not valid
RuntimeException if the name contains invalid/unsafe characters

at line 307
string getName()

Gets the name of the kernel.

Return Value

string The kernel name

at line 322
string getEnvironment()

Gets the environment.

Return Value

string The current environment

at line 330
bool isDebug()

Checks if debug mode is enabled.

Return Value

bool true if debug mode is enabled, false otherwise

at line 338
string getRootDir()

Gets the application root dir (path of the project's Kernel class).

Return Value

string The Kernel root dir

at line 353
string getProjectDir()

Gets the application root dir (path of the project's composer file).

Return Value

string The project root dir

at line 373
ContainerInterface|null getContainer()

Gets the current container.

Return Value

ContainerInterface|null A ContainerInterface instance or null when the Kernel is shutdown

at line 392
loadClassCache(string $name = 'classes', string $extension = '.php') deprecated

deprecated since version 3.3, to be removed in 4.0. The class cache is not needed anymore when using PHP 7.0.

Loads the PHP class cache.

This methods only registers the fact that you want to load the cache classes. The cache will actually only be loaded when the Kernel is booted.

That optimization is mainly useful when using the HttpCache class in which case the class cache is not loaded if the Response is in the cache.

Parameters

string $name The cache name prefix
string $extension File extension of the resulting file

at line 406
setClassCache(array $classes) deprecated

deprecated since version 3.3, to be removed in 4.0.

Parameters

array $classes

at line 418
setAnnotatedClassCache(array $annotatedClasses)

Parameters

array $annotatedClasses

at line 426
int getStartTime()

Gets the request start time (not available if debug is disabled).

Return Value

int The request start timestamp

at line 434
string getCacheDir()

Gets the cache directory.

Return Value

string The cache directory

at line 442
string getLogDir()

Gets the log directory.

Return Value

string The log directory

at line 450
string getCharset()

Gets the charset of the application.

Return Value

string The charset

at line 458
protected doLoadClassCache($name, $extension) deprecated

deprecated since version 3.3, to be removed in 4.0.

Parameters

$name
$extension

at line 481
protected initializeBundles()

Initializes the data structures related to the bundle management.

  • the bundles property maps a bundle name to the bundle instance,
    • the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first).

Exceptions

LogicException if two bundles share a common name
LogicException if a bundle tries to extend a non-registered bundle
LogicException if a bundle tries to extend itself
LogicException if two bundles extend the same ancestor

at line 541
protected build(ContainerBuilder $container)

The extension point similar to the Bundle::build() method.

Use this method to register compiler passes and manipulate the container during the building process.

Parameters

ContainerBuilder $container

at line 550
protected string getContainerClass()

Gets the container class.

Return Value

string The container class

at line 562
protected string getContainerBaseClass()

Gets the container's base class.

All names except Container must be fully qualified.

Return Value

string

at line 573
protected initializeContainer()

Initializes the service container.

The cached version of the service container is used when fresh, otherwise the container is built.

at line 689
protected array getKernelParameters()

Returns the kernel parameters.

Return Value

array An array of kernel parameters

at line 730
protected array getEnvParameters() deprecated

deprecated since version 3.3, to be removed in 4.0

Gets the environment parameters.

Only the parameters starting with "SYMFONY__" are considered.

Return Value

array An array of parameters

at line 754
protected ContainerBuilder buildContainer()

Builds the service container.

Return Value

ContainerBuilder The compiled service container

Exceptions

RuntimeException

at line 783
protected prepareContainer(ContainerBuilder $container)

Prepares the ContainerBuilder before it is compiled.

Parameters

ContainerBuilder $container

at line 815
protected ContainerBuilder getContainerBuilder()

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

Return Value

ContainerBuilder

at line 838
protected dumpContainer(ConfigCache $cache, ContainerBuilder $container, string $class, string $baseClass)

Dumps the service container to PHP code in the cache.

Parameters

ConfigCache $cache The config cache
ContainerBuilder $container The service container
string $class The name of the class to generate
string $baseClass The name of the container's base class

at line 875
protected DelegatingLoader getContainerLoader(ContainerInterface $container)

Returns a loader for the container.

Parameters

ContainerInterface $container

Return Value

DelegatingLoader The loader

at line 901
static string stripComments(string $source)

Removes comments from a PHP source string.

We don't use the PHP php_strip_whitespace() function as we want the content to be readable and well-formatted.

Parameters

string $source A PHP string

Return Value

string The PHP string with the comments removed

at line 954
serialize()

at line 959
unserialize($data)

Parameters

$data