PatternPluginManagerV3Polyfill
extends AbstractPluginManager
in package
Uses
PatternPluginManagerTrait
zend-servicemanager v3-compatible plugin manager implementation for cache pattern adapters.
Enforces that retrieved adapters are instances of Pattern\PatternInterface. Additionally, it registers a number of default patterns available.
Table of Contents
- $abstractFactories : array<string|int, AbstractFactoryInterface>
- $aliases : mixed
- $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 : mixed
- $initializers : array<string|int, InitializerInterface>|array<string|int, callable>
- $instanceOf : 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)
- $shareByDefault : bool
- Don't share by default
- $shared : array<string|int, bool>
- Enable/disable shared instances by service name.
- $sharedByDefault : bool
- Don't share 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
- Configure the service manager
- get() : mixed
- Override get to inject options as PatternOptions instance.
- 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
- validatePlugin() : mixed
- Validate the plugin is of the expected type (v2).
- 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
protected
mixed
$aliases
= ['callback' => \Zend\Cache\Pattern\CallbackCache::class, 'Callback' => \Zend\Cache\Pattern\CallbackCache::class, 'capture' => \Zend\Cache\Pattern\CaptureCache::class, 'Capture' => \Zend\Cache\Pattern\CaptureCache::class, 'class' => \Zend\Cache\Pattern\ClassCache::class, 'Class' => \Zend\Cache\Pattern\ClassCache::class, 'object' => \Zend\Cache\Pattern\ObjectCache::class, 'Object' => \Zend\Cache\Pattern\ObjectCache::class, 'output' => \Zend\Cache\Pattern\OutputCache::class, 'Output' => \Zend\Cache\Pattern\OutputCache::class]
$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
protected
mixed
$factories
= [
\Zend\Cache\Pattern\CallbackCache::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
\Zend\Cache\Pattern\CaptureCache::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
\Zend\Cache\Pattern\ClassCache::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
\Zend\Cache\Pattern\ObjectCache::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
\Zend\Cache\Pattern\OutputCache::class => \Zend\ServiceManager\Factory\InvokableFactory::class,
// v2 normalized FQCNs
'zendcachepatterncallbackcache' => \Zend\ServiceManager\Factory\InvokableFactory::class,
'zendcachepatterncapturecache' => \Zend\ServiceManager\Factory\InvokableFactory::class,
'zendcachepatternclasscache' => \Zend\ServiceManager\Factory\InvokableFactory::class,
'zendcachepatternobjectcache' => \Zend\ServiceManager\Factory\InvokableFactory::class,
'zendcachepatternoutputcache' => \Zend\ServiceManager\Factory\InvokableFactory::class,
]
$initializers
protected
array<string|int, InitializerInterface>|array<string|int, callable>
$initializers
= []
$instanceOf
An object type that the created instance must be instanced of
protected
string
$instanceOf
= \Zend\Cache\Pattern\PatternInterface::class
$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
= []
$shareByDefault
Don't share by default
protected
bool
$shareByDefault
= false
$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
Don't share by default
protected
bool
$sharedByDefault
= false
$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([array<string|int, mixed> $config = [] ]) : mixed
See ServiceManager::configure() for details on what $config accepts.
Parameters
- $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()
Configure the service manager
public
configure(array<string|int, mixed> $config) : self
Valid top keys are:
- services: service name => service instance pairs
- invokables: service name => class name pairs for classes that do not have required constructor arguments; internally, maps the class to an InvokableFactory instance, and creates an alias if the service name and class name do not match.
- factories: service name => factory pairs; factories may be any callable, string name resolving to an invokable class, or string name resolving to a FactoryInterface instance.
- abstract_factories: an array of abstract factories; these may be instances of AbstractFactoryInterface, or string names resolving to classes that implement that interface.
- delegators: service name => list of delegator factories for the given service; each item in the list may be a callable, a string name resolving to an invokable class, or a string name resolving to a class implementing DelegatorFactoryInterface.
- shared: service name => flag pairs; the flag is a boolean indicating whether or not the service is shared.
- aliases: alias => service name pairs.
- lazy_services: lazy service configuration; can contain the keys:
- class_map: service name => class name pairs.
- proxies_namespace: string namespace to use for generated proxy classes.
- proxies_target_dir: directory in which to write generated proxy classes; uses system temporary by default.
- write_proxy_files: boolean indicating whether generated proxy classes should be written; defaults to boolean false.
- shared_by_default: boolean, indicating if services in this instance should be shared by default.
Parameters
- $config : array<string|int, mixed>
Tags
Return values
self —get()
Override get to inject options as PatternOptions instance.
public
get(mixed $plugin[, array<string|int, mixed> $options = null ][, mixed $usePeeringServiceManagers = true ]) : mixed
Parameters
- $plugin : mixed
- $options : array<string|int, mixed> = null
-
Options to use when creating the instance.
- $usePeeringServiceManagers : mixed = true
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 —validatePlugin()
Validate the plugin is of the expected type (v2).
public
validatePlugin(mixed $plugin) : mixed
Proxies to validate()
.
Parameters
- $plugin : mixed
Tags
Return values
mixed —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.