ServiceManager implementation for managing plugins

Automatically registers an initializer which should be used to verify that a plugin instance is of a valid type. Additionally, allows plugins to accept an array of options for the constructor, which can be used to configure the plugin when retrieved. Finally, enables the allowOverride property by default to allow registering factories, aliases, and invokables to take the place of those provided by the implementing class.

package Default
inherited_from \Zend\ServiceManager\AbstractPluginManager

 Methods

Constructor

__construct(\Zend\ServiceManager\ConfigInterface $config = null
Inherited

Parameters

$config

\Zend\ServiceManager\ConfigInterface

Add abstract factory

addAbstractFactory(\Zend\ServiceManager\AbstractFactoryInterface|string $factory, boolean $topOfStack = true) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$factory

\Zend\ServiceManager\AbstractFactoryInterfacestring

$topOfStack

boolean

Exceptions

\Zend\ServiceManager\Exception\InvalidArgumentException if the abstract factory is invalid

Returns

\Zend\ServiceManager\ServiceManager

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

addDelegator(string $serviceName, string $delegatorFactoryName) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$serviceName

string

name of the service being the delegate

$delegatorFactoryName

string

name of the service being the delegator factory

Returns

\Zend\ServiceManager\ServiceManager

Add initializer

addInitializer(callable|\Zend\ServiceManager\InitializerInterface $initializer, boolean $topOfStack = true) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$initializer

callable\Zend\ServiceManager\InitializerInterface

$topOfStack

boolean

Exceptions

\Zend\ServiceManager\Exception\InvalidArgumentException

Returns

\Zend\ServiceManager\ServiceManager

Add a peering relationship

addPeeringServiceManager(\Zend\ServiceManager\ServiceManager $manager, string $peering = self::SCOPE_PARENT) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$manager

\Zend\ServiceManager\ServiceManager

$peering

string

Returns

\Zend\ServiceManager\ServiceManager

Determine if we can create an instance.

canCreate(string|array $name, boolean $checkAbstractFactories = true) : boolean
Inherited

Proxies to has()

deprecated this method is being deprecated as of zendframework 2.3, and may be removed in future major versions

Parameters

$name

stringarray

$checkAbstractFactories

boolean

Returns

boolean

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

canCreateFromAbstractFactory(string $cName, string $rName) : boolean
Inherited

Parameters

$cName

string

$rName

string

Returns

boolean

Create an instance of the requested service

create(string|array $name) : boolean | object
Inherited

Parameters

$name

stringarray

Returns

booleanobject

Create scoped service manager

createScopedServiceManager(string $peering = self::SCOPE_PARENT) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$peering

string

Returns

\Zend\ServiceManager\ServiceManager

Retrieve a registered instance

get(string $name, boolean $usePeeringServiceManagers = true) : object | array
Inherited
inherited_from \Zend\ServiceManager\ServiceLocatorInterface::get()

Parameters

$name

string

$usePeeringServiceManagers

boolean

Exceptions

\Zend\ServiceManager\Exception\ServiceNotFoundException

Returns

objectarray

Get allow override

getAllowOverride() : boolean
Inherited

Returns

boolean

Retrieve a keyed list of all canonical names. Handy for debugging!

getCanonicalNames() : array
Inherited

Returns

array

Retrieve a keyed list of all registered services. Handy for debugging!

getRegisteredServices() : array
Inherited

Returns

array

Get the main plugin manager. Useful for fetching dependencies from within factories.

getServiceLocator() : \Zend\ServiceManager\ServiceLocatorInterface
Inherited
inherited_from \Zend\ServiceManager\ServiceLocatorAwareInterface::getServiceLocator()

Returns

\Zend\ServiceManager\ServiceLocatorInterface

Get throw exceptions in create

getThrowExceptionInCreate() : boolean
Inherited

Returns

boolean

Determine if an instance exists.

has(string|array $name, boolean $checkAbstractFactories = true, boolean $usePeeringServiceManagers = true) : boolean
Inherited
inherited_from \Zend\ServiceManager\ServiceLocatorInterface::has()

Parameters

$name

stringarray

An array argument accepts exactly two values. Example: array('canonicalName', 'requestName')

$checkAbstractFactories

boolean

$usePeeringServiceManagers

boolean

Returns

boolean

Determine if we have an alias

hasAlias(string $alias) : boolean
Inherited

Parameters

$alias

string

Returns

boolean

isShared()

isShared(string $name) : boolean
Inherited

Parameters

$name

string

Exceptions

\Zend\ServiceManager\Exception\ServiceNotFoundException

Returns

boolean

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

retrieveFromPeeringManagerFirst() : boolean
Inherited

Returns

boolean

setAlias()

setAlias(string $alias, string $nameOrAlias) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$alias

string

$nameOrAlias

string

Exceptions

\Zend\ServiceManager\Exception\ServiceNotFoundException
\Zend\ServiceManager\Exception\InvalidServiceNameException

Returns

\Zend\ServiceManager\ServiceManager

Set allow override

setAllowOverride($allowOverride) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$allowOverride

Returns

\Zend\ServiceManager\ServiceManager

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

setCanonicalNames(array $canonicalNames) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$canonicalNames

array

Returns

\Zend\ServiceManager\ServiceManager

Set factory

setFactory(string $name, string|\Zend\ServiceManager\FactoryInterface|callable $factory, boolean $shared = null) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$name

string

$factory

string\Zend\ServiceManager\FactoryInterfacecallable

$shared

boolean

Exceptions

\Zend\ServiceManager\Exception\InvalidArgumentException
\Zend\ServiceManager\Exception\InvalidServiceNameException

Returns

\Zend\ServiceManager\ServiceManager

Set invokable class

setInvokableClass(string $name, string $invokableClass, boolean $shared = null) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$name

string

$invokableClass

string

$shared

boolean

Exceptions

\Zend\ServiceManager\Exception\InvalidServiceNameException

Returns

\Zend\ServiceManager\ServiceManager

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

setRetrieveFromPeeringManagerFirst(boolean $retrieveFromPeeringManagerFirst = true) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$retrieveFromPeeringManagerFirst

boolean

Returns

\Zend\ServiceManager\ServiceManager

Register a service with the locator

setService(string $name, mixed $service) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$name

string

$service

mixed

Exceptions

\Zend\ServiceManager\Exception\InvalidServiceNameException

Returns

\Zend\ServiceManager\ServiceManager

Set the main service locator so factories can have access to it to pull deps

setServiceLocator(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) : \Zend\ServiceManager\AbstractPluginManager
Inherited
inherited_from \Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator()

Parameters

$serviceLocator

\Zend\ServiceManager\ServiceLocatorInterface

Returns

\Zend\ServiceManager\AbstractPluginManager

Set flag indicating whether services are shared by default

setShareByDefault(boolean $shareByDefault) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$shareByDefault

boolean

Exceptions

\Zend\ServiceManager\Exception\RuntimeException if allowOverride is false

Returns

\Zend\ServiceManager\ServiceManager

setShared()

setShared(string $name, boolean $isShared) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$name

string

$isShared

boolean

Exceptions

\Zend\ServiceManager\Exception\ServiceNotFoundException

Returns

\Zend\ServiceManager\ServiceManager

Set throw exceptions in create

setThrowExceptionInCreate(boolean $throwExceptionInCreate) : \Zend\ServiceManager\ServiceManager
Inherited

Parameters

$throwExceptionInCreate

boolean

Returns

\Zend\ServiceManager\ServiceManager

Are services shared by default?

shareByDefault() : boolean
Inherited

Returns

boolean

Validate the plugin

validatePlugin(mixed $plugin) : boolean

Checks that the element is an instance of AssertionInterface

inherited_from \Zend\ServiceManager\AbstractPluginManager::validatePlugin()

Parameters

$plugin

mixed

Exceptions

\Zend\Permissions\Acl\Exception\InvalidArgumentException

Returns

boolean

Validate the plugin

validatePlugin(mixed $plugin) : void
Inherited

Checks that the filter loaded is either a valid callback or an instance of FilterInterface.

Parameters

$plugin

mixed

Exceptions

\Zend\ServiceManager\Exception\RuntimeException if invalid

Canonicalize name

canonicalizeName(string $name) : string
Inherited

Parameters

$name

string

Returns

string

Ensure the alias definition will not result in a circular reference

checkForCircularAliasReference(string $alias, string $nameOrAlias) : \Zend\Permissions\Acl\Assertion\AssertionManager
Inherited
fluent This method is part of a fluent interface and will return the same instance

Parameters

$alias

string

$nameOrAlias

string

Exceptions

\Zend\ServiceManager\Exception\CircularReferenceException

Returns

\Zend\Permissions\Acl\Assertion\AssertionManager

checkNestedContextStart()

checkNestedContextStart(string $cName) : \Zend\Permissions\Acl\Assertion\AssertionManager
Inherited
fluent This method is part of a fluent interface and will return the same instance

Parameters

$cName

string

Returns

\Zend\Permissions\Acl\Assertion\AssertionManager

checkNestedContextStop()

checkNestedContextStop(boolean $force = false) : \Zend\Permissions\Acl\Assertion\AssertionManager
Inherited
fluent This method is part of a fluent interface and will return the same instance

Parameters

$force

boolean

Returns

\Zend\Permissions\Acl\Assertion\AssertionManager

createDelegatorFromFactory()

createDelegatorFromFactory($canonicalName, $requestedName) : mixed
Inherited

Parameters

$canonicalName

$requestedName

Exceptions

\Zend\ServiceManager\Exception\ServiceNotCreatedException

Returns

mixed

Attempt to create an instance via an abstract factory

createFromAbstractFactory(string $canonicalName, string $requestedName) : object | null
Inherited

Parameters

$canonicalName

string

$requestedName

string

Exceptions

\Zend\ServiceManager\Exception\ServiceNotCreatedException If abstract factory is not callable

Returns

objectnull

Attempt to create an instance via a factory

createFromFactory(string $canonicalName, string $requestedName) : mixed
Inherited

Parameters

$canonicalName

string

$requestedName

string

Exceptions

\Zend\ServiceManager\Exception\ServiceNotCreatedException If factory is not callable

Returns

mixed

Attempt to create an instance via an invokable class

createFromInvokable(string $canonicalName, string $requestedName) : null | \stdClass
Inherited

Parameters

$canonicalName

string

$requestedName

string

Exceptions

\Zend\ServiceManager\Exception\ServiceNotFoundException If resolved class does not exist

Returns

null\stdClass

Create service via callback

createServiceViaCallback(callable $callable, string $cName, string $rName) : object
Inherited

Parameters

$callable

callable

$cName

string

$rName

string

Exceptions

\Zend\ServiceManager\Exception\ServiceNotCreatedException
\Zend\ServiceManager\Exception\ServiceNotFoundException
\Zend\ServiceManager\Exception\CircularDependencyFoundException

Returns

object

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

isSubclassOf(string $className, string $type) : boolean
InheritedStatic
see
see
deprecated since zf 2.3 requires PHP >= 5.3.23
deprecated this method is being deprecated as of zendframework 2.2, and may be removed in future major versions

Parameters

$className

string

$type

string

Returns

boolean

Loop over peering service managers.

loopPeeringServiceManagers(string $name) : mixed
Inherited

Parameters

$name

string

Returns

mixed

Resolve the alias for the given canonical name

resolveAlias(string $cName) : string
Inherited

Parameters

$cName

string

The canonical name to resolve

Returns

stringThe resolved canonical name

Attempt to retrieve an instance via a peering manager

retrieveFromPeeringManager(string $name) : mixed
Inherited

Parameters

$name

string

Returns

mixed

Unregister a service

unregisterService(string $canonical) : void
Inherited

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

$canonical

string

Creates a callback that uses a delegator to create a service

createDelegatorCallback(\Zend\ServiceManager\DelegatorFactoryInterface|callable $delegatorFactory, string $rName, string $cName, callable $creationCallback) : callable
Inherited

Parameters

$delegatorFactory

\Zend\ServiceManager\DelegatorFactoryInterfacecallable

the delegator factory

$rName

string

requested service name

$cName

string

canonical service name

$creationCallback

callable

callback for instantiating the real service

Returns

callable

tryThrowingServiceLocatorUsageException()

tryThrowingServiceLocatorUsageException(string $serviceName, boolean $isAutoInvokable, \Exception $exception) 
Inherited

Parameters

$serviceName

string

$isAutoInvokable

boolean

$exception

\Exception

Exceptions

\Exception
\Zend\ServiceManager\Exception\ServiceLocatorUsageException

 Properties

 

$abstractFactories

$abstractFactories : array<mixed,\Zend\ServiceManager\AbstractFactoryInterface>

Default

array()
 

$aliases

$aliases : array

Default

array()
 

$allowOverride

$allowOverride : boolean

Default

false
 

Whether or not to auto-add a class as an invokable class if it exists

$autoAddInvokableClass : boolean

Default

true
 

Lookup for canonicalized names.

$canonicalNames : array

Default

array()
 

map of characters to be replaced through strtr

$canonicalNamesReplacements : array

Default

array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '')
 

