fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / zendframework / zend-cache / src / PatternPluginManager.php
blobefaf18b7687f5c45d3a70bfcc3feb5a1a5d04a16
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Cache;
12 use Zend\ServiceManager\AbstractPluginManager;
13 use Zend\ServiceManager\Factory\InvokableFactory;
14 use Zend\ServiceManager\Exception\InvalidServiceException;
16 /**
17 * Plugin manager implementation for cache pattern adapters
19 * Enforces that retrieved adapters are instances of
20 * Pattern\PatternInterface. Additionally, it registers a number of default
21 * patterns available.
23 class PatternPluginManager extends AbstractPluginManager
25 protected $aliases = [
26 'callback' => Pattern\CallbackCache::class,
27 'Callback' => Pattern\CallbackCache::class,
28 'capture' => Pattern\CaptureCache::class,
29 'Capture' => Pattern\CaptureCache::class,
30 'class' => Pattern\ClassCache::class,
31 'Class' => Pattern\ClassCache::class,
32 'object' => Pattern\ObjectCache::class,
33 'Object' => Pattern\ObjectCache::class,
34 'output' => Pattern\OutputCache::class,
35 'Output' => Pattern\OutputCache::class,
38 protected $factories = [
39 Pattern\CallbackCache::class => InvokableFactory::class,
40 Pattern\CaptureCache::class => InvokableFactory::class,
41 Pattern\ClassCache::class => InvokableFactory::class,
42 Pattern\ObjectCache::class => InvokableFactory::class,
43 Pattern\OutputCache::class => InvokableFactory::class,
45 // v2 normalized FQCNs
46 'zendcachepatterncallbackcache' => InvokableFactory::class,
47 'zendcachepatterncapturecache' => InvokableFactory::class,
48 'zendcachepatternclasscache' => InvokableFactory::class,
49 'zendcachepatternobjectcache' => InvokableFactory::class,
50 'zendcachepatternoutputcache' => InvokableFactory::class,
53 /**
54 * Don't share by default
56 * @var boolean
58 protected $shareByDefault = false;
60 /**
61 * Don't share by default
63 * @var boolean
65 protected $sharedByDefault = false;
67 /**
68 * @var string
70 protected $instanceOf = Pattern\PatternInterface::class;
72 /**
73 * Override get to inject options as PatternOptions instance.
75 * {@inheritDoc}
77 public function get($plugin, array $options = [], $usePeeringServiceManagers = true)
79 if (empty($options)) {
80 return parent::get($plugin, [], $usePeeringServiceManagers);
83 $plugin = parent::get($plugin, [], $usePeeringServiceManagers);
84 $plugin->setOptions(new Pattern\PatternOptions($options));
85 return $plugin;
88 /**
89 * Override build to inject options as PatternOptions instance.
91 * {@inheritDoc}
93 public function build($plugin, array $options = null)
95 if (empty($options)) {
96 return parent::build($plugin);
99 $plugin = parent::build($plugin);
100 $plugin->setOptions(new Pattern\PatternOptions($options));
101 return $plugin;
105 * Validate the plugin is of the expected type (v3).
107 * Validates against `$instanceOf`.
109 * @param mixed $instance
110 * @throws InvalidServiceException
112 public function validate($instance)
114 if (! $instance instanceof $this->instanceOf) {
115 throw new InvalidServiceException(sprintf(
116 '%s can only create instances of %s; %s is invalid',
117 get_class($this),
118 $this->instanceOf,
119 (is_object($instance) ? get_class($instance) : gettype($instance))
125 * Validate the plugin is of the expected type (v2).
127 * Proxies to `validate()`.
129 * @param mixed $plugin
130 * @throws Exception\RuntimeException if invalid
132 public function validatePlugin($plugin)
134 try {
135 $this->validate($plugin);
136 } catch (InvalidServiceException $e) {
137 throw new Exception\RuntimeException($e->getMessage(), $e->getCode(), $e);