Luminova Framework

Factories

Last updated: 2024-07-25 20:16:33

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): bool

Parameters:

ParameterTypeDescription
$factorystringThe 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): bool

Parameters:

ParameterTypeDescription
$factorystringThe factory name.

Return Value:bool - Return true if shared instance was deleted, false otherwise.


clear

Clear all shared instance of factory.

public static clear(): void

Class Instance Methods

service

Return shared service class instance.

public static service(): \Luminova\Application\Services

Return Value:

\Luminova\Application\Services - Return instance of service class


functions

Utility function helper class.

public static functions(bool $shared = true): \Luminova\Application\Functions

Parameters:

ParameterTypeDescription
$sharedboolWhether 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\Session

Parameters:

ParameterTypeDescription
$params\Luminova\Interface\SessionManagerInterface|nullSession storage interface.
$sharedboolWhether to return a shared instance. Default is true.

Return Value

Session - Instance of the server-side user session class.


Client-side cookie class.

public static cookie(string $name, mixed $value = '', array $options = [], bool $shared = true): \Luminova\Cookies\Cookie

Parameters:

ParameterTypeDescription
$namestringCookie name.
$valuestringCookie value.
$optionsarrayOptional cookie options.
$sharedboolWhether 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\Task

Parameters:

ParameterTypeDescription
$sharedboolWhether 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\Modules

Parameters:

ParameterTypeDescription
$sharedboolWhether 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\Translator

Parameters:

ParameterTypeDescription
$localestring|nullLocale for translation.
$sharedboolWhether 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\LoggerInterface

Parameters:

ParameterTypeDescription
$sharedboolWhether 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\FileManager

Parameters:

ParameterTypeDescription
$sharedboolWhether 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\Validation

Parameters:

ParameterTypeDescription
$sharedboolWhether 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\Response

Parameters:

ParameterTypeDescription
$statusintHTTP response status code. Default is 200.
$sharedboolWhether 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\Request

Parameters:

ParameterTypeDescription
$sharedboolWhether 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\NetworkInterface

Parameters:

ParameterTypeDescription
$clientHttpClientInterface|nullHTTP client instance.
$sharedboolWhether 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\Caller

Parameters:

ParameterTypeDescription
$sharedboolWhether to return a shared instance. Default is true.

Return Value

Caller - Instance of the Caller class.