Options to use when creating an instance

$creationOptions : mixed

Default

null
 

$delegators

$delegators : array<mixed,array>

Default

array()
 

$factories

$factories : string | callable | \Closure | array<mixed,\Zend\ServiceManager\FactoryInterface>

Default

array()
 

$initializers

$initializers : array

Default

array()
 

Registered services and cached values

$instances : array

Default

array()
 

$invokableClasses

$invokableClasses : array

Default

array()
 

$nestedContext

$nestedContext : array

Default

array()
 

$nestedContextCounter

$nestedContextCounter : integer

Default

-1
 

$peeringServiceManagers

$peeringServiceManagers : array<mixed,\Zend\ServiceManager\ServiceManager>

Default

array()
 

$pendingAbstractFactoryRequests

$pendingAbstractFactoryRequests : array

Default

array()
 

$retrieveFromPeeringManagerFirst

$retrieveFromPeeringManagerFirst : boolean

Default

false
 

The main service locator

$serviceLocator : \Zend\ServiceManager\ServiceLocatorInterface

Default

 

$serviceManagerCaller

$serviceManagerCaller : \Zend\ServiceManager\ServiceLocatorInterface

Default

 

Whether or not to share by default

$shareByDefault : boolean

Default

true
 

$shared

$shared : array

Default

array()
 

$sharedByDefault

$sharedByDefault 

Default

true
 

Track whether not to throw exceptions during create()

$throwExceptionInCreate : boolean

Default

true

 Constants

 

SCOPE_CHILD

SCOPE_CHILD = 'child' 
 

SCOPE_PARENT

SCOPE_PARENT = 'parent'