AbstractPluginManager
extends ServiceManager
in package
implements
PluginManagerInterface
Abstract plugin manager.
Abstract PluginManagerInterface implementation providing:
- creation context support. The constructor accepts the parent container instance, which is then used when creating instances.
- plugin validation. Implementations may define the
$instanceOf
property to indicate what class types constitute valid plugins, omitting the requirement to define thevalidate()
method.
The implementation extends ServiceManager
, thus providing the same set
of capabilities as found in that implementation.
Interfaces, Classes, Traits and Enums
- PluginManagerInterface
- Interface for a plugin manager
Table of Contents
- $abstractFactories : array<string|int, AbstractFactoryInterface>
- $aliases : array<string|int, string>
- A list of aliases
- $allowOverride : mixed
- Whether or not changes may be made to this instance.
- $autoAddInvokableClass : bool
- Whether or not to auto-add a FQCN as an invokable if it exists.
- $configured : bool
- Service manager was already configured?
- $creationContext : ContainerInterface
- $delegators : array<string|int, array<string|int, string>>|array<string|int, array<string|int, DelegatorFactoryInterface>>
- $factories : array<string|int, string>|array<string|int, callable>
- A list of factories (either as string name or callable)
- $initializers : array<string|int, InitializerInterface>|array<string|int, callable>
- $instanceOf : null|string
- An object type that the created instance must be instanced of
- $lazyServices : array<string|int, mixed>
- $services : array<string|int, mixed>
- A list of already loaded services (this act as a local cache)
- $shared : array<string|int, bool>
- Enable/disable shared instances by service name.
- $sharedByDefault : bool
- Should the services be shared by default?
- $cachedAbstractFactories : array<string|int, mixed>
- Cached abstract factories from string.
- $lazyServicesDelegator : null|LazyServiceFactory
- $resolvedAliases : array<string|int, string>
- __construct() : mixed
- Constructor.
- addAbstractFactory() : mixed
- Add an abstract factory for resolving services.
- addDelegator() : mixed
- Add a delegator for a given service.
- addInitializer() : mixed
- Add an initializer.
- build() : mixed
- Build a service by its name, using optional options (such services are NEVER cached).
- configure() : self
- Override configure() to validate service instances.
- get() : mixed
- {@inheritDoc}
- getAllowOverride() : bool
- Retrieve the flag indicating immutability status.
- getServiceLocator() : ContainerInterface
- Implemented for backwards compatibility with previous plugin managers only.
- has() : mixed
- {@inheritDoc}
- mapLazyService() : mixed
- Create a lazy service mapping to a class.
- setAlias() : mixed
- Add an alias.
- setAllowOverride() : mixed
- Indicate whether or not the instance is immutable.
- setFactory() : mixed
- Specify a factory for a given service name.
- setInvokableClass() : mixed
- Add an invokable class mapping.
- setService() : mixed
- Map a service.
- setServiceLocator() : void
- Implemented for backwards compatibility only.
- setShared() : mixed
- Add a service sharing rule.
- validate() : void
- Validate an instance
- configureAliases() : void
- createAliasesForInvokables() : array<string|int, mixed>
- Create aliases for invokable classes.
- createDelegatorFromName() : object
- createFactoriesForInvokables() : array<string|int, mixed>
- Create invokable factories for invokable classes.
- createLazyServiceDelegatorFactory() : LazyServiceFactory
- Create the lazy services delegator factory.
- doCreate() : mixed
- Create a new instance with an already resolved name
- getFactory() : callable
- Get a factory for the given service name
- resolveAbstractFactories() : void
- Instantiate abstract factories for to avoid checks during service construction.
- resolveAliases() : void
- Resolve aliases to their canonical service names.
- resolveInitializers() : void
- Instantiate initializers for to avoid checks during service construction.
- resolveNewAliasesWithPreviouslyResolvedAliases() : void
- Rewrites the map of aliases by resolving the given $aliases with the existing resolved ones.
- validateOverrides() : mixed
- Determine if one or more services already exist in the container.
- validateOverrideSet() : mixed
- Determine if one or more services already exist for a given type.
Properties
$abstractFactories
protected
array<string|int, AbstractFactoryInterface>
$abstractFactories
= []
$aliases
A list of aliases
protected
array<string|int, string>
$aliases
= []
Should map one alias to a service name, or another alias (aliases are recursively resolved)
$allowOverride
Whether or not changes may be made to this instance.
protected
mixed
$allowOverride
= false
$autoAddInvokableClass
Whether or not to auto-add a FQCN as an invokable if it exists.
protected
bool
$autoAddInvokableClass
= true
$configured
Service manager was already configured?
protected
bool
$configured
= false
$creationContext
protected
ContainerInterface
$creationContext
$delegators
protected
array<string|int, array<string|int, string>>|array<string|int, array<string|int, DelegatorFactoryInterface>>
$delegators
= []
$factories
A list of factories (either as string name or callable)
protected
array<string|int, string>|array<string|int, callable>
$factories
= []
$initializers
protected
array<string|int, InitializerInterface>|array<string|int, callable>
$initializers
= []
$instanceOf
An object type that the created instance must be instanced of
protected
null|string
$instanceOf
= null
$lazyServices
protected
array<string|int, mixed>
$lazyServices
= []
$services
A list of already loaded services (this act as a local cache)
protected
array<string|int, mixed>
$services
= []
$shared
Enable/disable shared instances by service name.
protected
array<string|int, bool>
$shared
= []
Example configuration:
'shared' => [ MyService::class => true, // will be shared, even if "sharedByDefault" is false MyOtherService::class => false // won't be shared, even if "sharedByDefault" is true ]
$sharedByDefault
Should the services be shared by default?
protected
bool
$sharedByDefault
= true
$cachedAbstractFactories
Cached abstract factories from string.
private
array<string|int, mixed>
$cachedAbstractFactories
= []
$lazyServicesDelegator
private
null|LazyServiceFactory
$lazyServicesDelegator
$resolvedAliases
private
array<string|int, string>
$resolvedAliases
= []
Methods
__construct()
Constructor.
public
__construct([null|ConfigInterface|ContainerInterface|ContainerInterface $configInstanceOrParentLocator = null ][, array<string|int, mixed> $config = [] ]) : mixed
Sets the provided $parentLocator as the creation context for all factories; for $config, ServiceManager::configure() for details on its accepted structure.
Parameters
- $configInstanceOrParentLocator : null|ConfigInterface|ContainerInterface|ContainerInterface = null
- $config : array<string|int, mixed> = []
Return values
mixed —addAbstractFactory()
Add an abstract factory for resolving services.
public
addAbstractFactory(string|AbstractFactoryInterface $factory) : mixed
Parameters
- $factory : string|AbstractFactoryInterface
-
Service name
Return values
mixed —addDelegator()
Add a delegator for a given service.
public
addDelegator(string $name, string|callable|DelegatorFactoryInterface $factory) : mixed
Parameters
- $name : string
-
Service name
- $factory : string|callable|DelegatorFactoryInterface
-
Delegator factory to assign.
Return values
mixed —addInitializer()
Add an initializer.
public
addInitializer(string|callable|InitializerInterface $initializer) : mixed
Parameters
- $initializer : string|callable|InitializerInterface
Return values
mixed —build()
Build a service by its name, using optional options (such services are NEVER cached).
public
build(mixed $name[, array<string|int, mixed> $options = null ]) : mixed
Parameters
- $name : mixed
- $options : array<string|int, mixed> = null
Return values
mixed —configure()
Override configure() to validate service instances.
public
configure(array<string|int, mixed> $config) : self
If an instance passed in the services
configuration is invalid for the
plugin manager, this method will raise an InvalidServiceException.
Parameters
- $config : array<string|int, mixed>
Tags
Return values
self —get()
{@inheritDoc}
public
get(string $name[, null|array<string|int, mixed> $options = null ]) : mixed
Parameters
- $name : string
-
Service name of plugin to retrieve.
- $options : null|array<string|int, mixed> = null
-
Options to use when creating the instance.
Tags
Return values
mixed —getAllowOverride()
Retrieve the flag indicating immutability status.
public
getAllowOverride() : bool
Return values
bool —getServiceLocator()
Implemented for backwards compatibility with previous plugin managers only.
public
getServiceLocator() : ContainerInterface
Returns the creation context.
Tags
Return values
ContainerInterface —has()
{@inheritDoc}
public
has(mixed $name) : mixed
Parameters
- $name : mixed
Return values
mixed —mapLazyService()
Create a lazy service mapping to a class.
public
mapLazyService(string $name[, null|string $class = null ]) : mixed
Parameters
- $name : string
-
Service name to map
- $class : null|string = null
-
Class to which to map; if not provided, $name will be used for the mapping.
Return values
mixed —setAlias()
Add an alias.
public
setAlias(string $alias, string $target) : mixed
Parameters
- $alias : string
- $target : string
Return values
mixed —setAllowOverride()
Indicate whether or not the instance is immutable.
public
setAllowOverride(bool $flag) : mixed
Parameters
- $flag : bool
Return values
mixed —setFactory()
Specify a factory for a given service name.
public
setFactory(string $name, string|callable|FactoryInterface $factory) : mixed
Parameters
- $name : string
-
Service name
- $factory : string|callable|FactoryInterface
-
Factory to which to map.
Return values
mixed —setInvokableClass()
Add an invokable class mapping.
public
setInvokableClass(string $name[, null|string $class = null ]) : mixed
Parameters
- $name : string
-
Service name
- $class : null|string = null
-
Class to which to map; if omitted, $name is assumed.
Return values
mixed —setService()
Map a service.
public
setService(string $name, array<string|int, mixed>|object $service) : mixed
Parameters
- $name : string
-
Service name
- $service : array<string|int, mixed>|object
Return values
mixed —setServiceLocator()
Implemented for backwards compatibility only.
public
setServiceLocator(ContainerInterface $container) : void
Returns the creation context.
Parameters
- $container : ContainerInterface
Tags
Return values
void —setShared()
Add a service sharing rule.
public
setShared(string $name, bool $flag) : mixed
Parameters
- $name : string
-
Service name
- $flag : bool
-
Whether or not the service should be shared.
Return values
mixed —validate()
Validate an instance
public
validate(mixed $instance) : void
Parameters
- $instance : mixed
Return values
void —configureAliases()
private
configureAliases(array<string|int, string> $aliases) : void
Parameters
- $aliases : array<string|int, string>
Return values
void —createAliasesForInvokables()
Create aliases for invokable classes.
private
createAliasesForInvokables(array<string|int, mixed> $invokables) : array<string|int, mixed>
If an invokable service name does not match the class it maps to, this creates an alias to the class (which will later be mapped as an invokable factory).
Parameters
- $invokables : array<string|int, mixed>
Return values
array<string|int, mixed> —createDelegatorFromName()
private
createDelegatorFromName(string $name[, null|array<string|int, mixed> $options = null ]) : object
Parameters
- $name : string
- $options : null|array<string|int, mixed> = null
Return values
object —createFactoriesForInvokables()
Create invokable factories for invokable classes.
private
createFactoriesForInvokables(array<string|int, mixed> $invokables) : array<string|int, mixed>
If an invokable service name does not match the class it maps to, this creates an invokable factory entry for the class name; otherwise, it creates an invokable factory for the entry name.
Parameters
- $invokables : array<string|int, mixed>
Return values
array<string|int, mixed> —createLazyServiceDelegatorFactory()
Create the lazy services delegator factory.
private
createLazyServiceDelegatorFactory() : LazyServiceFactory
Creates the lazy services delegator factory based on the lazy_services configuration present.
Tags
Return values
LazyServiceFactory —doCreate()
Create a new instance with an already resolved name
private
doCreate(string $resolvedName[, null|array<string|int, mixed> $options = null ]) : mixed
This is a highly performance sensitive method, do not modify if you have not benchmarked it carefully
Parameters
- $resolvedName : string
- $options : null|array<string|int, mixed> = null
Tags
Return values
mixed —getFactory()
Get a factory for the given service name
private
getFactory(string $name) : callable
Parameters
- $name : string
Tags
Return values
callable —resolveAbstractFactories()
Instantiate abstract factories for to avoid checks during service construction.
private
resolveAbstractFactories(array<string|int, string>|array<string|int, AbstractFactoryInterface> $abstractFactories) : void
Parameters
- $abstractFactories : array<string|int, string>|array<string|int, AbstractFactoryInterface>
Return values
void —resolveAliases()
Resolve aliases to their canonical service names.
private
resolveAliases(array<string|int, string> $aliases) : void
Parameters
- $aliases : array<string|int, string>
Return values
void —resolveInitializers()
Instantiate initializers for to avoid checks during service construction.
private
resolveInitializers(array<string|int, string>|array<string|int, InitializerInterface>|array<string|int, callable> $initializers) : void
Parameters
- $initializers : array<string|int, string>|array<string|int, InitializerInterface>|array<string|int, callable>
Return values
void —resolveNewAliasesWithPreviouslyResolvedAliases()
Rewrites the map of aliases by resolving the given $aliases with the existing resolved ones.
private
resolveNewAliasesWithPreviouslyResolvedAliases(array<string|int, string> $aliases) : void
This is mostly done for performance reasons.
Parameters
- $aliases : array<string|int, string>
Return values
void —validateOverrides()
Determine if one or more services already exist in the container.
private
validateOverrides(array<string|int, mixed> $config) : mixed
If the allow override flag is true or it's first time configured, this method does nothing.
Otherwise, it checks against each of the following service types, if present, and validates that none are defining services that already exist; if they do, it raises an exception indicating modification is not allowed.
Parameters
- $config : array<string|int, mixed>
Tags
Return values
mixed —validateOverrideSet()
Determine if one or more services already exist for a given type.
private
validateOverrideSet(array<string|int, string> $services, string $type) : mixed
Loops through the provided service names, checking if any have current service instances; if not, it returns, but otherwise, it raises an exception indicating modification is not allowed.
Parameters
- $services : array<string|int, string>
- $type : string
-
Type of service being checked.