Locator
in package
implements
ArrayAccess, Countable, IteratorAggregate
Service locator class
Tags
Table of Contents
Interfaces
- ArrayAccess
- Countable
- IteratorAggregate
Properties
- $loaded : array<string|int, mixed>
- Services that are loaded/instantiated
- $services : array<string|int, mixed>
- Services
- $called : array<string|int, mixed>
- Recursion called service name tracker
- $depth : int
- Recursion depth level tracker
Methods
- __construct() : mixed
- Constructor
- __get() : mixed
- Get a service
- __isset() : bool
- Determine if a service is available
- __set() : void
- Set a service
- __unset() : void
- Unset a service
- addParam() : static
- Add to a service's parameters
- count() : int
- Return count
- get() : mixed
- Get/load a service
- getCall() : mixed
- Get a service's callable string or object
- getIterator() : ArrayIterator
- Get iterator
- getParams() : mixed
- Get a service's parameters
- hasParams() : bool
- Check if a service has parameters
- isAvailable() : bool
- Determine of a service object is available (but not loaded)
- isLoaded() : bool
- Determine of a service object is loaded
- offsetExists() : bool
- Determine if a service is available
- offsetGet() : mixed
- Get a service
- offsetSet() : void
- Set a service
- offsetUnset() : void
- Unset a service
- reload() : mixed
- Re-load a service object
- remove() : static
- Remove a service
- removeParam() : static
- Remove a service's parameters
- set() : static
- Set a service. It will overwrite any previous service with the same name.
- setCall() : static
- Set a service's callable string or object
- setParams() : static
- Set a service's parameters
- setServices() : static
- Set service objects from an array of services
Properties
$loaded
Services that are loaded/instantiated
protected
array<string|int, mixed>
$loaded
= []
$services
Services
protected
array<string|int, mixed>
$services
= []
$called
Recursion called service name tracker
private
static array<string|int, mixed>
$called
= []
$depth
Recursion depth level tracker
private
static int
$depth
= 0
Methods
__construct()
Constructor
public
__construct([array<string|int, mixed>|null $services = null ][, bool $default = true ]) : mixed
Instantiate the service locator object.
Parameters
- $services : array<string|int, mixed>|null = null
- $default : bool = true
Tags
__get()
Get a service
public
__get(string $name) : mixed
Parameters
- $name : string
Tags
__isset()
Determine if a service is available
public
__isset(string $name) : bool
Parameters
- $name : string
Return values
bool__set()
Set a service
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
Tags
__unset()
Unset a service
public
__unset(string $name) : void
Parameters
- $name : string
addParam()
Add to a service's parameters
public
addParam(string $name, mixed $param[, mixed $key = null ]) : static
Parameters
- $name : string
- $param : mixed
- $key : mixed = null
Return values
staticcount()
Return count
public
count() : int
Return values
intget()
Get/load a service
public
get(string $name) : mixed
Parameters
- $name : string
Tags
getCall()
Get a service's callable string or object
public
getCall(string $name) : mixed
Parameters
- $name : string
getIterator()
Get iterator
public
getIterator() : ArrayIterator
Return values
ArrayIteratorgetParams()
Get a service's parameters
public
getParams(string $name) : mixed
Parameters
- $name : string
hasParams()
Check if a service has parameters
public
hasParams(string $name) : bool
Parameters
- $name : string
Return values
boolisAvailable()
Determine of a service object is available (but not loaded)
public
isAvailable(string $name) : bool
Parameters
- $name : string
Return values
boolisLoaded()
Determine of a service object is loaded
public
isLoaded(string $name) : bool
Parameters
- $name : string
Return values
booloffsetExists()
Determine if a service is available
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
booloffsetGet()
Get a service
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
Tags
offsetSet()
Set a service
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
Tags
offsetUnset()
Unset a service
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
reload()
Re-load a service object
public
reload(string $name) : mixed
Parameters
- $name : string
remove()
Remove a service
public
remove(string $name) : static
Parameters
- $name : string
Return values
staticremoveParam()
Remove a service's parameters
public
removeParam(string $name, mixed $param[, mixed $key = null ]) : static
Parameters
- $name : string
- $param : mixed
- $key : mixed = null
Return values
staticset()
Set a service. It will overwrite any previous service with the same name.
public
set(string $name, mixed $service) : static
A service can be a CallableObject, callable string, or an array that contains a 'call' key and an optional 'params' key. Valid callable strings are:
'someFunction'
'SomeClass'
'SomeClass->foo'
'SomeClass::bar'
Parameters
- $name : string
- $service : mixed
Tags
Return values
staticsetCall()
Set a service's callable string or object
public
setCall(string $name, mixed $call) : static
Parameters
- $name : string
- $call : mixed
Return values
staticsetParams()
Set a service's parameters
public
setParams(string $name, mixed $params) : static
Parameters
- $name : string
- $params : mixed
Return values
staticsetServices()
Set service objects from an array of services
public
setServices(array<string|int, mixed> $services) : static
Parameters
- $services : array<string|int, mixed>