PHP Luminova: Application Factory Modules Management
Create or reuse framework objects by their registered factory names.
Factory is a utility class in the Luminova framework designed to simplify the management of class instances across the Luminova codebase. It serves as a centralized hub, allowing the management of shared instances of classes throughout the framework.
Unlike the Services utility, Factory does not require configuration or registering classes. Class registration is defined within the Factory class and ready to be initialized when needed. Additionally, Factory does not support initializing classes by fully qualified class name (e.g., SomeClass::class), you must initialize using the predefine names.
Usages
To dynamically create an instance of a factory class, you can use the Factory::methodName().
use Luminova\Foundation\Module\Factory;
$instance = Factory::cookie('foo', 'foo-value', [], true);Global Helper Function
Additionally, there is a namespaced helper function Luminova\Funcs\factory() available, which provides a convenient way to access factory instances.
use function Luminova\Funcs\factory;
$instance = factory('cookie', true, 'foo', 'foo-value', []);Class Definition
- Full namespace:
Luminova\Foundation\Module\Factory - This class is final.
Methods
has
Check if class is available in factories
public static function has(string $factory): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$factory | string | The factory name. |
Return:
bool - Returns true if the name is registered in the factory map.
delete
Delete a shared instance of factory class.
public static function delete(string $factory): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$factory | string | The factory name. |
Return:bool - Return true if shared instance was deleted, false otherwise.
clear
Clear all shared instance of factory.
public static function clear(): voidFor the application logger and HTTP client, see the service kernel. For other application services, see Service instances.
service
Return shared service class instance.
public static function service(): ServiceReturn:
Luminova\Foundation\Module\Service - Return instance of service class
Factory Names
The following dynamic calls forward their constructor arguments to the indicated class. A direct call uses an optional trailing boolean for sharing. The factory() helper takes the sharing flag before constructor arguments.
session
Server-side user session class.
public static function session(?Luminova\Interface\SessionManagerInterface $manager = null, bool $shared = true): Luminova\Sessions\SessionParameters:
| Parameter | Type | Description |
|---|---|---|
$params | SessionManagerInterface|null | Session storage interface. |
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Session - Instance of the server-side user session class.
cookie
Client-side cookie class.
public static function cookie(string $name, mixed $value = '', CookieConfig|array $options = [], bool $shared = true): Luminova\Cookies\CookieParameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | Cookie name. |
$value | string | Cookie value. |
$options | array<array-key, mixed> | Optional cookie options. |
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Cookie - Instance of the client-side cookie class.
task
Time task utility class.
public static function task(bool $shared = true): Luminova\Time\TaskParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Task - Instance of the time task utility class.
language
Application translation class.
public static function language(?string $locale = null, bool $shared = true): Luminova\Components\Languages\TranslatorParameters:
| Parameter | Type | Description |
|---|---|---|
$locale | string|null | Locale for translation. |
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Translator - Instance of the application translation class.
filesystem
File manager class.
public static function filesystem(bool $shared = true): Luminova\Storage\FilesystemParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
FileManager - Instance of the file manager class.
validate
Input validation class.
public static function validate(bool $shared = true): Luminova\Security\ValidationParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Validation - Instance of the input validation class.
response
Render response class.
public static function response(string|array|object|null $content = null, int $status = 200, array $headers = [], bool $shared = true): Luminova\Template\ResponseParameters:
| Parameter | Type | Description |
|---|---|---|
$content | string|array<array-key, mixed>|object|null | Optional response content (default null). |
$status | int | HTTP response status code (default 200). |
$headers | array<string, mixed> | Response header map (default []). |
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Response - Instance of the render response class.
request
HTTP Request class.
public static function request(bool $shared = true): Luminova\Http\RequestParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Request - Instance of the HTTP Request class.
caller
This method can be used to call all methods withing a giving class class or list all extenders.
public static function caller(bool $shared = true): Luminova\Foundation\Module\CallerParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Caller - Instance of the Caller class.
Other factory names
| Name | Class | Constructor arguments |
|---|---|---|
escaper | Luminova\Security\Escaper | Optional encoding, default utf-8. |
renderer, fileResponse | Luminova\Storage\Renderer | Storage directory, then optional ETag and weak ETag flags. |
notification | Luminova\Notifications\Firebase\Notification | Optional service account configuration, default ServiceAccount.json. |