PHP Luminova: Application Service Kernel
Luminova Service Kernel provides a simple, predictable way to initialize core services. Configure logger, cache, mailer, HTTP client, and session handlers for your application in one place.
The Service Kernel is responsible for bootstrapping core services in a Luminova application.
It does not handle requests, routing, middleware, or application flow.Its only responsibility is to define which core services are used at boot time. Including implementing dynamic environment-deriving Application Classes.
If a service is not defined, Luminova falls back to its default implementation.
Purpose
The Kernel exists to centralize system-level configuration:
- Define core services (application, routing, logger, cache, session, mailer, HTTP client, Memcached, Redis)
- Replace default implementations when needed
- Register custom application services
- Support environment-specific service configuration
- Act as a lightweight service container via
has(),get()andresolve(), with an optional shared-instance registry
Kernel Contract
Every Luminova application must define exactly one Kernel class.
Requirements:
- Location:
/app/Kernel.php - Class name:
Kernel(fixed, cannot be changed) - Must extend:
Luminova\Foundation\Core\ServiceKernel - Must implement the three abstract methods:
has(),get()andshouldShareService()
The default kernel delegates everything to the framework's built-in service handling:
namespace App;
use Luminova\Foundation\Core\ServiceKernel;
final class Kernel extends ServiceKernel
{
public function shouldShareService(string $service): bool
{
return parent::shouldShareDefaultService($service);
}
public function get(string $service, mixed ...$arguments): object|string|null
{
return parent::getDefaultService($service, ...$arguments);
}
public function has(string $service): bool
{
return parent::isDefaultService($service);
}
}Note:
Built-in services are resolved by
Kernel::resolve()directly through the protected default-service handlers, they never pass through yourget(),has()orshouldShareService().To replace a built-in service, override its factory method instead (e.g.getLogger(),getMailer()). See Methods.
Services
Kernel::resolve() supports the following built-in service identifiers:
| Service | Identifiers |
|---|---|
| HTTP Client | http.client, Psr\Http\Client\ClientInterface::class, Luminova\Interface\ClientInterface::class |
| Logger | logger, Psr\Log\LoggerInterface::class |
| Mailer | mailer, Luminova\Interface\MailerInterface::class |
| Session | session, Luminova\Interface\SessionInterface::class |
| Router | router, routing, Luminova\Interface\RouterInterface::class |
| Application | app, application, Luminova\Foundation\Core\Application::class |
| Memcached | memcached, Memcached::class |
| Redis | redis, Redis::class |
| Cache | cache, Luminova\Base\Cache::class |
| Cache ID | cache.id |
| App Keys | app.keys |
You can resolve a service using either its short identifier or its corresponding class/interface name.Aliases are normalized to a canonical service name, so router, routing and RouterInterface::class all refer to the same service.
For example:
$logger = Kernel::resolve('logger');
// or
$logger = Kernel::resolve(LoggerInterface::class);The cache.id and app.keys services are values rather than objects:
// Request-based cache identifier.
$cacheId = Kernel::resolve(Kernel::SERVICE_CACHE_ID, prefix: 'user-1');
// Current and previous application encryption keys.
$keys = Kernel::resolve(Kernel::SERVICE_APP_KEYS);Note:
You can also define custom service identifiers and resolve them through
kernel().Register the service with the kernel container by overridinghas()andget(), then pass your custom identifier tokernel().
$payment = Kernel::resolve('myPayment');This allows applications and modules to expose their own services through the same kernel service-resolution mechanism.
Examples
Basic Kernel Class
A minimal kernel implementation defines how custom application services are registered, resolved, and shared while allowing built-in services to fall back to the framework defaults.
// /app/Kernel.php
namespace App;
use Monolog\Level;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use App\Services\MyClassService;
use App\Services\MyPaymentService;
use Monolog\Handler\StreamHandler;
use Luminova\Foundation\Core\ServiceKernel;
final class Kernel extends ServiceKernel
{
/**
* Resolve a registered application service.
*/
public function get(string $service, mixed ...$arguments): mixed
{
return match ($service) {
'myPayment' => $this->getMyPayment(...$arguments),
'myClass' => $this->getMyClass(...$arguments),
default => parent::getDefaultService($service, ...$arguments),
};
}
/**
* Determine whether a service is registered by the application kernel.
*/
public function has(string $service): bool
{
return match ($service) {
'myPayment',
'myClass' => true,
default => parent::isDefaultService($service),
};
}
/**
* Determine whether a resolved custom service should be shared.
*/
public function shouldShareService(string $service): bool
{
return match ($service) {
'myPayment' => false,
'myClass' => true,
default => parent::shouldShareDefaultService($service),
};
}
/**
* Resolve the application's preferred logger.
*
* This overrides the framework's default logger with a custom Monolog
* configuration.
*/
public function getLogger(mixed ...$arguments): LoggerInterface
{
$logger = new Logger('my_app_channel');
$logger->pushHandler(
new StreamHandler(
root('/writeable/logs/', 'app.log'),
Level::Debug
)
);
return $logger;
}
/**
* Custom payment service.
*/
public function getMyPayment(string $key, string $merchant): MyPaymentService
{
return new MyPaymentService($key, $merchant);
}
/**
* Other custom class service.
*/
public function getMyClass(mixed ...$arguments): MyClassService
{
return new MyClassService(...$arguments);
}
}Define only what you need. Everything else falls back to the framework's built-in service handling.
shouldShareService(),get()andhas()are abstract methods, so every customKernelmust implement them.For built-in services, sharing is decided byparent::shouldShareDefaultService()andshouldShareService()is not consulted. For custom services,shouldShareService()is the sole authority.
Registering a Class-String Service
get() may return a class name instead of an object. When resolve() receives a string that is an existing class, it instantiates it with the supplied arguments.
public function has(string $service): bool
{
return match ($service) {
'myClass' => true,
default => parent::isDefaultService($service),
};
}
public function get(string $service, mixed ...$arguments): mixed
{
return match ($service) {
'myClass' => MyClassService::class,
default => parent::getDefaultService($service, ...$arguments),
};
}// Instantiated as: new MyClassService('arg1', 'arg2')
$service = Kernel::resolve('myClass', true, 'arg1', 'arg2');Dynamic Service Resolving
The Kernel can dynamically resolve which application service to use based on the runtime context.
This allows you to switch application behavior depending on environment (CLI vs HTTP) or architecture (MVC vs HMVC), without touching the core boot process.
Example: Resolving Application
// Kernel::getApplication
use Luminova\Runtime;
use App\CliApplication;
use App\HttpApplication;
use App\HttpHmvcApplication;
use Luminova\Foundation\Core\Application;
public function getApplication(): Application
{
return match (true) {
Runtime::isCommand() => new CliApplication(),
Runtime::isHmvc() => new HttpHmvcApplication(),
default => new HttpApplication(),
};
}Override
getApplicationonly when you intend to return a concreteApplicationinstance. Leave it undefined in your Kernel to keep the framework default (App\Application).
Accessing Kernel Services
The kernel provides two ways to access application services: directly through the kernel instance or through the service resolver. The Luminova::kernel() helper provides the recommended public API.
Manual Kernel Access
Use Kernel::create() when you need direct access to the kernel instance or its configuration methods.
use App\Kernel;
// Retrieve the shared kernel instance.
$kernel = Kernel::create(shared: true);
// Resolve a new application instance directly.
$application = $kernel->getApplication();Calling getApplication() directly creates a new application instance according to the kernel implementation. It does not use the service resolver's shared-service registry.
Using the Service Resolver
Use Kernel::resolve() when resolving a service. It handles registered services, built-in services, and shared service instances.
use App\Kernel;
// Resolve and share the application instance.
$application = Kernel::resolve(
Kernel::SERVICE_APPLICATION,
shared: true
);
// Resolve a new application instance without sharing it.
$application = Kernel::resolve(
Kernel::SERVICE_APPLICATION,
shared: false
);
// Resolve the routing system, the application is passed to the router.
$router = Kernel::resolve(
Kernel::SERVICE_ROUTING,
true,
$application
);
// Resolve the HTTP client with additional arguments.
$client = Kernel::resolve(
Kernel::SERVICE_HTTP_CLIENT,
shared: true,
// ...arguments
);
$response = $client->request(
'GET',
'https://example.com',
// ...request options
);When
shared: trueis used, the service resolver reuses an existing shared service instance when one has been registered. The HTTP client is never stored as shared.
Managing Shared Services
The shared service registry can be managed manually with share(), unshare() and isShared().
use App\Kernel;
// Register an object as the shared instance of a service.
Kernel::share('logger', $logger);
// Check whether a shared instance exists (aliases are normalized).
Kernel::isShared(Psr\Log\LoggerInterface::class); // true
// Remove the shared instance, the next resolve() creates a new one.
Kernel::unshare('logger');Class Definition
- Class namespace:
\App\Kernel - This class extends:
Luminova\Foundation\Core\ServiceKernel
Constants
| Constant | Value | Description |
|---|---|---|
SERVICE_HTTP_CLIENT | http.client | HTTP client service identifier. |
SERVICE_LOGGER | logger | Logger service identifier. |
SERVICE_MAILER | mailer | Mailer service identifier. |
SERVICE_SESSION | session | Session service identifier. |
SERVICE_ROUTING | routing | Routing system service identifier. |
SERVICE_APPLICATION | application | Application service identifier. |
SERVICE_MEMCACHED | memcached | Memcached service identifier. |
SERVICE_REDIS | redis | Redis service identifier. |
SERVICE_CACHE | cache | Cache service identifier. |
SERVICE_CACHE_ID | cache.id | Auto URI-driven cache identifier. |
SERVICE_APP_KEYS | app.keys | Application encryption keys identifier. |
All constants are
public final const, they may be referenced (e.g.Kernel::SERVICE_LOGGER) but not overridden.
Methods
create
Create or retrieve a kernel instance.
When $shared is true, returns the existing shared kernel instance or creates and stores one when none exists. When $shared is false, a new kernel instance is created for the current resolution and is not stored as the shared instance.
public static function create(bool $shared): staticParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return or create the shared kernel instance. |
Return Value:
static - Returns the shared kernel instance, or a new instance when sharing is disabled.
Note:This method is used by Luminova to initialize and create the kernel object.Use
resolve()to resolve services.
resolve
Resolve a service from the application kernel.
When $shared is enabled and a shared instance of the service is already registered, that instance is returned and $arguments are ignored. Aliases are normalized, so the same instance is returned for router, routing and RouterInterface::class.
Otherwise the service is resolved as follows:
- Built-in services are resolved by the kernel's default service handlers (
getLogger(),getCacheProvider(), etc.). The result is stored as shared only when$sharedistrueand the service is shared by default (seeshouldShareDefaultService()). Your kernel'shas(),get()andshouldShareService()are not consulted. - Custom services must be registered with
has(), then are resolved withget(). Ifget()returns a string naming an existing class, it is instantiated with$arguments. The result is stored as shared only when$sharedistrueandshouldShareService()returnstrue.
When $shared is disabled, a previously shared instance is not reused and the result is not stored. A null result is never stored.
final public static function resolve(
string $service,
bool $shared = true,
mixed ...$arguments
): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service identifier or class/interface name. |
$shared | bool | Whether to reuse and, when supported, store a shared service instance (default: true). |
...$arguments | mixed | Arguments passed to the service resolver or constructor. |
Return Value:
mixed - Returns the resolved service result.
Throws:
Luminova\Exceptions\RuntimeException- If the service is not registered and is not a built-in kernel service.Luminova\Exceptions\ClassException- If the resolved service is not a valid object.Luminova\Exceptions\RuntimeException- If a Redis connection or authentication fails while resolvingredis.
Note:
This method is
finaland cannot be overridden.Theapplicationservice ignores$arguments. Theroutingservice expects theApplicationinstance as its argument.Because thecacheservice is shared by default, later calls with different driver arguments return the first shared instance unlessshared: falseis used.
Examples:
Direct usage:
use App\Kernel;
$logger = Kernel::resolve('logger');Via the global function:
use function Luminova\Funcs\kernel;
$logger = kernel('logger');share
Register a service as a shared service.
The provided value is stored in the shared service registry using the service's resolved name. Subsequent calls to resolve() with $shared enabled return the registered value instead of creating a new one. An existing entry for the same service is replaced.
public static final function share(string $service, mixed $result): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service name or alias to register. |
$result | mixed | The service instance or value to share. |
Return Value:
void
unshare
Remove a service from the shared service registry.
The next resolve() call for the service creates a new instance. Has no effect when the service is not shared.
public static final function unshare(string $service): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service name or alias to remove. |
Return Value:
void
isShared
Determine whether a service is registered as a shared service.
public static final function isShared(string $service): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service name or alias to check. |
Return Value:
bool - Returns true if the service is registered as shared, otherwise false.
has
Determine whether a service is defined in the kernel.
This method only checks for the existence of the service identifier and does not guarantee that the service can be successfully resolved.
abstract public function has(string $service): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service identifier or class/interface name. |
Return Value:
bool - Returns true if the service exists, false otherwise.
Note:Override this method along with
get()to register custom services.resolve()only callshas()for services that are not built-in.
get
Resolve a service instance from the kernel.
Implementations are responsible for resolving the given service identifier and returning the corresponding service instance, class name or other value.
A class name may be returned when the service is registered as a class-string, the kernel resolver will instantiate it using the supplied arguments.
abstract public function get(string $service, mixed ...$arguments): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service identifier or class/interface name. |
...$arguments | mixed | Arguments passed to the service resolver or constructor when applicable. |
Return Value:
mixed - Returns the resolved service result, a resolvable class name, or null when the service cannot be resolved.
Throws:
\Throwable - If the service cannot be resolved.
Note:Override this method along with
has()to register custom services.The defaultApp\Kernelnarrows the return type toobject|string|null, which is allowed, but delegating togetDefaultService()may return non-object values such ascache.idorapp.keys. Usemixedif you delegate those.resolve()callsget()only for custom services.
shouldShareService
Determine whether the kernel should share the same service object.
Returning true allows the kernel to reuse the same service instance for subsequent resolutions. Returning false causes a new instance to be created for each resolution.
This method is consulted by resolve() for custom services only, where it is the sole authority on whether the instance is shared. Built-in services are never passed to it, their sharing is decided by shouldShareDefaultService().
abstract public function shouldShareService(string $service): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service identifier or class/interface name. |
Return Value:
bool - Returns true to share the service object, otherwise false.
Note:This method is abstract and has no default implementation, every
App\Kernelmust define its own logic.
getApplication
Resolve and return the application instance.
Override this method to provide a custom application implementation. The returned instance is used as the application's main runtime entry point and may vary depending on the current runtime environment.
public function getApplication(): Luminova\Foundation\Core\ApplicationReturn Value:
Luminova\Foundation\Core\Application - Returns the application instance to use.
Default implementation returns
new \App\Application(). Use this only if you really need tochange application behavior, or use a different application class based on environment or HMVC module.Arguments passed toresolve()are not forwarded to this method.
Example:
Custom application resolution.
return match (true) {
Runtime::isCommand() => new App\CliApplication(),
Runtime::isHmvc() => new App\HttpHmvcApplication(),
default => new App\HttpApplication(),
};getRoutingSystem
Resolve and return the application's routing system.
Override this method to provide a custom routing implementation. The returned router must implement Luminova\Interface\RouterInterface.
The application instance is passed to the routing system constructor so the router can access the application's runtime configuration.
public function getRoutingSystem(Luminova\Foundation\Core\Application $app): Luminova\Interface\RouterInterfaceParameters:
| Parameter | Type | Description |
|---|---|---|
$app | Application | The application instance passed to the routing system constructor. |
Return Value:
Luminova\Interface\RouterInterface - Returns the application's routing system.
Default implementation returns
new Luminova\Routing\Router($app).
getSessionClient
Resolve and return the application's session client.
Override this method to provide a custom session implementation. The returned client must implement Luminova\Interface\SessionInterface.
public function getSessionClient(mixed ...$arguments): Luminova\Interface\SessionInterfaceParameters:
| Parameter | Type | Description |
|---|---|---|
...$arguments | mixed | Arguments passed to the session client constructor. |
Return Value:
Luminova\Interface\SessionInterface - Returns the application's session client.
Default implementation returns
new Luminova\Sessions\Session(...$arguments).
Example:
Custom session resolution.
$session = new Session(...$arguments);
match ($request->getPrefix()) {
'admin' => $session->setStorage('admin'),
default => $session->setStorage('users'),
};
return $session;getLogger
Resolve and return the application's preferred logger.
Override this method to provide a custom logger implementation. The returned logger must implement PSR's Psr\Log\LoggerInterface.
public function getLogger(mixed ...$arguments): Psr\Log\LoggerInterfaceParameters:
| Parameter | Type | Description |
|---|---|---|
...$arguments | mixed | Arguments passed to the logger constructor. |
Return Value:
Psr\Log\LoggerInterface - Returns the application's logger instance.
Default implementation returns
new Luminova\Logger\NovaLogger(...$arguments).
Example:
Custom logger.
return new MonoLogger($config);getMailer
Resolve and return the application's preferred mailer.
Override this method to provide a custom mailer implementation. The returned mailer must implement Luminova\Interface\MailerInterface.
Built-in mailer implementations include:
Luminova\Components\Email\Clients\PHPMailerLuminova\Components\Email\Clients\SwiftMailerLuminova\Email\Clients\NovaMailer(default)
public function getMailer(mixed ...$arguments): Luminova\Interface\MailerInterfaceParameters:
| Parameter | Type | Description |
|---|---|---|
...$arguments | mixed | Arguments passed to the mailer constructor. |
Return Value:
Luminova\Interface\MailerInterface - Returns the application's mailer instance.
Examples:
Using PHPMailer.
return new PHPMailer($config);Using SwiftMailer.
return new SwiftMailer($config);Using a custom mailer.
return new MyMailer($config);getHttpClient
Resolve and return the application's HTTP client.
Override this method to provide a custom HTTP client implementation. The returned client must implement the PSR Psr\Http\Client\ClientInterface.
Built-in Luminova HTTP clients include:
Luminova\Http\Client\Novio— default client.Luminova\Http\Client\Guzzle.
public function getHttpClient(mixed ...$arguments): Psr\Http\Client\ClientInterfaceParameters:
| Parameter | Type | Description |
|---|---|---|
...$arguments | mixed | Arguments passed to the HTTP client constructor. |
Return Value:
Psr\Http\Client\ClientInterface - Returns the application's HTTP client instance.
The HTTP client is not shared by default because its implementation may maintain request-specific state or configuration.
getCacheProvider
Create and configure the application cache provider.
The method acts as a factory for cache implementations and resolves the appropriate driver implementation at runtime. The cache provider must extend Luminova\Base\Cache.
When $driver is null, the driver is loaded from the system.cache.driver environment setting and defaults to filecache. The driver name is trimmed before matching.
Supported drivers:
filecache→Luminova\Cache\FileCache(file-based storage)memcached→Luminova\Cache\MemoryCache(Memcached-based storage)redis→Luminova\Cache\RedisCache(Redis-based storage)
The storage namespace and persistent connection identifier are passed directly to the selected cache implementation. Before being returned, the cache provider has PHP's automatic serialization disabled (SERIALIZER_PHP_AUTO set to false).
public function getCacheProvider(
?string $driver = null,
?string $storage = null,
?string $persistentId = null,
string $context = 'global'
): ?Luminova\Base\CacheParameters:
| Parameter | Type | Description |
|---|---|---|
$driver | string|null | Cache driver name, or null to use the configured default (default: null). |
$storage | string|null | Storage namespace or identifier (default: null). |
$persistentId | string|null | Persistent connection identifier (default: null). |
$context | string | Logical cache context (e.g. orm, global). Accepted for custom implementations, the default implementation does not use it (default: global). |
Return Value:
Luminova\Base\Cache|null - Returns a cache driver instance, or null if the driver is unsupported.
Examples:
Basic usage.
$cache = Kernel::resolve(
service: 'cache',
shared: true,
// getCacheProvider params
driver: 'redis',
storage: 'storage',
persistentId: 'persistent-id',
context: 'global'
);Note:The
cacheservice is shared by default. Useshared: falseto create a separate cache provider with different arguments.
getMemcached
Create and configure a Memcached client instance.
Returns null when the Memcached extension is unavailable. The client supports optional persistent connections, a post-creation callback, and a logical identifier for grouping or distinguishing connections.
The following options are applied:
OPT_LIBKETAMA_COMPATIBLE— enabled for consistent hashingOPT_BINARY_PROTOCOL— enabledOPT_TCP_NODELAY— enabledOPT_CONNECT_TIMEOUT— frommemcached.connect.timeout(default:1000)OPT_RETRY_TIMEOUT— frommemcached.retry.timeout(default:2)OPT_SERVER_FAILURE_LIMIT— frommemcached.server.failure.limit(default:5)OPT_REMOVE_FAILED_SERVERS— enabledOPT_PREFIX_KEY— optional, frommemcached.key.prefixwhen set
Server connection settings are loaded from the environment:
memcached.host— default:127.0.0.1memcached.port— default:11211memcached.weight— default:0
public function getMemcached(
?string $persistentId = null,
?callable $onNewObject = null,
string $identifier = ''
): ?MemcachedParameters:
| Parameter | Type | Description |
|---|---|---|
$persistentId | string|null | Persistent connection ID for connection reuse (default: null). |
$onNewObject | callable|null | Optional callback executed when a new instance is created (default: null). |
$identifier | string | Logical connection identifier or context key (default: ''). |
Return Value:
Memcached|null - Returns a configured Memcached instance, or null if the Memcached extension is unavailable.
getRedis
Create and configure a Redis client instance.
Returns null when the Redis extension is unavailable. The client supports both regular and persistent connections, selected by the presence of a persistent connection identifier.
Connection and client settings are loaded from the environment:
redis.host— default:127.0.0.1redis.port— default:6379redis.timeout— default:0redis.password— optional authentication passwordredis.database— default:0redis.key.prefix— optional key prefix, falls back to$identifierwhen not configured
When $persistentId is provided (not null or empty), a persistent Redis connection is created using that identifier. Otherwise, a regular connection is established. After connecting, the password is authenticated when set, the configured database is selected, and the key prefix is applied when not empty. The $onNewObject callback is invoked last, after the connection has been established and all configured Redis options have been applied.
public function getRedis(
?string $persistentId = null,
?callable $onNewObject = null,
string $identifier = ''
): ?RedisParameters:
| Parameter | Type | Description |
|---|---|---|
$persistentId | string|null | Optional persistent connection identifier used to reuse an existing Redis connection (default: null). |
$onNewObject | callable|null | Optional callback executed after a new Redis instance has been connected and configured (default: null). |
$identifier | string | Optional connection identifier or context key (default: ''). |
Return Value:
Redis|null - Returns a configured Redis instance, or null when the Redis extension is unavailable.
Throws:
Luminova\Exceptions\RuntimeException- If the connection to the Redis server fails.Luminova\Exceptions\RuntimeException- If Redis password authentication fails.
getApplicationKeys
Get the current and previous application encryption keys.
The current key (app.key) is returned first, followed by previously configured keys from app.keys. Previous keys allow data encrypted with an older application key to remain decryptable after key rotation. Empty or whitespace-only entries in app.keys are skipped.
public static function getApplicationKeys(): arrayReturn Value:
array<int,string> - Returns application encryption keys ordered from newest to oldest.
Example:
$keys = Kernel::getApplicationKeys();
// Or via the service resolver.
$keys = Kernel::resolve(Kernel::SERVICE_APP_KEYS);getCacheId
Generate a cache identifier for the current request.
Creates a normalized cache key from the request method (CLI when unavailable) and URI. The URI may optionally include query parameters, and known static file extensions are removed so the same resource does not produce duplicate cache entries (e.g. .html). The characters / ? & = # and spaces are replaced with :.
The identifier can be returned as either a raw key or an XXH3 hash (falls back to md5 when xxh3 is unavailable).
public static function getCacheId(
?string $prefix = null,
?bool $withUriQuery = null,
bool $hashValue = true
): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$prefix | string|null | Optional prefix to prepend to the generated key (default: null). |
$withUriQuery | bool|null | Whether to include query parameters in the key. When null, the value is read from page.cache.query.params in the environment, defaulting to false. |
$hashValue | bool | Whether to return the generated key as an XXH3 hash (default: true). |
Return Value:
string - Returns the generated cache identifier or its hash.
Examples:
$cacheId = Kernel::getCacheId();
$cacheIdWithoutQuery = Kernel::getCacheId(
withUriQuery: false
);
$rawCacheId = Kernel::getCacheId(
hashValue: false
);
$userCacheId = Kernel::getCacheId(
prefix: 'user-1',
hashValue: true
);Protected Methods
These methods are available to your App\Kernel class for delegating to the framework's built-in service handling. They are final and cannot be overridden.
resolveServiceName
Resolve a service alias or interface/class name to its canonical service name.
Known aliases and service class names are mapped to the identifier used by the service container. Unknown names are returned unchanged after surrounding whitespace has been removed.
protected static final function resolveServiceName(string $service): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service alias, interface, or class name. |
Return Value:
string - Returns the canonical service name, or the trimmed input when no known mapping exists.
isDefaultService
Determine whether a service identifier maps to a built-in kernel service.
Built-in services are all SERVICE_* constants, including cache.id and app.keys.
protected final static function isDefaultService(string $service): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service identifier or class/interface name. |
Return Value:
bool - Returns true if the service is a built-in kernel service, otherwise false.
getDefaultService
Resolve a built-in kernel service.
The identifier is normalized, then dispatched to the matching factory method: getHttpClient(), getLogger(), getMailer(), getSessionClient(), getRoutingSystem(), getApplication(), getMemcached(), getRedis(), getCacheProvider(), getCacheId() or getApplicationKeys(). Overriding any of these factory methods changes what the service resolves to.
protected final function getDefaultService(string $service, mixed ...$arguments): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service identifier or class/interface name. |
...$arguments | mixed | Arguments passed to the factory method. Not forwarded to getApplication() and getApplicationKeys(). |
Return Value:
mixed - Returns the resolved service, or null when the identifier is not a built-in service.
shouldShareDefaultService
Determine whether a built-in service should be shared.
| Service | Shared |
|---|---|
logger, mailer, session, routing, application, memcached, redis, cache | Yes |
http.client, cache.id, app.keys | No |
| Unknown or custom services | No |
protected final static function shouldShareDefaultService(string $service): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$service | string | The service identifier or class/interface name. |
Return Value:
bool - Returns true if the built-in service should be shared, otherwise false.