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.

category Zend
package Zend_ServiceManager

 Methods

Constructor

__construct(\Zend\ServiceManager\ConfigInterface $configuration) 

Add a default initializer to ensure the plugin is valid after instance creation.

Parameters

Add abstract factory

addAbstractFactory(\Zend\ServiceManager\AbstractFactoryInterface | string $factory, bool $topOfStack) : \Zend\ServiceManager\ServiceManager
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::addAbstractFactory()

Parameters

$topOfStack

bool

Exceptions

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

Returns

Add initializer

addInitializer(\Zend\ServiceManager\callable | \Zend\ServiceManager\InitializerInterface $initializer, bool $topOfStack) : \Zend\ServiceManager\ServiceManager
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::addInitializer()

Parameters

$initializer

\Zend\ServiceManager\callable\Zend\ServiceManager\InitializerInterface

$topOfStack

bool

Exceptions

\Zend\ServiceManager\Exception\InvalidArgumentException

Returns

Add a peering relationship

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

inherited_from \Zend\ServiceManager\ServiceManager::addPeeringServiceManager()

Parameters

$peering

string

Returns

Determine if we can create an instance.

canCreate(string | array $name, bool $checkAbstractFactories) : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::canCreate()

Parameters

$name

stringarray

$checkAbstractFactories

bool

Returns

bool

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

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

inherited_from \Zend\ServiceManager\ServiceManager::canCreateFromAbstractFactory()

Parameters

$cName

string

$rName

string

Returns

bool

Create an instance

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

inherited_from \Zend\ServiceManager\ServiceManager::create()

Parameters

$name

stringarray

Exceptions

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

Returns

boolobject

Create scoped service manager

createScopedServiceManager(string $peering) : \Zend\ServiceManager\ServiceManager
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::createScopedServiceManager()

Parameters

$peering

string

Returns

Retrieve a service from the manager by name

get(string $name, array $options, bool $usePeeringServiceManagers) : object

Allows passing an array of options to use when creating the instance. createFromInvokable() will use these and pass them to the instance constructor if not null and a non-empty array.

Parameters

$name

string

$options

array

$usePeeringServiceManagers

bool

Exceptions

\Zend\ServiceManager\Exception\ServiceNotFoundException

Returns

object

Get allow override

getAllowOverride() : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::getAllowOverride()

Returns

bool

Retrieve a keyed list of all canonical names.

getCanonicalNames() : array
Inherited

Handy for debugging!

inherited_from \Zend\ServiceManager\ServiceManager::getCanonicalNames()

Returns

array

Retrieve a keyed list of all registered services.

getRegisteredServices() : array
Inherited

Handy for debugging!

inherited_from \Zend\ServiceManager\ServiceManager::getRegisteredServices()

Returns

array

Get the main plugin manager.

getServiceLocator() : mixed

Useful for fetching dependencies from within factories.

Returns

mixed

Get throw exceptions in create

getThrowExceptionInCreate() : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::getThrowExceptionInCreate()

Returns

bool

Check for a registered instance

has(string | array $name, bool $checkAbstractFactories, bool $usePeeringServiceManagers) : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::has()

Parameters

$name

stringarray

$checkAbstractFactories

bool

$usePeeringServiceManagers

bool

Returns

bool

Determine if we have an alias

hasAlias(string $alias) : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::hasAlias()

Parameters

$alias

string

Returns

bool

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

retrieveFromPeeringManagerFirst() : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::retrieveFromPeeringManagerFirst()

Returns

bool

setAlias()

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

inherited_from \Zend\ServiceManager\ServiceManager::setAlias()

Parameters

$alias

string

$nameOrAlias

string

Exceptions

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

Returns

Set allow override

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

inherited_from \Zend\ServiceManager\ServiceManager::setAllowOverride()

Parameters

$allowOverride

Returns

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

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

inherited_from \Zend\ServiceManager\ServiceManager::setCanonicalNames()

Parameters

$canonicalNames

array

Returns

Set factory

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

inherited_from \Zend\ServiceManager\ServiceManager::setFactory()

Parameters

$name

string

$factory

string\Zend\ServiceManager\FactoryInterface\Zend\ServiceManager\callable

$shared

bool

Exceptions

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

Returns

Set invokable class

setInvokableClass(string $name, string $invokableClass, bool $shared) : \Zend\ServiceManager\ServiceManager
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::setInvokableClass()

Parameters

$name

string

$invokableClass

string

$shared

bool

Exceptions

\Zend\ServiceManager\Exception\InvalidServiceNameException

Returns

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

