\Anax\DIDIFactoryConfig

DI factory class creating a set of default services by loading them from a configuration file.

Summary

Methods
Properties
Constants
configure()
getConfig()
get()
has()
set()
setShared()
getServices()
getActiveServices()
__construct()
No public properties found
No constants found
load()
createService()
$config
$loaded
$active
N/A
No private methods found
No private properties found
N/A

Properties

$config

$config : array<mixed,>

Type

array<mixed,> — store the configuration in this array.

$loaded

$loaded : array

Type

array — Store all lazy loaded services, ready to be instantiated.

$active

$active : 

Type

Methods

configure()

configure(array|string  $what) : self

Set a configuration object to use, this object have the ability to load configuration from an array or files.

Parameters

array|string $what

is an array with key/value config options or a file to be included which returns such an array.

Returns

self

getConfig()

getConfig(string  $key, string  $default = null) : mixed

Helper function for reading values from the configuration and appy default values where configuration item is missing.

Parameters

string $key

matching a key in the config array.

string $default

value returned when config item is not found.

Returns

mixed —

or null if key does not exists.

get()

get(string  $service) : mixed

Finds an entry in the container by its identifier and returns it.

If the service is active/singelton then that instance is returned, else the service is loaded and a new instance is returned.

Parameters

string $service

Identifier of the entry to look for.

Throws

\Anax\DI\Exception\NotFoundException

No entry was found for this identifier.

\Anax\DI\Exception\Exception

Error while retrieving the entry.

Returns

mixed —

Entry.

has()

has(string  $service) : boolean

Returns true if the container can return an entry for the given identifier, otherwise false

has($id) returning true does not mean that get($id) will not throw an exception. It does however mean that get($id) will not throw a NotFoundException.

Parameters

string $service

Identifier of the entry to look for.

Returns

boolean

set()

set(string  $service, mixed  $loader) : void

Set a service and connect it to a task which creates the object (lazy loading).

Parameters

string $service

as a service label, naming this service.

mixed $loader

contains a pre-defined object, a string with class name or an callable which returns an instance of the service object. Its the way to actually load, insantiate, the service object.

setShared()

setShared(string  $service, mixed  $loader) : void

Set a singleton service and connect it to a task which creates the object (lazy loading).

Parameters

string $service

as a service label, naming this service.

mixed $loader

contains a pre-defined object, a string with class name or an callable which returns an instance of the service object. Its the way to actually load, insantiate, the service object.

getServices()

getServices() : void

Return an arry with all loaded services names.

getActiveServices()

getActiveServices() : void

Return an arry with all active services names.

__construct()

__construct(array|string|null  $what = null) 

Constructor optionally creating a set of services from a configuration file.

Parameters

array|string|null $what

is an array with key/value config options or a file to be included which returns such an array.

load()

load(string  $service) : object

Load a prepared service object and create an instance of it.

Parameters

string $service

as a service label, naming this service.

Throws

\Anax\DI\Exception\Exception

when service could not be loaded.

Returns

object —

as instance of the service object.

createService()

createService(string  $name, array  $service) : self

Create a service from a name and an array containing details on how to create it.

Parameters

string $name

of service.

array $service

details to use when creating the service.

Returns

self