Documentation

Factories
in package

Factories for creating instances.

Factories allows dynamic loading of components by their path and name. The "shared instance" implementation provides a large performance boost and helps keep code clean of lengthy instantiation checks.

Table of Contents

$basenames  : array<string, array<string|int, string>>
Mapping of class basenames (no namespace) to their instances.
$instances  : array<string, array<string|int, mixed>>
Store for instances of any component that has been requested as "shared".
$options  : array<string, array<string|int, mixed>>
Store of component-specific options, usually from CodeIgniter\Config\Factory.
$configOptions  : array<string, mixed>
Explicit options for the Config component to prevent logic loops.
__callStatic()  : mixed
Loads instances based on the method component name. Either creates a new instance or returns an existing shared instance.
config()  :
getBasename()  : string
Gets a basename from a class name, namespaced or not.
getOptions()  : array<string, mixed>
Returns the component-specific configuration
injectMock()  : mixed
Helper method for injecting mock instances
models()  :
reset()  : mixed
Resets the static arrays, optionally just for one component
setOptions()  : array<string, mixed>
Normalizes, stores, and returns the configuration for a specific component
locateClass()  : string|null
Finds a component class
verifyInstanceOf()  : bool
Verifies that a class & config satisfy the "instanceOf" option
verifyPreferApp()  : bool
Verifies that a class & config satisfy the "preferApp" option

Properties

$basenames

Mapping of class basenames (no namespace) to their instances.

protected static array<string, array<string|int, string>> $basenames = []

$instances

Store for instances of any component that has been requested as "shared".

protected static array<string, array<string|int, mixed>> $instances = []

A multi-dimensional array with components as keys to the array of name-indexed instances.

$options

Store of component-specific options, usually from CodeIgniter\Config\Factory.

protected static array<string, array<string|int, mixed>> $options = []

$configOptions

Explicit options for the Config component to prevent logic loops.

private static array<string, mixed> $configOptions = ['component' => 'config', 'path' => 'Config', 'instanceOf' => null, 'getShared' => true, 'preferApp' => true]

Methods

__callStatic()

Loads instances based on the method component name. Either creates a new instance or returns an existing shared instance.

public static __callStatic(string $component, array<string|int, mixed> $arguments) : mixed
Parameters
$component : string
$arguments : array<string|int, mixed>
Return values
mixed

config()

public static config(mixed $arguments) :
Parameters
$arguments : mixed
Return values

getBasename()

Gets a basename from a class name, namespaced or not.

public static getBasename(string $name) : string
Parameters
$name : string
Return values
string

getOptions()

Returns the component-specific configuration

public static getOptions(string $component) : array<string, mixed>
Parameters
$component : string

Lowercase, plural component name

Return values
array<string, mixed>

injectMock()

Helper method for injecting mock instances

public static injectMock(string $component, string $name, object $instance) : mixed
Parameters
$component : string

Lowercase, plural component name

$name : string

The name of the instance

$instance : object
Return values
mixed

models()

public static models(mixed $arguments) :
Parameters
$arguments : mixed
Return values

reset()

Resets the static arrays, optionally just for one component

public static reset([string $component = null ]) : mixed
Parameters
$component : string = null

Lowercase, plural component name

Return values
mixed

setOptions()

Normalizes, stores, and returns the configuration for a specific component

public static setOptions(string $component, array<string|int, mixed> $values) : array<string, mixed>
Parameters
$component : string

Lowercase, plural component name

$values : array<string|int, mixed>
Return values
array<string, mixed>

The result after applying defaults and normalization

locateClass()

Finds a component class

protected static locateClass(array<string|int, mixed> $options, string $name) : string|null
Parameters
$options : array<string|int, mixed>

The array of component-specific directives

$name : string

Class name, namespace optional

Return values
string|null

verifyInstanceOf()

Verifies that a class & config satisfy the "instanceOf" option

protected static verifyInstanceOf(array<string|int, mixed> $options, string $name) : bool
Parameters
$options : array<string|int, mixed>

The array of component-specific directives

$name : string

Class name, namespace optional

Return values
bool

verifyPreferApp()

Verifies that a class & config satisfy the "preferApp" option

protected static verifyPreferApp(array<string|int, mixed> $options, string $name) : bool
Parameters
$options : array<string|int, mixed>

The array of component-specific directives

$name : string

Class name, namespace optional

Return values
bool

Search results