Luminova Framework

PHP Luminova: Customization of Optional Features and Framework Behavior

Last updated: 2026-11-28 20:57:12

Configure optional Luminova features in your project’s `.env` file, including PHP attribute routing, dependency injection for route handlers, PSR-4 autoloading, class aliases, and custom global functions.

Use feature flags to choose how your Luminova application discovers routes, loads library classes and helper functions, and registers services at startup. Set the flags in your project’s .env file, then add the corresponding routes, class mappings, or service definitions where indicated below.


Configure Feature Flags

Use enable or true to turn a feature on and disable or false to turn it off. When adding an example mapping to an existing app/Config/Modules.php, keep the aliases and namespace mappings your project already uses.


PHP Attribute Routing

Set feature.route.attributes = enable to let Luminova discover routes from PHP attributes. Place #[Route] above the controller method that handles the request. In this example, the same method handles GET / and POST /. The class-level #[Error] attribute registers an error handler for matching web routes.

namespace App\Controllers\Http;

use Luminova\Base\Http\AbstractController;
use Luminova\Attributes\Route;
use Luminova\Attributes\Error;
use App\Errors\Controllers\AppError;

#[Error('web', pattern: '/.*', onError: [AppError::class, 'onTrigger'])]
class MyController extends AbstractController
{
    #[Route('/', methods: ['GET', 'POST'])]
    public function index(): int
    {
        return $this->view('index');
    }
}

Set feature.route.cache.attributes = enable to reuse cached route definitions. See HTTP route attributes and CLI command attributes for the two route types.


Class Aliases

Set feature.app.class.alias = enable and add your aliases to the alias array in app/Config/Modules.php. Use the alias as the array key and the fully qualified name of an autoloadable class as the value.

return [
    'alias' => [
        'Foo' => App\Utils\ExampleFoo::class,
    ],
    'psr-4' => [],
];

Usage Example

After bootstrap, use the alias Foo to instantiate App\Utils\ExampleFoo.

$foo = new \Foo();

Application Services

Set feature.app.services = enable to load your application’s service registrations during bootstrap. In app/Config/Services.php, add registrations to the existing bootstrap() method. For example, self::newService(ExampleClass::class) registers an imported class under its short name so you can retrieve it with service('ExampleClass').

For manual registration, use Luminova\Foundation\Module\Service::add(). This allows you to pass constructor dependencies yourself. Use a single registration method for each service.

use App\Utils\ExampleClass;
use Luminova\Foundation\Module\Service;
use function Luminova\Funcs\service;

Service::add(new ExampleClass());

$example = service('ExampleClass');

See Service registration for sharing and constructor options.


PSR-4 Autoloading

Set feature.app.autoload.psr4 = enable and add a namespace mapping to the psr-4 array in app/Config/Modules.php. The mapped directory is relative to libraries/libs/.

return [
    'alias' => [],
    'psr-4' => [
        'Example\Tools' => 'example/tools',
    ],
];

With this mapping, Luminova loads Example\Tools\Formatter from libraries/libs/example/tools/Formatter.php when your code first references the class. Declare namespace Example\Tools; in that file and match the case of the class and file names.

Single File Import

To load a particular file directly, use the import() helper. It works independently of the custom PSR-4 setting.

use function Luminova\Funcs\import;

import('libraries:libs/example/tools/Formatter.php');

Custom Global Functions

Set feature.app.dev.functions = enable to load app/Utils/Global.php during bootstrap. Add your application’s global helper functions to that file.

if (!function_exists('my_string_count')) {
    function my_string_count(string $string): int
    {
        return strlen($string);
    }
}

Dependency Injection

Set feature.route.dependency.injection = enable to let the router supply dependencies to controller methods and route closures. The following example uses method-based routing, which requires feature.route.attributes = disable. The router injects the incoming request and passes the captured URL segment as $token.

use Luminova\Interface\RequestInterface;
use Luminova\Routing\Router;
use function Luminova\Funcs\response;

Router::get('/users/token/([a-zA-Z0-9-]+)', static function (RequestInterface $request, string $token): int {
    return response()->json([
        'method' => $request->getMethod(),
        'tokenLength' => strlen($token),
    ]);
});

For a controller method, register UserController::showToken as the callback and declare the same parameters on the method. See Controller dependency injection for configuration, argument order, and custom bindings.