setRetrieveFromPeeringManagerFirst(bool $retrieveFromPeeringManagerFirst) : \Zend\ServiceManager\ServiceManager
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::setRetrieveFromPeeringManagerFirst()

Parameters

$retrieveFromPeeringManagerFirst

bool

Returns

Register a service with the locator.

setService(string $name, mixed $service, bool $shared) : \Zend\ServiceManager\AbstractPluginManager

Validates that the service object via validatePlugin() prior to attempting to register it.

Parameters

$name

string

$service

mixed

$shared

bool

Exceptions

\Zend\ServiceManager\Exception\InvalidServiceNameException

Returns

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

setServiceLocator(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) : \Zend\ServiceManager\AbstractPluginManager

Set flag indicating whether services are shared by default

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

inherited_from \Zend\ServiceManager\ServiceManager::setShareByDefault()

Parameters

$shareByDefault

bool

Exceptions

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

Returns

setShared()

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

inherited_from \Zend\ServiceManager\ServiceManager::setShared()

Parameters

$name

string

$isShared

bool

Exceptions

\Zend\ServiceManager\Exception\ServiceNotFoundException

Returns

Set throw exceptions in create

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

inherited_from \Zend\ServiceManager\ServiceManager::setThrowExceptionInCreate()

Parameters

$throwExceptionInCreate

bool

Returns

Are services shared by default?

shareByDefault() : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::shareByDefault()

Returns

bool

Validate the plugin

validatePlugin(mixed $plugin) : void

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

inherited_from \Zend\ServiceManager\ServiceManager::canonicalizeName()

Parameters

$name

string

Returns

string

Attempt to create an instance via an abstract factory

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

inherited_from \Zend\ServiceManager\ServiceManager::createFromAbstractFactory()

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 class

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

Overrides parent implementation by passing $creationOptions to the constructor, if non-null.

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

Overrides parent implementation by passing $creationOptions to the constructor, if non-null.

Parameters

$canonicalName

string

$requestedName

string

Exceptions

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

Returns

null\stdClass

Create service via callback

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

inherited_from \Zend\ServiceManager\ServiceManager::createServiceViaCallback()

Parameters

$callable

\Zend\ServiceManager\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) : bool
Inherited

see \Zend\ServiceManager\https://bugs.php.net/bug.php?id=53727
see \Zend\ServiceManager\https://github.com/zendframework/zf2/pull/1807
inherited_from \Zend\ServiceManager\ServiceManager::isSubclassOf()

Parameters

$className

string

$type

string

Returns

bool

Attempt to retrieve an instance via a peering manager

retrieveFromPeeringManager(string $name) : mixed
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::retrieveFromPeeringManager()

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.

inherited_from \Zend\ServiceManager\ServiceManager::unregisterService()

Parameters

$canonical

string

 Properties

 

$abstractFactories

$abstractFactories : \Zend\ServiceManager\AbstractFactoryInterface[]
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$abstractFactories
 

$aliases

$aliases : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$aliases
 

Allow overriding by default

$allowOverride : bool

 

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

$autoAddInvokableClass : bool

 

Lookup for canonicalized names.

$canonicalNames : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$canonicalNames
 

<p>map of characters to be replaced through strtr</p>

$canonicalNamesReplacements : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$canonicalNamesReplacements
 

Options to use when creating an instance

$creationOptions : mixed

 

$factories

$factories : string | \Zend\ServiceManager\callable | \Closure | \Zend\ServiceManager\FactoryInterface[]
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$factories
 

$initializers

$initializers : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$initializers
 

Registered services and cached values

$instances : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$instances
 

$invokableClasses

$invokableClasses : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$invokableClasses
 

$peeringServiceManagers

$peeringServiceManagers : \Zend\ServiceManager\ServiceManager[]
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$peeringServiceManagers
 

$pendingAbstractFactoryRequests

$pendingAbstractFactoryRequests : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$pendingAbstractFactoryRequests
 

$retrieveFromPeeringManagerFirst

$retrieveFromPeeringManagerFirst : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$retrieveFromPeeringManagerFirst
 

The main service locator

$serviceLocator : \Zend\ServiceManager\ServiceLocatorInterface

 

Whether or not to share by default

$shareByDefault : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$shareByDefault
 

$shared

$shared : array
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$shared
 

<p>Track whether not to throw exceptions during create()</p>

$throwExceptionInCreate : bool
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::$$throwExceptionInCreate

 Constants

 

SCOPE_CHILD

SCOPE_CHILD 
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::SCOPE_CHILD
 

SCOPE_PARENT

SCOPE_PARENT 
Inherited

inherited_from \Zend\ServiceManager\ServiceManager::SCOPE_PARENT