Documentation

KernelInterface extends HttpKernelInterface, Serializable

The Kernel is the heart of the Symfony system.

It manages an environment made of bundles.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

MASTER_REQUEST  = 1
SUB_REQUEST  = 2
boot()  : mixed
Boots the current kernel.
getBundle()  : BundleInterface|array<string|int, BundleInterface>
Returns a bundle and optionally its descendants by its name.
getBundles()  : array<string|int, BundleInterface>
Gets the registered bundle instances.
getCacheDir()  : string
Gets the cache directory.
getCharset()  : string
Gets the charset of the application.
getContainer()  : ContainerInterface|null
Gets the current container.
getEnvironment()  : string
Gets the environment.
getLogDir()  : string
Gets the log directory.
getName()  : string
Gets the name of the kernel.
getRootDir()  : string
Gets the application root dir (path of the project's Kernel class).
getStartTime()  : float
Gets the request start time (not available if debug is disabled).
handle()  : Response
Handles a Request to convert it to a Response.
isDebug()  : bool
Checks if debug mode is enabled.
locateResource()  : string|array<string|int, mixed>
Returns the file path for a given resource.
registerBundles()  : iteratable<string|int, mixed>|array<string|int, BundleInterface>
Returns an array of bundles to register.
registerContainerConfiguration()  : mixed
Loads the container configuration.
shutdown()  : mixed
Shutdowns the kernel.

Constants

Methods

boot()

Boots the current kernel.

public boot() : mixed
Return values
mixed

getBundle()

Returns a bundle and optionally its descendants by its name.

public getBundle(string $name[, bool $first = true ]) : BundleInterface|array<string|int, BundleInterface>

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
$name : string

Bundle name

$first : bool = true

Whether to return the first bundle only or together with its descendants

Tags
throws
InvalidArgumentException

when the bundle is not enabled

Return values
BundleInterface|array<string|int, BundleInterface>

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

getCacheDir()

Gets the cache directory.

public getCacheDir() : string
Return values
string

The cache directory

getCharset()

Gets the charset of the application.

public getCharset() : string
Return values
string

The charset

getContainer()

Gets the current container.

public getContainer() : ContainerInterface|null
Return values
ContainerInterface|null

A ContainerInterface instance or null when the Kernel is shutdown

getEnvironment()

Gets the environment.

public getEnvironment() : string
Return values
string

The current environment

getLogDir()

Gets the log directory.

public getLogDir() : string
Return values
string

The log directory

getName()

Gets the name of the kernel.

public getName() : string
Return values
string

The kernel name

getRootDir()

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

public getRootDir() : string
Return values
string

The Kernel root dir

getStartTime()

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

public getStartTime() : float
Return values
float

The request start timestamp

handle()

Handles a Request to convert it to a Response.

public handle(Request $request[, int $type = self::MASTER_REQUEST ][, bool $catch = true ]) : 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

$type : int = self::MASTER_REQUEST

The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)

$catch : bool = true

Whether to catch exceptions or not

Tags
throws
Exception

When an Exception occurs during processing

Return values
Response

A Response instance

isDebug()

Checks if debug mode is enabled.

public isDebug() : bool
Return values
bool

true if debug mode is enabled, false otherwise

locateResource()

Returns the file path for a given resource.

public locateResource(string $name[, string $dir = null ][, bool $first = true ]) : string|array<string|int, mixed>

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
$name : string

A resource name to locate

$dir : string = null

A directory where to look for the resource first

$first : bool = true

Whether to return the first path or paths for all matching bundles

Tags
throws
InvalidArgumentException

if the file cannot be found or the name is not valid

throws
RuntimeException

if the name contains invalid/unsafe characters

Return values
string|array<string|int, mixed>

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

registerBundles()

Returns an array of bundles to register.

public registerBundles() : iteratable<string|int, mixed>|array<string|int, BundleInterface>
Return values
iteratable<string|int, mixed>|array<string|int, BundleInterface>

An iterable of bundle instances

registerContainerConfiguration()

Loads the container configuration.

public registerContainerConfiguration(LoaderInterface $loader) : mixed
Parameters
$loader : LoaderInterface
Return values
mixed

shutdown()

Shutdowns the kernel.

public shutdown() : mixed

This method is mainly useful when doing functional testing.

Return values
mixed

Search results