Luminova Framework

PHP Luminova: Application Service Kernel

Last updated: 2025-12-29 00:21:19

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 a lightweight kernel used to bootstrap core services in a Luminova application.

It does not handle requests, routing, middleware, or application flow.Its only job is to define which core services the framework should use at boot time.

When a service is not provided by the Kernel, Luminova automatically falls back to its default implementation.


Purpose

The Kernel exists to:

  • Provide core framework services (logger, cache, session, mailer, HTTP client)
  • Allow replacing defaults with application-specific or environment-dependent implementations
  • Serve as a single, predictable entry point for system configuration

Kernel Contract

Every application defines one kernel class, at:

/app/Kernel.php

The class must implement:

Luminova\Interface\ServiceKernelInterface

Example

Define Kernel Class

Defines the core contract for an application kernel.

// /app/Kernel.php

namespace App;

use Monolog\Level;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Monolog\Handler\StreamHandler;
use Luminova\Interface\ServiceKernelInterface;

final class Kernel implements ServiceKernelInterface
{
    /**
     * Initialize the kernel.
     */
    public static function create(bool $shared): static
    {
        if (!$shared) {
            return new self();
        }

        if (!self::$instance instanceof self) {
            self::$shared = new self();
        }

        return self::$shared;
    }

    /**
     * Whether to reuse a kernel instance.
     */
    public static function shouldShareObject(): bool
    {
        return true;
    }

    /**
     * Provide application logger.
     */
    public function getLogger(): ?LoggerInterface
    {
        $logger = new Logger('my_app_channel');
        $logger->pushHandler(
            new StreamHandler(root('/writeable/logs/', 'app.log'), Level::Debug)
        );

        return $logger;
    }

    // Implement other required methods
}

Note:

This kernel is discovered and initialized automatically during the framework boot process.Extend this class once as app/Kernel.php.


Accessing Kernel Methods

The Kernel is automatically resolved during the framework boot process.

Manual Initialization

use App\Kernel;

$kernel = Kernel::create();
$application = $kernel->getApplication();

Using Service Class (Recommended)

The preferred way is via the Luminova\Luminova Class, which automatically resolves the Kernel and handles shared instances.

use Luminova\Luminova;

// Get application logger
$logger = Luminova::kernel(notShared: false)->getLogger();
$logger->info('User logged in successfully');

// Get application HTTP client
$client = Luminova::kernel(notShared: false)->getHttpClient([...]);
$response = $client->request('GET', 'https://example.com', [...]);

Class Definition


Methods

create

Create a kernel instance.

This static factory method is called by Luminova to create the kernel instance.

  • When $shared is true, the kernel may return a shared instance
  • When $shared is false, the kernel must return a new instance

This gives the application full control over kernel reuse.

Typical use cases for shared kernels:

  • Shared configuration
  • Shared service instances
  • Reduced initialization cost
public static create(bool $shared): ServiceKernelInterface;

Parameters:

ParameterTypeDescription
$sharedboolWhether the kernel is intended to be shared.

Return Value:

Luminova\Interface\ServiceKernelInterface - Returns shared or new kernel instance.

Note:This method is used by Luminova to initialize and create kernel object.


shouldShareObject

Defines whether the kernel should share a single application object.

  • Returning true allows Luminova to reuse the same kernel instance
  • Returning false forces a new kernel instance on each request or context

Default behavior is to share the kernel.

public static shouldShareObject(): bool

Return Value:

bool - Returns true to share object, false otherwise.


getRoutingSystem

Get the routing system instance.

Override this method if your application provides a custom router.Returning null instructs the framework to use the default router.

public getRoutingSystem(): ?Luminova\Interface\RouterInterface

Return Value:

Luminova\Interface\RouterInterface|null - Returns the routing system instance, or null for the default.


getApplication

Allows using a custom Application class.

Override this method to using a custom Application class.Or null to allow Luminova create use the default.

public getApplication(): ?Luminova\Foundation\Core\Application

Return Value:

Luminova\Foundation\Core\Application|null - Returns the application instance, or null for the default.

Use this only if you really need to change application behavioror use different application based on environment or HMVC module


getLogger

Get the preferred logger instance.

The returned logger must implement PSR's LoggerInterface.Returning null instructs the framework to fall back to its default logger.

public getLogger(): ?Psr\Log\LoggerInterface

Return Value:

Psr\Log\LoggerInterface|null - Returns the logger instance, or null for the default.


getMailer

Get the mail client to use for the application.

The mailer must implement Psr\Mail\MailerInterface.

You may return either:

  • an instance of the mailer,

  • a class name implementing the mailer,

  • or null to use the default mailer.

  • You can use built-in clients like:

    • Luminova\Components\Email\Clients\PHPMailer
    • Luminova\Components\Email\Clients\SwiftMailer
public getMailer(): Luminova\Interface\MailerInterface|class-string<Luminova\Interface\MailerInterface>|null

Return Value:

Luminova\Interface\MailerInterface|class-string<\Luminova\Interface\MailerInterface>|null - Returns a mailer, instance, a mailer fully qualified name, or null for the default mailer.


getHttpClient

Return the HTTP client used for outbound requests.

If null is returned, the default Luminova Novio client is used.Custom clients must implement the PSR ClientInterface.

Luminova clients:

  • \Luminova\Http\Client\Novio (default)
  • \Luminova\Http\Client\Guzzle
public getHttpClient(array $config = []): Psr\Http\Client\ClientInterface|string|null

Parameters:

ParameterTypeDescription
$configarrayOptional configuration options for the HTTP client.

Return Value:

Psr\Http\Client\ClientInterface|string|null - Returns a client instance, a client class name, or null to use the default.


getCacheProvider

Get the cache provider for the application.

The cache provider must extend Luminova\Base\Cache.You may return either:

  • an instance of the cache provider,
  • a class name implementing the cache provider,
  • or null to use the default cache provider.
public getCacheProvider(): Luminova\Base\Cache|class-string<Luminova\Base\Cache>|null

Return Value:

Luminova\Base\Cache|class-string<\Luminova\Base\Cache>|null - Returns a cache provider instance, a cache provider fully qualified name, or null for the default cache provider.


getSessionHandler

Get the session handler for the application.

The session handler must extend Luminova\Base\SessionHandler.You may return either:

  • an instance of the session handler,
  • a class name implementing the session handler,
  • or null to use the default session handler.
public getSessionHandler(): Luminova\Base\SessionHandler|class-string<Luminova\Base\SessionHandler>|null

Return Value:

\Luminova\Base\SessionHandler|class-string<Luminova\Base\SessionHandler>|null - Returns a session handler instance, a session handler fully qualified name, or null for the default session handler.