Luminova Framework

PHP Luminova: Services Layer Autoloading Configurations

Last updated: 2024-08-28 21:24:52

Register and autoload services that should be discoverable throughout your application.

The Service Configuration class allows you to register services to be autoloaded and discoverable anywhere in your application. It allows you specify initialization arguments, and optionally specify whether the class instance should be shared, and whether it should be serialized and stored as cache.



ToDo

Enable the service feature by setting feature.app.services = enable in your environment configuration file.


Methods

To get started with service usages and method read the Application Service Guide.

bootstrap

Register services to autoload and make them discoverable.

public bootstrap(): void

To register a classes, use the static newService method available in CoreServices within the bootstrap method as shown below.

Do not create a duplicate of the bootstrap method or the Service class. To register multiple classes, simply add each class in a new line within the bootstrap method using newService.

Example

<?php
namespace App\Config;

use Luminova\Base\CoreServices;
use App\Utils\YourServiceClassName;

class Services extends CoreServices
{
    public function bootstrap(): void
    {
        static::newService(
            YourServiceClassName::class, // Class name to register.
            null, // Class name alias (defaults to the class basename if null).
            true, // Should return shared instance.
            true, // Should serialize and store the class object.
            [ // Initialization arguments, must be array list (int keys)
                'foo', 
                'bar', 
                true, 
                new fooClass(), 
                ['my', 'key' => 'array']
            ]
        );
        //...
    }
}