class Kernel implements KernelInterface, 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

Methods

__construct(string $environment, bool $debug)

Constructor.

__clone()

No description

boot()

Boots the current 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.

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.

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.

static string
stripComments(string $source)

Removes comments from a PHP source string.

serialize()

No description

unserialize($data)

No description

Details

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

Constructor.

Parameters

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

at line line 90
__clone()

at line line 103
boot()

Boots the current kernel.

at line line 126
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 A Request instance
Response $response A Response instance

at line line 140
shutdown()

Shutdowns the kernel.

This method is mainly useful when doing functional testing.

at line line 159
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::MASTERREQUEST or HttpKernelInterface::SUBREQUEST)
bool $catch Whether to catch exceptions or not

Return Value

Response A Response instance

Exceptions

Exception When an Exception occurs during processing

at line line 181
BundleInterface[] getBundles()

Gets the registered bundle instances.

Return Value

BundleInterface[] An array of registered bundle instances

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

Returns a bundle and optionally its descendants by its name.

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 line 207
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 line 264
string getName()

Gets the name of the kernel.

Return Value

string The kernel name

at line line 279
string getEnvironment()

Gets the environment.

Return Value

string The current environment

at line line 287
bool isDebug()

Checks if debug mode is enabled.

Return Value

bool true if debug mode is enabled, false otherwise

at line line 295
string getRootDir()

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

Return Value

string The Kernel root dir

at line line 310
string getProjectDir()

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

Return Value

string The project root dir

at line line 330
ContainerInterface getContainer()

Gets the current container.

Return Value

ContainerInterface A ContainerInterface instance

at line line 338
setAnnotatedClassCache(array $annotatedClasses)

Parameters

array $annotatedClasses

at line line 346
int getStartTime()

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

Return Value

int The request start timestamp

at line line 354
string getCacheDir()

Gets the cache directory.

Return Value

string The cache directory

at line line 362
string getLogDir()

Gets the log directory.

Return Value

string The log directory

at line line 370
string getCharset()

Gets the charset of the application.

Return Value

string The charset

at line line 712
static string stripComments(string $source)

Removes comments from a PHP source string.

We don't use the PHP phpstripwhitespace() 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 line 763
serialize()

at line line 768
unserialize($data)

Parameters

$data