PHP Luminova: Management of Core Factory Classes
Factory is Luminova's utility class that provides class instance management without the need for class registration or configuration. However, you must initialize classes using predefined 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().
<?php
use \Luminova\Application\Factory;
$instance = Factory::cookie('foo', 'foo-value', [], true);Global Helper Function
Additionally, there is a global helper function factory() available, which provides a convenient way to access factory instances.
<?php
$instance = factory('cookie', 'foo', 'foo-value', [], true);- Class namespace:
\Luminova\Application\Factory
Methods
has
Check if class is available in factories
public static has(string $factory): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$factory | string | The factory name. |
Return Value:
bool - Return true if class is available in factories, false otherwise.
delete
Delete a shared instance of factory class.
public static delete(string $factory): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$factory | string | The factory name. |
Return Value:bool - Return true if shared instance was deleted, false otherwise.
clear
Clear all shared instance of factory.
public static clear(): voidClass Instance Methods
service
Return shared service class instance.
public static service(): \Luminova\Application\ServicesReturn Value:
\Luminova\Application\Services - Return instance of service class
functions
Utility function helper class.
public static functions(bool $shared = true): \Luminova\Application\FunctionsParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Functions - Instance of the utility function helper class.
session
Server-side user session class.
public static session(?\Luminova\Interface\SessionManagerInterface $manager = null, bool $shared = true): \Luminova\Sessions\SessionParameters:
| Parameter | Type | Description |
|---|---|---|
$params | \Luminova\Interface\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 cookie(string $name, mixed $value = '', array $options = [], bool $shared = true): \Luminova\Cookies\CookieParameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | Cookie name. |
$value | string | Cookie value. |
$options | array | 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 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.
modules
PSR-4 Module autoloader and file importer class.
public static modules(bool $shared = true): \Luminova\Library\ModulesParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Modules - Instance of the PSR-4 Module autoloader and file importer class.
language
Application translation class.
public static language(?string $locale = null, bool $shared = true): \Luminova\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.
logger
PSR logger class.
public static logger(bool $shared = true): \Psr\Log\LoggerInterfaceParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
LoggerInterface - Instance of the PSR logger class.
fileManager
File manager class.
public static fileManager(bool $shared = true): \Luminova\Storages\FileManagerParameters:
| 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 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 response(int $status = 200, bool $shared = true): \Luminova\Template\ResponseParameters:
| Parameter | Type | Description |
|---|---|---|
$status | int | HTTP response status code. Default is 200. |
$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 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.
network
HTTP Network request class.
public static network(?Luminova\Interface\HttpClientInterface $client = null, bool $shared = true): Luminova\Interface\NetworkInterfaceParameters:
| Parameter | Type | Description |
|---|---|---|
$client | HttpClientInterface|null | HTTP client instance. |
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
NetworkInterface - Instance of the HTTP Network request class.
caller
This method can be used to call all methods withing a giving class class or list all extenders.
public static caller(bool $shared = true): \Luminova\Application\CallerParameters:
| Parameter | Type | Description |
|---|---|---|
$shared | bool | Whether to return a shared instance. Default is true. |
Return Value
Caller - Instance of the Caller class.