Adapted to be usable from EL-6 (patch doesn't support rename) From d967c0d39c48a79c3c37ff84d8658240038f4d78 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 26 Oct 2017 12:51:36 +0100 Subject: [PATCH] :fire: Polyfill PatternPluginManager - to allow work with Zend SMv2 and v3 Fixes issue with PHP 7.2 signature compatibility. --- autoload/patternPluginManagerPolyfill.php | 17 +++++ composer.json | 7 +- composer.lock | 2 +- .../PatternPluginManagerTrait.php | 75 +++++++++++++++++++ .../PatternPluginManagerV2Polyfill.php} | 77 +++---------------- .../PatternPluginManagerV3Polyfill.php | 87 ++++++++++++++++++++++ 6 files changed, 197 insertions(+), 68 deletions(-) create mode 100644 autoload/patternPluginManagerPolyfill.php create mode 100644 src/PatternPluginManager/PatternPluginManagerTrait.php rename src/{PatternPluginManager.php => PatternPluginManager/PatternPluginManagerV2Polyfill.php} (51%) create mode 100644 src/PatternPluginManager/PatternPluginManagerV3Polyfill.php diff --git a/autoload/patternPluginManagerPolyfill.php b/autoload/patternPluginManagerPolyfill.php new file mode 100644 index 00000000..4d896fb8 --- /dev/null +++ b/autoload/patternPluginManagerPolyfill.php @@ -0,0 +1,17 @@ +setOptions(new Pattern\PatternOptions($options)); + return $plugin; + } + + /** + * Validate the plugin is of the expected type (v3). + * + * Validates against `$instanceOf`. + * + * @param mixed $instance + * @throws InvalidServiceException + */ + public function validate($instance) + { + if (! $instance instanceof $this->instanceOf) { + throw new InvalidServiceException(sprintf( + '%s can only create instances of %s; %s is invalid', + get_class($this), + $this->instanceOf, + (is_object($instance) ? get_class($instance) : gettype($instance)) + )); + } + } + + /** + * Validate the plugin is of the expected type (v2). + * + * Proxies to `validate()`. + * + * @param mixed $plugin + * @throws Exception\RuntimeException if invalid + */ + public function validatePlugin($plugin) + { + try { + $this->validate($plugin); + } catch (InvalidServiceException $e) { + throw new Exception\RuntimeException($e->getMessage(), $e->getCode(), $e); + } + } +} diff --git a/src/PatternPluginManager.php b/src/PatternPluginManager/PatternPluginManagerV2Polyfill.php --- a/src/PatternPluginManager/PatternPluginManagerV2Polyfill.php +++ b/src/PatternPluginManager/PatternPluginManagerV2Polyfill.php @@ -1,27 +1,27 @@ Pattern\CallbackCache::class, 'Callback' => Pattern\CallbackCache::class, @@ -53,14 +53,14 @@ class PatternPluginManager extends AbstractPluginManager /** * Don't share by default * - * @var boolean + * @var bool */ protected $shareByDefault = false; /** * Don't share by default * - * @var boolean + * @var bool */ protected $sharedByDefault = false; @@ -74,7 +74,7 @@ class PatternPluginManager extends AbstractPluginManager * * {@inheritDoc} */ - public function get($plugin, array $options = [], $usePeeringServiceManagers = true) + public function get($plugin, $options = [], $usePeeringServiceManagers = true) { if (empty($options)) { return parent::get($plugin, [], $usePeeringServiceManagers); @@ -84,57 +84,4 @@ public function get($plugin, array $options = [], $usePeeringServiceManagers = t $plugin->setOptions(new Pattern\PatternOptions($options)); return $plugin; } - - /** - * Override build to inject options as PatternOptions instance. - * - * {@inheritDoc} - */ - public function build($plugin, array $options = null) - { - if (empty($options)) { - return parent::build($plugin); - } - - $plugin = parent::build($plugin); - $plugin->setOptions(new Pattern\PatternOptions($options)); - return $plugin; - } - - /** - * Validate the plugin is of the expected type (v3). - * - * Validates against `$instanceOf`. - * - * @param mixed $instance - * @throws InvalidServiceException - */ - public function validate($instance) - { - if (! $instance instanceof $this->instanceOf) { - throw new InvalidServiceException(sprintf( - '%s can only create instances of %s; %s is invalid', - get_class($this), - $this->instanceOf, - (is_object($instance) ? get_class($instance) : gettype($instance)) - )); - } - } - - /** - * Validate the plugin is of the expected type (v2). - * - * Proxies to `validate()`. - * - * @param mixed $plugin - * @throws Exception\RuntimeException if invalid - */ - public function validatePlugin($plugin) - { - try { - $this->validate($plugin); - } catch (InvalidServiceException $e) { - throw new Exception\RuntimeException($e->getMessage(), $e->getCode(), $e); - } - } } diff --git a/src/PatternPluginManager/PatternPluginManagerV3Polyfill.php b/src/PatternPluginManager/PatternPluginManagerV3Polyfill.php new file mode 100644 index 00000000..c00ef1d5 --- /dev/null +++ b/src/PatternPluginManager/PatternPluginManagerV3Polyfill.php @@ -0,0 +1,87 @@ + Pattern\CallbackCache::class, + 'Callback' => Pattern\CallbackCache::class, + 'capture' => Pattern\CaptureCache::class, + 'Capture' => Pattern\CaptureCache::class, + 'class' => Pattern\ClassCache::class, + 'Class' => Pattern\ClassCache::class, + 'object' => Pattern\ObjectCache::class, + 'Object' => Pattern\ObjectCache::class, + 'output' => Pattern\OutputCache::class, + 'Output' => Pattern\OutputCache::class, + ]; + + protected $factories = [ + Pattern\CallbackCache::class => InvokableFactory::class, + Pattern\CaptureCache::class => InvokableFactory::class, + Pattern\ClassCache::class => InvokableFactory::class, + Pattern\ObjectCache::class => InvokableFactory::class, + Pattern\OutputCache::class => InvokableFactory::class, + + // v2 normalized FQCNs + 'zendcachepatterncallbackcache' => InvokableFactory::class, + 'zendcachepatterncapturecache' => InvokableFactory::class, + 'zendcachepatternclasscache' => InvokableFactory::class, + 'zendcachepatternobjectcache' => InvokableFactory::class, + 'zendcachepatternoutputcache' => InvokableFactory::class, + ]; + + /** + * Don't share by default + * + * @var bool + */ + protected $shareByDefault = false; + + /** + * Don't share by default + * + * @var bool + */ + protected $sharedByDefault = false; + + /** + * @var string + */ + protected $instanceOf = Pattern\PatternInterface::class; + + /** + * Override get to inject options as PatternOptions instance. + * + * {@inheritDoc} + */ + public function get($plugin, array $options = null, $usePeeringServiceManagers = true) + { + if (empty($options)) { + return parent::get($plugin, null, $usePeeringServiceManagers); + } + + $plugin = parent::get($plugin, null, $usePeeringServiceManagers); + $plugin->setOptions(new Pattern\PatternOptions($options)); + return $plugin; + } +}