Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
/zend-mvcPublic archive

Commitcb15aa2

Browse files
committed
Vary PluginManager implementation based on zend-servicemanager version detected
`PluginManager` overrides the `get()` method, which has a differentsignature in v2 than in v3. Until PHP 7.2, this was not a problem;however, in 7.2, even optional values must follow the exact samesignature as the parent. As a result, we now need to vary theimplementations.This patch provides `AbstractPluginManager`, which contains the bulk of thelogic for implementing the `PluginManager`. It then introduces thefollowing:- `PluginManagerSM2`, which extends `AbstractPluginManager` and implements the zend-servicemanager v2 `get()` signature.- `PluginManagerSM3`, which extends `AbstractPluginManager` and implements the zend-servicemanager v3 `get()` signature.It removes the `PluginManager` class.It then adds a file-based autoloader that checks to see if`Zend\ServiceManager\PluginManagerInterface` exists. If it does, italiases `PluginManager` to `PluginManagerSM3`; otherwise, it aliases itto `PluginManagerSM2`.Additionally, this patch updates to zend-servicemanager 2.7.10, whichhas important fixes to how it handles creation options withInvokableFactory that are necessary here.
1 parent7cc1ecf commitcb15aa2

File tree

7 files changed

+103
-36
lines changed

7 files changed

+103
-36
lines changed

