Installing and Configuring Lumina
This guide will walk you through the process of installing and configuring Lumina using Composer and setting up the container and routes.
Installation via Composer
Install Lumina using the following Composer command:
composer create-project auroralumina/lumina app
This command will create a new directory called app
with the Lumina application installed.
Configuring the Container
After installation, you'll find configuration files in the app/
directory. The bootstrap.php
file is responsible for initializing the Lumina container.
The container.php
file in the infrastructure/
directory registers the application's dependencies with the container. In this example, the HelloService
service is registered.
<?php
use App\Services\HelloService;
use AuroraLumina\Interface\ContainerInterface;
return function (ContainerInterface $container)
{
$container->bindScoped(HelloService::class);
};
The bindScoped
method is used to register a service that should be created as a singleton. This means that only one instance of the HelloService
class will be created and shared throughout the application.
Configuring Routes
The routes.php
file in the infrastructure/
directory defines the application's routes. In this example, two routes are defined: one for /hello/{name}
and another for /hello/2/{name}
.
<?php
use App\Services\HelloService;
use App\Controllers\HelloController;
use AuroraLumina\Request\ServerRequest;
use AuroraLumina\Request\RequestArguments;
use AuroraLumina\Interface\RouterInterface;
return function (RouterInterface $route)
{
$route->get('/hello/controller/{name}', [HelloController::class, 'index']);
$route->get('/hello/{name}', function(ServerRequest $request, RequestArguments $args, HelloService $helloService)
{
$name = $args->name;
$hourMinute = $helloService->hourMinute();
return ['name' => $name, 'hourMinute' => $hourMinute];
});
};
The get
method is used to define a new route that responds to HTTP GET requests. The first argument is the route pattern, and the second argument is a closure that defines the response.
In this example, the HomeController
class is used to handle the response for the /hello/{name}
route. The HelloService
service is injected into the closure for the /hello/2/{name}
route.
Running the Application
To run the application, add the following code to the public/index.php
file:
<?php
require __DIR__ . '/../vendor/autoload.php';
(require_once __DIR__. '/../app/bootstrap.php')->run(false);
Now, your Lumina application is configured and ready to run. Make sure your web server is configured correctly to serve files from the public/
directory.
INFO
Note that Lumina comes with pre-defined scripts to facilitate initial project setup. Feel free to modify these scripts according to your project's needs.
Directory Structure
Here is the directory structure for a Lumina application:
├─ app
│ ├─ controllers
│ └─ services
├─ infrastructure
│ ├─ container.php
│ └─ routes.php
└─ public
└─ index.php
The app/
directory contains the application's business logic, including controllers and services. The infrastructure/
directory contains configuration files, such as the container and routes. The public/
directory contains the entry point for the application, index.php
.