PHP Luminova: Custom Service Registry
Register reusable application objects and retrieve shared or fresh instances by name.
Use Luminova\Foundation\Module\Service for application services that need a shared instance or a serialized copy. The registry uses the class basename as the service name. The Service API reference describes registration, lookup, and removal.
Examples
Service Registration
For programmatic registration, add the service before the first lookup. Pass an already constructed object to provide its dependencies at registration time.
use App\Utils\YourServiceClassName;
use Luminova\Foundation\Module\Service;
use function Luminova\Funcs\service;
Service::add(new YourServiceClassName('param1', 'param2'));
$instance = service('YourServiceClassName');The two optional flags at the end of a Service::add() call are serialization followed by sharing. Sharing defaults to true and serialization defaults to false. When serialization is enabled, the service is also shared.
Reinitialization
Supply the registered class’s constructor arguments after the sharing and serialization flags in service(). Set both flags to false to create a fresh object without replacing the shared instance.
use function Luminova\Funcs\service;
$fresh = service('YourServiceClassName', false, false, 'new1', 'new2');The static lookup form takes the constructor arguments first, followed by the serialization and sharing flags.
use Luminova\Foundation\Module\Service;
$fresh = Service::YourServiceClassName('new1', 'new2', false, false);