Zend Framework  3.0
Public Member Functions | Protected Attributes | List of all members
ServiceLocator Class Reference

Simple service locator implementation capable of using closures to generate instances. More...

Public Member Functions

 set ($name, $service)
 Register a service with the locator.
Parameters
string$name
mixed$service
Returns
ServiceLocatorInterface

 
 has ($name)
 Can the locator return the named instance?
 
 get ($name, array $params=[])
 Retrieve a registered service.
 

Protected Attributes

 $map = []
 
 $services = []
 

Detailed Description

Simple service locator implementation capable of using closures to generate instances.

Member Function Documentation

get (   $name,
array  $params = [] 
)

Retrieve a registered service.

Tests first if a value is registered for the service, and, if so, returns it.

If the value returned is a non-object callback or closure, the return value is retrieved, stored, and returned. Parameters passed to the method are passed to the callback, but only on the first retrieval.

If the service requested matches a method in the method map, the return value of that method is returned. Parameters are passed to the matching method.

Parameters
string$name
array$params
Returns
mixed
has (   $name)

Can the locator return the named instance?

Parameters
string$name
Returns
bool
set (   $name,
  $service 
)

Register a service with the locator.

Parameters
string$name
mixed$service
Returns
ServiceLocatorInterface

Implements ServiceLocatorInterface.

Member Data Documentation

$map = []
protected
$services = []
protected