Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit c50ca92

Browse files
committed
Get tests passing against zend-servicemanager v2
1 parent c1677f9 commit c50ca92

File tree

57 files changed

+748
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+748
-502
lines changed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"zendframework/zend-inputfilter": "^2.6",
3434
"zendframework/zend-json": "^2.6.1",
3535
"zendframework/zend-log": "^2.7.1",
36-
"zendframework/zend-modulemanager": "^2.7",
36+
"zendframework/zend-modulemanager": "^2.7.1",
3737
"zendframework/zend-session": "^2.6.2",
3838
"zendframework/zend-serializer": "^2.6.1",
3939
"zendframework/zend-text": "^2.6",
@@ -64,12 +64,10 @@
6464
"zendframework/zend-version": "Zend\\Version component",
6565
"zendframework/zend-view": "Zend\\View component"
6666
},
67-
"minimum-stability": "dev",
68-
"prefer-stable": true,
6967
"extra": {
7068
"branch-alias": {
7169
"dev-master": "2.6-dev",
72-
"dev-develop": "3.0-dev"
70+
"dev-develop": "2.7-dev"
7371
}
7472
},
7573
"autoload-dev": {

src/Application.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,15 @@ public function run()
315315

316316
// Trigger route event
317317
$event->setName(MvcEvent::EVENT_ROUTE);
318+
$event->stopPropagation(false); // Clear before triggering
318319
$result = $events->triggerEventUntil($shortCircuit, $event);
319320
if ($result->stopped()) {
320321
$response = $result->last();
321322
if ($response instanceof ResponseInterface) {
322323
$event->setName(MvcEvent::EVENT_FINISH);
323324
$event->setTarget($this);
324325
$event->setResponse($response);
326+
$event->stopPropagation(false); // Clear before triggering
325327
$events->triggerEvent($event);
326328
$this->response = $response;
327329
return $this;
@@ -334,6 +336,7 @@ public function run()
334336

335337
// Trigger dispatch event
336338
$event->setName(MvcEvent::EVENT_DISPATCH);
339+
$event->stopPropagation(false); // Clear before triggering
337340
$result = $events->triggerEventUntil($shortCircuit, $event);
338341

339342
// Complete response
@@ -342,6 +345,7 @@ public function run()
342345
$event->setName(MvcEvent::EVENT_FINISH);
343346
$event->setTarget($this);
344347
$event->setResponse($response);
348+
$event->stopPropagation(false); // Clear before triggering
345349
$events->triggerEvent($event);
346350
$this->response = $response;
347351
return $this;
@@ -376,9 +380,11 @@ protected function completeRequest(MvcEvent $event)
376380
$event->setTarget($this);
377381

378382
$event->setName(MvcEvent::EVENT_RENDER);
383+
$event->stopPropagation(false); // Clear before triggering
379384
$events->triggerEvent($event);
380385

381386
$event->setName(MvcEvent::EVENT_FINISH);
387+
$event->stopPropagation(false); // Clear before triggering
382388
$events->triggerEvent($event);
383389

384390
return $this;

src/Controller/ControllerManager.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function validatePlugin($plugin)
107107
* @param DispatchableInterface|ContainerInterface $second Controller when
108108
* using zend-servicemanager v3; container under v2.
109109
*/
110-
public function injectEventManager(ContainerInterface $container, $controller)
110+
public function injectEventManager($first, $second)
111111
{
112112
if ($first instanceof ContainerInterface) {
113113
$container = $first;
@@ -123,6 +123,11 @@ public function injectEventManager(ContainerInterface $container, $controller)
123123

124124
$events = $controller->getEventManager();
125125
if (! $events || ! $events->getSharedManager() instanceof SharedEventManagerInterface) {
126+
// For v2, we need to pull the parent service locator
127+
if (! method_exists($container, 'configure')) {
128+
$container = $container->getServiceLocator() ?: $container;
129+
}
130+
126131
$controller->setEventManager($container->get('EventManager'));
127132
}
128133
}
@@ -135,7 +140,7 @@ public function injectEventManager(ContainerInterface $container, $controller)
135140
* @param DispatchableInterface|ContainerInterface $second Controller when
136141
* using zend-servicemanager v3; container under v2.
137142
*/
138-
public function injectConsole(ContainerInterface $container, $controller)
143+
public function injectConsole($first, $second)
139144
{
140145
if ($first instanceof ContainerInterface) {
141146
$container = $first;
@@ -149,6 +154,11 @@ public function injectConsole(ContainerInterface $container, $controller)
149154
return;
150155
}
151156

157+
// For v2, we need to pull the parent service locator
158+
if (! method_exists($container, 'configure')) {
159+
$container = $container->getServiceLocator() ?: $container;
160+
}
161+
152162
$controller->setConsole($container->get('Console'));
153163
}
154164

@@ -160,7 +170,7 @@ public function injectConsole(ContainerInterface $container, $controller)
160170
* @param DispatchableInterface|ContainerInterface $second Controller when
161171
* using zend-servicemanager v3; container under v2.
162172
*/
163-
public function injectPluginManager(ContainerInterface $container, $controller)
173+
public function injectPluginManager($first, $second)
164174
{
165175
if ($first instanceof ContainerInterface) {
166176
$container = $first;
@@ -174,6 +184,11 @@ public function injectPluginManager(ContainerInterface $container, $controller)
174184
return;
175185
}
176186

187+
// For v2, we need to pull the parent service locator
188+
if (! method_exists($container, 'configure')) {
189+
$container = $container->getServiceLocator() ?: $container;
190+
}
191+
177192
$controller->setPluginManager($container->get('ControllerPluginManager'));
178193
}
179194
}

src/Controller/Plugin/Forward.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
177177
$results[$id] = [];
178178
foreach ($eventArray as $eventName => $classArray) {
179179
$results[$id][$eventName] = [];
180-
$events = $sharedEvents->getListeners([$id], $eventName);
180+
$events = $sharedEvents->getListeners($id, $eventName) ?: [];
181181
foreach ($events as $currentEvent) {
182182
$currentCallback = $currentEvent;
183183

src/Controller/Plugin/Service/ForwardFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function __invoke(ContainerInterface $container, $name, array $options =
4747
*/
4848
public function createService(ServiceLocatorInterface $container)
4949
{
50-
return $this($container, Forward::class);
50+
$parentContainer = $container->getServiceLocator() ?: $container;
51+
return $this($parentContainer, Forward::class);
5152
}
5253
}

src/Controller/Plugin/Service/IdentityFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public function __invoke(ContainerInterface $container, $name, array $options =
4141
*/
4242
public function createService(ServiceLocatorInterface $container)
4343
{
44+
// Retrieve the parent container when under zend-servicemanager v2
45+
if (! method_exists($container, 'configure')) {
46+
$container = $container->getServiceLocator() ?: $container;
47+
}
48+
4449
return $this($container, Identity::class);
4550
}
4651
}

src/DispatchListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public function onDispatch(MvcEvent $e)
9292

9393
try {
9494
$controller = $controllerManager->get($controllerName);
95+
} catch (Exception\InvalidControllerException $exception) {
96+
$return = $this->marshalControllerNotFoundEvent($application::ERROR_CONTROLLER_INVALID, $controllerName, $e, $application, $exception);
97+
return $this->complete($return, $e);
9598
} catch (InvalidServiceException $exception) {
9699
$return = $this->marshalControllerNotFoundEvent($application::ERROR_CONTROLLER_INVALID, $controllerName, $e, $application, $exception);
97100
return $this->complete($return, $e);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
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
8+
*/
9+
10+
namespace Zend\Mvc\Exception;
11+
12+
class InvalidControllerException extends \Exception implements ExceptionInterface
13+
{
14+
}

src/Router/Console/SimpleRouteStack.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
use Traversable;
1313
use Zend\Mvc\Router\Exception;
14+
use Zend\Mvc\Router\RouteInvokableFactory;
1415
use Zend\Mvc\Router\SimpleRouteStack as BaseSimpleRouteStack;
16+
use Zend\ServiceManager\Config;
1517
use Zend\Stdlib\ArrayUtils;
1618

1719
/**
@@ -26,11 +28,24 @@ class SimpleRouteStack extends BaseSimpleRouteStack
2628
*/
2729
protected function init()
2830
{
29-
$routes = $this->routePluginManager;
30-
$this->routePluginManager = $routes->withConfig(['invokables' => [
31-
'catchall' => __NAMESPACE__ . '\Catchall',
32-
'simple' => __NAMESPACE__ . '\Simple',
33-
]]);
31+
(new Config([
32+
'aliases' => [
33+
'catchall' => Catchall::class,
34+
'catchAll' => Catchall::class,
35+
'Catchall' => Catchall::class,
36+
'CatchAll' => Catchall::class,
37+
'simple' => Simple::class,
38+
'Simple' => Simple::class,
39+
],
40+
'factories' => [
41+
Catchall::class => RouteInvokableFactory::class,
42+
Simple::class => RouteInvokableFactory::class,
43+
44+
// v2 normalized names
45+
'zendmvcrouterconsoleCatchall' => RouteInvokableFactory::class,
46+
'zendmvcrouterconsoleSimple' => RouteInvokableFactory::class,
47+
],
48+
]))->configureServiceManager($this->routePluginManager);
3449
}
3550

3651
/**

src/Router/Http/TreeRouteStack.php

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use ArrayObject;
1313
use Traversable;
1414
use Zend\Mvc\Router\Exception;
15+
use Zend\Mvc\Router\RouteInvokableFactory;
1516
use Zend\Mvc\Router\SimpleRouteStack;
17+
use Zend\ServiceManager\Config;
1618
use Zend\Stdlib\ArrayUtils;
1719
use Zend\Stdlib\RequestInterface as Request;
1820
use Zend\Uri\Http as HttpUri;
@@ -58,7 +60,9 @@ public static function factory($options = [])
5860
{
5961
if ($options instanceof Traversable) {
6062
$options = ArrayUtils::iteratorToArray($options);
61-
} elseif (!is_array($options)) {
63+
}
64+
65+
if (! is_array($options)) {
6266
throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable set of options');
6367
}
6468

@@ -80,33 +84,59 @@ protected function init()
8084
{
8185
$this->prototypes = new ArrayObject;
8286

83-
$routes = $this->routePluginManager;
84-
$this->routePluginManager = $routes->withConfig([
87+
(new Config([
8588
'aliases' => [
86-
'Chain' => 'chain',
87-
'Hostname' => 'hostname',
88-
'Literal' => 'literal',
89-
'Method' => 'method',
90-
'Part' => 'part',
91-
'Query' => 'query',
92-
'Regex' => 'regex',
93-
'Scheme' => 'scheme',
94-
'Segment' => 'segment',
95-
'Wildcard' => 'wildcard',
89+
'chain' => Chain::class,
90+
'Chain' => Chain::class,
91+
'hostname' => Hostname::class,
92+
'Hostname' => Hostname::class,
93+
'hostName' => Hostname::class,
94+
'HostName' => Hostname::class,
95+
'literal' => Literal::class,
96+
'Literal' => Literal::class,
97+
'method' => Method::class,
98+
'Method' => Method::class,
99+
'part' => Part::class,
100+
'Part' => Part::class,
101+
'query' => Query::class,
102+
'Query' => Query::class,
103+
'regex' => Regex::class,
104+
'Regex' => Regex::class,
105+
'scheme' => Scheme::class,
106+
'Scheme' => Scheme::class,
107+
'segment' => Segment::class,
108+
'Segment' => Segment::class,
109+
'wildcard' => Wildcard::class,
110+
'Wildcard' => Wildcard::class,
111+
'wildCard' => Wildcard::class,
112+
'WildCard' => Wildcard::class,
96113
],
97-
'invokables' => [
98-
'chain' => __NAMESPACE__ . '\Chain',
99-
'hostname' => __NAMESPACE__ . '\Hostname',
100-
'literal' => __NAMESPACE__ . '\Literal',
101-
'method' => __NAMESPACE__ . '\Method',
102-
'part' => __NAMESPACE__ . '\Part',
103-
'query' => __NAMESPACE__ . '\Query',
104-
'regex' => __NAMESPACE__ . '\Regex',
105-
'scheme' => __NAMESPACE__ . '\Scheme',
106-
'segment' => __NAMESPACE__ . '\Segment',
107-
'wildcard' => __NAMESPACE__ . '\Wildcard',
114+
'factories' => [
115+
Chain::class => RouteInvokableFactory::class,
116+
Hostname::class => RouteInvokableFactory::class,
117+
Literal::class => RouteInvokableFactory::class,
118+
Method::class => RouteInvokableFactory::class,
119+
Part::class => RouteInvokableFactory::class,
120+
Query::class => RouteInvokableFactory::class,
121+
Regex::class => RouteInvokableFactory::class,
122+
Scheme::class => RouteInvokableFactory::class,
123+
Segment::class => RouteInvokableFactory::class,
124+
Wildcard::class => RouteInvokableFactory::class,
125+
126+
// v2 normalized names
127+
128+
'zendmvcrouterhttpchain' => RouteInvokableFactory::class,
129+
'zendmvcrouterhttphostname' => RouteInvokableFactory::class,
130+
'zendmvcrouterhttpliteral' => RouteInvokableFactory::class,
131+
'zendmvcrouterhttpmethod' => RouteInvokableFactory::class,
132+
'zendmvcrouterhttppart' => RouteInvokableFactory::class,
133+
'zendmvcrouterhttpquery' => RouteInvokableFactory::class,
134+
'zendmvcrouterhttpregex' => RouteInvokableFactory::class,
135+
'zendmvcrouterhttpscheme' => RouteInvokableFactory::class,
136+
'zendmvcrouterhttpsegment' => RouteInvokableFactory::class,
137+
'zendmvcrouterhttpwildcard' => RouteInvokableFactory::class,
108138
],
109-
]);
139+
]))->configureServiceManager($this->routePluginManager);
110140
}
111141

112142
/**

0 commit comments

Comments
 (0)