1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
Adapted to be usable from EL-6 (patch doesn't support rename)
From d967c0d39c48a79c3c37ff84d8658240038f4d78 Mon Sep 17 00:00:00 2001
From: webimpress <contact@webimpress.com>
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 @@
+<?php
+/**
+ * @see https://github.com/zendframework/zend-cache for the canonical source repository
+ * @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
+ */
+
+use Zend\Cache\PatternPluginManager;
+use Zend\ServiceManager\ServiceManager;
+
+call_user_func(function () {
+ $target = method_exists(ServiceManager::class, 'configure')
+ ? PatternPluginManager\PatternPluginManagerV3Polyfill::class
+ : PatternPluginManager\PatternPluginManagerV2Polyfill::class;
+
+ class_alias($target, PatternPluginManager::class);
+});
diff --git a/src/PatternPluginManager/PatternPluginManagerTrait.php b/src/PatternPluginManager/PatternPluginManagerTrait.php
new file mode 100644
index 00000000..8c6f2b27
--- /dev/null
+++ b/src/PatternPluginManager/PatternPluginManagerTrait.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * @see https://github.com/zendframework/zend-cache for the canonical source repository
+ * @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
+ */
+
+namespace Zend\Cache\PatternPluginManager;
+
+use Zend\Cache\Exception;
+use Zend\Cache\Pattern;
+use Zend\ServiceManager\Exception\InvalidServiceException;
+
+/**
+ * Trait providing common logic between FormElementManager implementations.
+ *
+ * Trait does not define properties, as the properties common between the
+ * two versions are originally defined in their parent class, causing a
+ * resolution conflict.
+ */
+trait PatternPluginManagerTrait
+{
+ /**
+ * 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.php b/src/PatternPluginManager/PatternPluginManagerV2Polyfill.php
--- a/src/PatternPluginManager/PatternPluginManagerV2Polyfill.php
+++ b/src/PatternPluginManager/PatternPluginManagerV2Polyfill.php
@@ -1,27 +1,27 @@
<?php
/**
- * Zend Framework (http://framework.zend.com/)
- *
- * @link http://github.com/zendframework/zf2 for the canonical source repository
- * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @see https://github.com/zendframework/zend-cache for the canonical source repository
+ * @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
*/
-namespace Zend\Cache;
+namespace Zend\Cache\PatternPluginManager;
+use Zend\Cache\Pattern;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Factory\InvokableFactory;
-use Zend\ServiceManager\Exception\InvalidServiceException;
/**
- * Plugin manager implementation for cache pattern adapters
+ * zend-servicemanager v2-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.
*/
-class PatternPluginManager extends AbstractPluginManager
+class PatternPluginManagerV2Polyfill extends AbstractPluginManager
{
+ use PatternPluginManagerTrait;
+
protected $aliases = [
'callback' => 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 @@
+<?php
+/**
+ * @see https://github.com/zendframework/zend-cache for the canonical source repository
+ * @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license https://github.com/zendframework/zend-cache/blob/master/LICENSE.md New BSD License
+ */
+
+namespace Zend\Cache\PatternPluginManager;
+
+use Zend\Cache\Pattern;
+use Zend\ServiceManager\AbstractPluginManager;
+use Zend\ServiceManager\Factory\InvokableFactory;
+
+/**
+ * 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.
+ */
+class PatternPluginManagerV3Polyfill extends AbstractPluginManager
+{
+ use PatternPluginManagerTrait;
+
+ protected $aliases = [
+ 'callback' => 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;
+ }
+}
|