FileAccess Orion

PluginManager extends AbstractPluginManager
in package

Plugin manager implementation for cache plugins

Enforces that plugins retrieved are instances of Plugin\PluginInterface. Additionally, it registers a number of default plugins 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  : array<string|int, mixed>
Do not share by default (v2)
$shared  : array<string|int, bool>
Enable/disable shared instances by service name.
$sharedByDefault  : array<string|int, mixed>
Do not share by default (v3)
$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
{@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
validatePlugin()  : void
Validate the plugin
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

$aliases

protected mixed $aliases = ['clear_expired_by_factor' => \Zend\Cache\Storage\Plugin\ClearExpiredByFactor::class, 'clearexpiredbyfactor' => \Zend\Cache\Storage\Plugin\ClearExpiredByFactor::class, 'clearExpiredByFactor' => \Zend\Cache\Storage\Plugin\ClearExpiredByFactor::class, 'ClearExpiredByFactor' => \Zend\Cache\Storage\Plugin\ClearExpiredByFactor::class, 'exception_handler' => \Zend\Cache\Storage\Plugin\ExceptionHandler::class, 'exceptionhandler' => \Zend\Cache\Storage\Plugin\ExceptionHandler::class, 'exceptionHandler' => \Zend\Cache\Storage\Plugin\ExceptionHandler::class, 'ExceptionHandler' => \Zend\Cache\Storage\Plugin\ExceptionHandler::class, 'ignore_user_abort' => \Zend\Cache\Storage\Plugin\IgnoreUserAbort::class, 'ignoreuserabort' => \Zend\Cache\Storage\Plugin\IgnoreUserAbort::class, 'ignoreUserAbort' => \Zend\Cache\Storage\Plugin\IgnoreUserAbort::class, 'IgnoreUserAbort' => \Zend\Cache\Storage\Plugin\IgnoreUserAbort::class, 'optimize_by_factor' => \Zend\Cache\Storage\Plugin\OptimizeByFactor::class, 'optimizebyfactor' => \Zend\Cache\Storage\Plugin\OptimizeByFactor::class, 'optimizeByFactor' => \Zend\Cache\Storage\Plugin\OptimizeByFactor::class, 'OptimizeByFactor' => \Zend\Cache\Storage\Plugin\OptimizeByFactor::class, 'serializer' => \Zend\Cache\Storage\Plugin\Serializer::class, 'Serializer' => \Zend\Cache\Storage\Plugin\Serializer::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

$factories

protected mixed $factories = [ \Zend\Cache\Storage\Plugin\ClearExpiredByFactor::class => \Zend\ServiceManager\Factory\InvokableFactory::class, \Zend\Cache\Storage\Plugin\ExceptionHandler::class => \Zend\ServiceManager\Factory\InvokableFactory::class, \Zend\Cache\Storage\Plugin\IgnoreUserAbort::class => \Zend\ServiceManager\Factory\InvokableFactory::class, \Zend\Cache\Storage\Plugin\OptimizeByFactor::class => \Zend\ServiceManager\Factory\InvokableFactory::class, \Zend\Cache\Storage\Plugin\Serializer::class => \Zend\ServiceManager\Factory\InvokableFactory::class, // v2 normalized FQCNs 'zendcachestoragepluginclearexpiredbyfactor' => \Zend\ServiceManager\Factory\InvokableFactory::class, 'zendcachestoragepluginexceptionhandler' => \Zend\ServiceManager\Factory\InvokableFactory::class, 'zendcachestoragepluginignoreuserabort' => \Zend\ServiceManager\Factory\InvokableFactory::class, 'zendcachestoragepluginoptimizebyfactor' => \Zend\ServiceManager\Factory\InvokableFactory::class, 'zendcachestoragepluginserializer' => \Zend\ServiceManager\Factory\InvokableFactory::class, ]

$instanceOf

An object type that the created instance must be instanced of

protected string $instanceOf = \Zend\Cache\Storage\Plugin\PluginInterface::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

Do not share by default (v2)

protected array<string|int, mixed> $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

Do not share by default (v3)

protected array<string|int, mixed> $sharedByDefault = false

$cachedAbstractFactories

Cached abstract factories from string.

private array<string|int, mixed> $cachedAbstractFactories = []

$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

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
throws
ContainerModificationsNotAllowedException

if the allow override flag has been toggled off, and a service instance exists for a given service.

Return values
self

get()

{@inheritDoc}

public get(mixed $name) : mixed
Parameters
$name : mixed
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
deprecated

since 3.0.0. Factories using 3.0 should use the container instance passed to the factory instead.

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
deprecated

since 3.0.0. The creation context should be passed during instantiation instead.

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

public validatePlugin(mixed $plugin) : void

Checks that the plugin loaded is an instance of Plugin\PluginInterface.

Parameters
$plugin : mixed
Tags
throws
RuntimeException

if invalid

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>

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
throws
ServiceNotFoundException

if unable to resolve the service.

throws
ServiceNotCreatedException

if an exception is raised when creating a service.

throws
ContainerException

if any other error occurs

Return values
mixed

getFactory()

Get a factory for the given service name

private getFactory(string $name) : callable
Parameters
$name : string
Tags
throws
ServiceNotFoundException
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
throws
ContainerModificationsNotAllowedException

if any services provided already have instances available.

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.

Tags
throws
ContainerModificationsNotAllowedException

if any services provided already have instances available.

Return values
mixed

Search results