‎composer.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
],
99
"homepage":"https://github.com/zendframework/zend-mvc",
1010
"autoload": {
11+
"files": [
12+
"src/autoload.php"
13+
],
1114
"psr-4": {
1215
"Zend\\Mvc\\":"src/"
1316
}
1417
},
1518
"require": {
1619
"php":"^5.5 || ^7.0",
1720
"zendframework/zend-eventmanager":"^2.6.4 || ^3.0",
18-
"zendframework/zend-servicemanager":"^2.7.9 || ^3.0.3",
21+
"zendframework/zend-servicemanager":"^2.7.10 || ^3.0.3",
1922
"zendframework/zend-hydrator":"^1.1 || ^2.4",
2023
"zendframework/zend-form":"^2.11",
2124
"zendframework/zend-stdlib":"^2.7.5 || ^3.0",

‎composer.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎src/Controller/PluginManager.php‎renamed to ‎src/Controller/AbstractPluginManager.php‎

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
5-
* @link http://github.com/zendframework/zf2 for the canonical source repository
6-
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7-
* @license http://framework.zend.com/license/new-bsd New BSD License
3+
* @see https://github.com/zendframework/zend-mvc for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License
86
*/
97

108
namespaceZend\Mvc\Controller;
119

1210
useZend\Mvc\Exception;
13-
useZend\ServiceManager\AbstractPluginManager;
11+
useZend\ServiceManager\AbstractPluginManagerasBasePluginManager;
1412
useZend\ServiceManager\Exception\InvalidServiceException;
1513
useZend\ServiceManager\Factory\InvokableFactory;
1614
useZend\Stdlib\DispatchableInterface;
1715

1816
/**
19-
*Plugin manager implementationforcontrollers
17+
*Base functionalityforthe controller plugins plugin manager.
2018
*
21-
* Registers a number of default plugins, and contains an initializer for
22-
* injecting plugins with the current controller.
19+
* Functionality is split between two concrete implementations as the signatures
20+
* for `get()` vary between zend-servicemanager v2 and v3. The autoloader aliases
21+
* `Zend\Mvc\Controller\PluginManager` to the version-appropriate class, which
22+
* in turn composses this trait.
2323
*/
24-
classPluginManagerextendsAbstractPluginManager
24+
abstractclassAbstractPluginManagerextendsBasePluginManager
2525
{
2626
/**
2727
* Plugins must be of this type.
@@ -106,28 +106,6 @@ class PluginManager extends AbstractPluginManager
106106
*/
107107
protected$controller;
108108

109-
/**
110-
* Retrieve a registered instance
111-
*
112-
* After the plugin is retrieved from the service locator, inject the
113-
* controller in the plugin every time it is requested. This is required
114-
* because a controller can use a plugin and another controller can be
115-
* dispatched afterwards. If this second controller uses the same plugin
116-
* as the first controller, the reference to the controller inside the
117-
* plugin is lost.
118-
*
119-
* @param string $name
120-
* @return DispatchableInterface
121-
*/
122-
publicfunctionget($name,array$options =null,$usePeeringServiceManagers =true)
123-
{
124-
$options =$options ?: [];
125-
$plugin =parent::get($name,$options);
126-
$this->injectController($plugin);
127-
128-
return$plugin;
129-
}
130-
131109
/**
132110
* Set controller
133111
*

‎src/Controller/ControllerManager.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
useZend\EventManager\EventManagerAwareInterface;
1414
useZend\EventManager\SharedEventManagerInterface;
1515
useZend\Mvc\Exception;
16-
useZend\ServiceManager\AbstractPluginManager;
16+
useZend\ServiceManager\AbstractPluginManagerasBasePluginManager;
1717
useZend\ServiceManager\ConfigInterface;
1818
useZend\ServiceManager\Exception\InvalidServiceException;
1919
useZend\ServiceManager\ServiceLocatorAwareInterface;
@@ -24,7 +24,7 @@
2424
*
2525
* Does not define any controllers by default, but does add a validator.
2626
*/
27-
class ControllerManagerextendsAbstractPluginManager
27+
class ControllerManagerextendsBasePluginManager
2828
{
2929
/**
3030
* We do not want arbitrary classes instantiated as controllers.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-mvc for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespaceZend\Mvc\Controller;
9+
10+
useZend\Stdlib\DispatchableInterface;
11+
12+
class PluginManagerSM2extends AbstractPluginManager
13+
{
14+
/**
15+
* Retrieve a registered instance
16+
*
17+
* After the plugin is retrieved from the service locator, inject the
18+
* controller in the plugin every time it is requested. This is required
19+
* because a controller can use a plugin and another controller can be
20+
* dispatched afterwards. If this second controller uses the same plugin
21+
* as the first controller, the reference to the controller inside the
22+
* plugin is lost.
23+
*
24+
* @param string $name
25+
* @return DispatchableInterface
26+
*/
27+
publicfunctionget($name,$options = [],$usePeeringServiceManagers =true)
28+
{
29+
$options =is_array($options) &&empty($options) ?null :$options;
30+
$plugin =parent::get($name,$options);
31+
$this->injectController($plugin);
32+
33+
return$plugin;
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-mvc for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespaceZend\Mvc\Controller;
9+
10+
useZend\Stdlib\DispatchableInterface;
11+
12+
class PluginManagerSM3extends AbstractPluginManager
13+
{
14+
/**
15+
* Retrieve a registered instance
16+
*
17+
* After the plugin is retrieved from the service locator, inject the
18+
* controller in the plugin every time it is requested. This is required
19+
* because a controller can use a plugin and another controller can be
20+
* dispatched afterwards. If this second controller uses the same plugin
21+
* as the first controller, the reference to the controller inside the
22+
* plugin is lost.
23+
*
24+
* @param string $name
25+
* @param null|array $options
26+
* @return DispatchableInterface
27+
*/
28+
publicfunctionget($name,array$options =null)
29+
{
30+
$plugin =parent::get($name,$options);
31+
$this->injectController($plugin);
32+
33+
return$plugin;
34+
}
35+
}

‎src/autoload.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-mvc for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-mvc/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespaceZend\Mvc;
9+
10+
useZend\ServiceManager\PluginManagerInterface;
11+
12+
if (class_exists(PluginManagerInterface::class)) {
13+
class_alias(Controller\PluginManagerSM3::class,Controller\PluginManager::class,true);
14+
}else {
15+
class_alias(Controller\PluginManagerSM2::class,Controller\PluginManager::class,true);
16+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp