Zend Framework  2.4
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
ServiceManager Class Reference

Public Member Functions

 __construct (ConfigInterface $config=null)
 Constructor.
 
 setAllowOverride ($allowOverride)
 Set allow override.
 
 getAllowOverride ()
 Get allow override.
 
 setShareByDefault ($shareByDefault)
 Set flag indicating whether services are shared by default.
 
 shareByDefault ()
 Are services shared by default?
 
 setThrowExceptionInCreate ($throwExceptionInCreate)
 Set throw exceptions in create.
 
 getThrowExceptionInCreate ()
 Get throw exceptions in create.
 
 setRetrieveFromPeeringManagerFirst ($retrieveFromPeeringManagerFirst=true)
 Set flag indicating whether to pull from peering manager before attempting creation.
 
 retrieveFromPeeringManagerFirst ()
 Should we retrieve from the peering manager prior to attempting to create a service?
 
 setInvokableClass ($name, $invokableClass, $shared=null)
 Set invokable class.
 
 setFactory ($name, $factory, $shared=null)
 Set factory.
 
 addAbstractFactory ($factory, $topOfStack=true)
 Add abstract factory.
 
 addDelegator ($serviceName, $delegatorFactoryName)
 Sets the given service name as to be handled by a delegator factory.
 
 addInitializer ($initializer, $topOfStack=true)
 Add initializer.
 
 setService ($name, $service)
 Register a service with the locator.
 
 setShared ($name, $isShared)
 
 isShared ($name)
 
 get ($name, $usePeeringServiceManagers=true)
 Retrieve a registered instance.
 
 create ($name)
 Create an instance of the requested service.
 
 doCreate ($rName, $cName)
 Actually creates the service.
 
 canCreate ($name, $checkAbstractFactories=true)
 Determine if we can create an instance.
 
 has ($name, $checkAbstractFactories=true, $usePeeringServiceManagers=true)
 Determine if an instance exists.
 
 canCreateFromAbstractFactory ($cName, $rName)
 Determine if we can create an instance from an abstract factory.
 
 setAlias ($alias, $nameOrAlias)
 
 hasAlias ($alias)
 Determine if we have an alias.
 
 createScopedServiceManager ($peering=self::SCOPE_PARENT)
 Create scoped service manager.
 
 addPeeringServiceManager (ServiceManager $manager, $peering=self::SCOPE_PARENT)
 Add a peering relationship.
 
 getRegisteredServices ()
 Retrieve a keyed list of all registered services.
 
 getCanonicalNames ()
 Retrieve a keyed list of all canonical names.
 
 setCanonicalNames ($canonicalNames)
 Allows to override the canonical names lookup map with predefined values.
 
- Public Member Functions inherited from ServiceLocatorInterface
 get ($name)
 Retrieve a registered instance.
 
 has ($name)
 Check for a registered instance.
 

Public Attributes

const SCOPE_PARENT = 'parent'
 #+ Constants
 
const SCOPE_CHILD = 'child'
 

Protected Member Functions

 resolveAlias ($cName)
 Resolve the alias for the given canonical name.
 
 checkForCircularAliasReference ($alias, $nameOrAlias)
 Ensure the alias definition will not result in a circular reference.
 
 canonicalizeName ($name)
 Canonicalize name.
 
 createServiceViaCallback ($callable, $cName, $rName)
 Create service via callback.
 
 retrieveFromPeeringManager ($name)
 Attempt to retrieve an instance via a peering manager.
 
 loopPeeringServiceManagers ($name)
 Loop over peering service managers.
 
 createFromInvokable ($canonicalName, $requestedName)
 Attempt to create an instance via an invokable class.
 
 createFromFactory ($canonicalName, $requestedName)
 Attempt to create an instance via a factory.
 
 createFromAbstractFactory ($canonicalName, $requestedName)
 Attempt to create an instance via an abstract factory.
 
 checkNestedContextStart ($cName)
 
 checkNestedContextStop ($force=false)
 
 createDelegatorFromFactory ($canonicalName, $requestedName)
 
 unregisterService ($canonical)
 Unregister a service.
 

Static Protected Member Functions

static isSubclassOf ($className, $type)
 Checks if the object has this class as one of its parents.
 

Protected Attributes

 $canonicalNames = array()
 
 $allowOverride = false
 
 $invokableClasses = array()
 
 $factories = array()
 
 $abstractFactories = array()
 
 $delegators = array()
 
 $pendingAbstractFactoryRequests = array()
 
 $nestedContextCounter = -1
 
 $nestedContext = array()
 
 $shared = array()
 
 $instances = array()
 
 $aliases = array()
 
 $initializers = array()
 
 $peeringServiceManagers = array()
 
 $shareByDefault = true
 
 $retrieveFromPeeringManagerFirst = false
 
 $throwExceptionInCreate = true
 
 $canonicalNamesReplacements = array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '')
 
 $serviceManagerCaller
 

Constructor & Destructor Documentation

__construct ( ConfigInterface  $config = null)

Constructor.

Parameters
ConfigInterface$config

Member Function Documentation

addAbstractFactory (   $factory,
  $topOfStack = true 
)

Add abstract factory.

Parameters
AbstractFactoryInterface | string$factory
bool$topOfStack
Returns
ServiceManager
Exceptions
Exception\InvalidArgumentExceptionif the abstract factory is invalid
addDelegator (   $serviceName,
  $delegatorFactoryName 
)

Sets the given service name as to be handled by a delegator factory.

Parameters
string$serviceNamename of the service being the delegate
string$delegatorFactoryNamename of the service being the delegator factory
Returns
ServiceManager
addInitializer (   $initializer,
  $topOfStack = true 
)

Add initializer.

Parameters
callable | InitializerInterface$initializer
bool$topOfStack
Returns
ServiceManager
Exceptions
Exception\InvalidArgumentException
addPeeringServiceManager ( ServiceManager  $manager,
  $peering = self::SCOPE_PARENT 
)

Add a peering relationship.

Parameters
ServiceManager$manager
string$peering
Returns
ServiceManager
canCreate (   $name,
  $checkAbstractFactories = true 
)

Determine if we can create an instance.

Proxies to has()

Parameters
string | array$name
bool$checkAbstractFactories
Returns
bool
Deprecated:
this method is being deprecated as of zendframework 2.3, and may be removed in future major versions
canCreateFromAbstractFactory (   $cName,
  $rName 
)

Determine if we can create an instance from an abstract factory.

Parameters
string$cName
string$rName
Returns
bool
canonicalizeName (   $name)
protected

Canonicalize name.

Parameters
string$name
Returns
string
checkForCircularAliasReference (   $alias,
  $nameOrAlias 
)
protected

Ensure the alias definition will not result in a circular reference.

Parameters
string$alias
string$nameOrAlias
Exceptions
Exception\CircularReferenceException
Returns
self
checkNestedContextStart (   $cName)
protected
Parameters
string$cName
Returns
self
checkNestedContextStop (   $force = false)
protected
Parameters
bool$force
Returns
self
bool Track whether not to throw exceptions during create (   $name)

Create an instance of the requested service.

Parameters
string | array$name
Returns
bool|object
createDelegatorFromFactory (   $canonicalName,
  $requestedName 
)
protected
Parameters
$canonicalName
$requestedName
Returns
mixed
Exceptions
Exception\ServiceNotCreatedException
createFromAbstractFactory (   $canonicalName,
  $requestedName 
)
protected

Attempt to create an instance via an abstract factory.

Parameters
string$canonicalName
string$requestedName
Returns
object|null
Exceptions
Exception\ServiceNotCreatedExceptionIf abstract factory is not callable
createFromFactory (   $canonicalName,
  $requestedName 
)
protected

Attempt to create an instance via a factory.

Parameters
string$canonicalName
string$requestedName
Returns
mixed
Exceptions
Exception\ServiceNotCreatedExceptionIf factory is not callable
createFromInvokable (   $canonicalName,
  $requestedName 
)
protected

Attempt to create an instance via an invokable class.

Parameters
string$canonicalName
string$requestedName
Returns
null|
Exceptions
Exception\ServiceNotFoundExceptionIf resolved class does not exist
createScopedServiceManager (   $peering = self::SCOPE_PARENT)

Create scoped service manager.

Parameters
string$peering
Returns
ServiceManager
createServiceViaCallback (   $callable,
  $cName,
  $rName 
)
protected

Create service via callback.

Parameters
callable$callable
string$cName
string$rName
Exceptions
Exception\ServiceNotCreatedException
Exception\ServiceNotFoundException
Exception\CircularDependencyFoundException
Returns
object
doCreate (   $rName,
  $cName 
)

Actually creates the service.

Parameters
string$rNamereal service name
string$cNamecanonicalized service name
Returns
bool|mixed|null|object
Exceptions
Exception\ServiceNotFoundException
get (   $name,
  $usePeeringServiceManagers = true 
)

Retrieve a registered instance.

Parameters
string$name
bool$usePeeringServiceManagers
Exceptions
Exception\ServiceNotFoundException
Returns
object|array
getAllowOverride ( )

Get allow override.

Returns
bool
getCanonicalNames ( )

Retrieve a keyed list of all canonical names.

Handy for debugging!

Returns
array
getRegisteredServices ( )

Retrieve a keyed list of all registered services.

Handy for debugging!

Returns
array
getThrowExceptionInCreate ( )

Get throw exceptions in create.

Returns
bool
has (   $name,
  $checkAbstractFactories = true,
  $usePeeringServiceManagers = true 
)

Determine if an instance exists.

Parameters
string | array$nameAn array argument accepts exactly two values. Example: array('canonicalName', 'requestName')
bool$checkAbstractFactories
bool$usePeeringServiceManagers
Returns
bool
hasAlias (   $alias)

Determine if we have an alias.

Parameters
string$alias
Returns
bool
isShared (   $name)
Parameters
string$name
Returns
bool
Exceptions
Exception\ServiceNotFoundException
static isSubclassOf (   $className,
  $type 
)
staticprotected

Checks if the object has this class as one of its parents.

See Also
https://bugs.php.net/bug.php?id=53727
https://github.com/zendframework/zf2/pull/1807
Deprecated:
since zf 2.3 requires PHP >= 5.3.23
Parameters
string$className
string$type
Returns
bool
Deprecated:
this method is being deprecated as of zendframework 2.2, and may be removed in future major versions
loopPeeringServiceManagers (   $name)
protected

Loop over peering service managers.

Parameters
string$name
Returns
mixed
resolveAlias (   $cName)
protected

Resolve the alias for the given canonical name.

Parameters
string$cNameThe canonical name to resolve
Returns
string The resolved canonical name
retrieveFromPeeringManager (   $name)
protected

Attempt to retrieve an instance via a peering manager.

Parameters
string$name
Returns
mixed
retrieveFromPeeringManagerFirst ( )

Should we retrieve from the peering manager prior to attempting to create a service?

Returns
bool
setAlias (   $alias,
  $nameOrAlias 
)
Parameters
string$alias
string$nameOrAlias
Returns
ServiceManager
Exceptions
Exception\ServiceNotFoundException
Exception\InvalidServiceNameException
setAllowOverride (   $allowOverride)

Set allow override.

Parameters
$allowOverride
Returns
ServiceManager
setCanonicalNames (   $canonicalNames)

Allows to override the canonical names lookup map with predefined values.

Parameters
array$canonicalNames
Returns
ServiceManager
setFactory (   $name,
  $factory,
  $shared = null 
)

Set factory.

Parameters
string$name
string | FactoryInterface | callable$factory
bool$shared
Returns
ServiceManager
Exceptions
Exception\InvalidArgumentException
Exception\InvalidServiceNameException
setInvokableClass (   $name,
  $invokableClass,
  $shared = null 
)

Set invokable class.

Parameters
string$name
string$invokableClass
bool$shared
Returns
ServiceManager
Exceptions
Exception\InvalidServiceNameException
setRetrieveFromPeeringManagerFirst (   $retrieveFromPeeringManagerFirst = true)

Set flag indicating whether to pull from peering manager before attempting creation.

Parameters
bool$retrieveFromPeeringManagerFirst
Returns
ServiceManager
setService (   $name,
  $service 
)

Register a service with the locator.

Parameters
string$name
mixed$service
Returns
ServiceManager
Exceptions
Exception\InvalidServiceNameException
setShareByDefault (   $shareByDefault)

Set flag indicating whether services are shared by default.

Parameters
bool$shareByDefault
Returns
ServiceManager
Exceptions
Exception\RuntimeExceptionif allowOverride is false
setShared (   $name,
  $isShared 
)
Parameters
string$name
bool$isShared
Returns
ServiceManager
Exceptions
Exception\ServiceNotFoundException
setThrowExceptionInCreate (   $throwExceptionInCreate)

Set throw exceptions in create.

Parameters
bool$throwExceptionInCreate
Returns
ServiceManager
shareByDefault ( )

Are services shared by default?

Returns
bool
unregisterService (   $canonical)
protected

Unregister a service.

Called when $allowOverride is true and we detect that a service being added to the instance already exists. This will remove the duplicate entry, and also any shared flags previously registered.

Parameters
string$canonical
Returns
void

Member Data Documentation

$abstractFactories = array()
protected
$aliases = array()
protected
$allowOverride = false
protected
$canonicalNames = array()
protected
$canonicalNamesReplacements = array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '')
protected
$delegators = array()
protected
$factories = array()
protected
$initializers = array()
protected
$instances = array()
protected
$invokableClasses = array()
protected
$nestedContext = array()
protected
$nestedContextCounter = -1
protected
$peeringServiceManagers = array()
protected
$pendingAbstractFactoryRequests = array()
protected
$retrieveFromPeeringManagerFirst = false
protected
$serviceManagerCaller
protected
$shareByDefault = true
protected
$shared = array()
protected
$throwExceptionInCreate = true
protected
const SCOPE_CHILD = 'child'
const SCOPE_PARENT = 'parent'

#+ Constants