kernel.php
Table of Contents
Functions
- app() : mixed
- Retrieve an instance of the specified class from the container.
- singleton() : mixed
- Registers or retrieves a singleton instance of a class in the container.
- env() : mixed
- Retrieves the value of an environment variable.
- resourcesDirectory() : string
- Retrieves the path to the resources directory.
- config() : mixed
- Retrieve a configuration value by its key.
Functions
app()
Retrieve an instance of the specified class from the container.
app([string $class = Kernel::class ]) : mixed
By default, this function resolves the Kernel
class, but you can specify
a different class to resolve by passing its fully qualified class name.
Parameters
- $class : string = Kernel::class
-
The fully qualified class name to resolve. Defaults to
Kernel::class
.
Return values
mixed —The resolved instance of the specified class.
singleton()
Registers or retrieves a singleton instance of a class in the container.
singleton(string $class[, string|callable|null $build = null ]) : mixed
This function ensures that only one instance of the specified class is created and shared throughout the application. If a callable or a specific build logic is provided, it will be used to construct the instance.
Parameters
- $class : string
-
The fully qualified class name to register or retrieve as a singleton.
- $build : string|callable|null = null
-
Optional. A callable or a string representing the logic to build the instance. If null, the default constructor will be used.
Tags
Return values
mixed —The singleton instance of the specified class.
env()
Retrieves the value of an environment variable.
env(string $var[, mixed $default = null ]) : mixed
This function checks the $_ENV
superglobal for the specified variable
and returns its value if it exists. If the variable is not set, the
provided default value will be returned instead.
Parameters
- $var : string
-
The name of the environment variable to retrieve.
- $default : mixed = null
-
The default value to return if the environment variable is not set. Defaults to null.
Return values
mixed —The value of the environment variable, or the default value if the variable is not set.
resourcesDirectory()
Retrieves the path to the resources directory.
resourcesDirectory() : string
Return values
string —The absolute path to the resources directory.
config()
Retrieve a configuration value by its key.
config(string $key[, mixed $default = null ]) : mixed
This function fetches a configuration value from the application's configuration repository. If the specified key does not exist, a default value can be returned.
Parameters
- $key : string
-
The configuration key to retrieve.
- $default : mixed = null
-
The default value to return if the key does not exist. Defaults to null.
Return values
mixed —The configuration value associated with the key, or the default value if the key does not exist.