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

Commit 5c41367

Browse files
committed
Fixed unit test issue
2 parents 47ac19a + c6b02a9 commit 5c41367

Some content is hidden

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

55 files changed

+662
-467
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/doc export-ignore
12
/test export-ignore
23
/vendor export-ignore
34
.coveralls.yml export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.*.sw*
77
.*.un~
88
nbproject
9+
doc/html/
910
tmp/
1011

1112
clover.xml

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.7.0 - TBD
5+
## 3.0.0 - TBD
66

77
### Added
88

9-
- Nothing.
9+
- [#31](https://github.com/zendframework/zend-mvc/pull/31) adds three required
10+
arguments to the `Zend\Mvc\Application` constructor: an EventManager
11+
instance, a Request instance, and a Response instance.
1012

1113
### Deprecated
1214

@@ -18,6 +20,9 @@ All notable changes to this project will be documented in this file, in reverse
1820

1921
### Fixed
2022

23+
- [#31](https://github.com/zendframework/zend-mvc/pull/31) updates the component
24+
to use zend-eventmanager v3.
25+
2126
## 2.6.1 - TBD
2227

2328
### Added

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
},
1515
"require": {
1616
"php": ">=5.5",
17-
"zendframework/zend-eventmanager": "~2.5",
17+
"zendframework/zend-eventmanager": "dev-develop as 2.7.0",
1818
"zendframework/zend-servicemanager": "~2.5",
1919
"zendframework/zend-hydrator": "~1.0",
2020
"zendframework/zend-form": "~2.6",
2121
"zendframework/zend-stdlib": "~2.7",
22-
"zendframework/zend-psr7bridge": "^0.2"
22+
"zendframework/zend-psr7bridge": "^0.2",
23+
"container-interop/container-interop": "^1.1"
2324
},
2425
"require-dev": {
2526
"zendframework/zend-authentication": "~2.5",
@@ -32,14 +33,14 @@
3233
"zendframework/zend-inputfilter": "~2.5",
3334
"zendframework/zend-json": "~2.5",
3435
"zendframework/zend-log": "~2.5",
35-
"zendframework/zend-modulemanager": "~2.6",
36+
"zendframework/zend-modulemanager": "dev-develop as 2.7.0",
3637
"zendframework/zend-session": "~2.5",
3738
"zendframework/zend-serializer": "~2.5",
3839
"zendframework/zend-text": "~2.5",
3940
"zendframework/zend-uri": "~2.5",
4041
"zendframework/zend-validator": "~2.5",
4142
"zendframework/zend-version": "~2.5",
42-
"zendframework/zend-view": "~2.5",
43+
"zendframework/zend-view": "dev-develop as 2.6.0",
4344
"fabpot/php-cs-fixer": "1.7.*",
4445
"phpunit/PHPUnit": "~4.0"
4546
},
@@ -68,7 +69,7 @@
6869
"extra": {
6970
"branch-alias": {
7071
"dev-master": "2.6-dev",
71-
"dev-develop": "2.7-dev"
72+
"dev-develop": "3.0-dev"
7273
}
7374
},
7475
"autoload-dev": {

doc/book/migration.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Migration Guide
2+
3+
This is a guide for migration from version 2 to version 3 of zend-mvc.
4+
5+
## Application
6+
7+
The constructor signature of `Zend\Mvc\Application` has changed. Previously, it
8+
was:
9+
10+
```php
11+
__construct($configuration, ServiceManager $serviceManager)
12+
```
13+
14+
and internally, it pulled the services `EventManager`, `Request`, and `Response`
15+
from the provided `$serviceManager` during initialization.
16+
17+
The new constructor signature is:
18+
19+
```php
20+
__construct(
21+
$configuration,
22+
ServiceManager $serviceManager,
23+
EventManager $events,
24+
RequestInterface $request,
25+
ResponseInterface $response
26+
)
27+
```
28+
29+
making all dependencies explicit. The factory
30+
`Zend\Mvc\Service\ApplicationFactory` was updated to follow the new signature.
31+
32+
This change should only affect users who are manually instantiating the
33+
`Application` instance.
34+
35+
## EventManager initializer and ControllerManager event manager injection
36+
37+
zend-mvc provides two mechanisms for injecting event managers into
38+
`EventManagerAware` objects. One is the "EventManagerAwareInitializer"
39+
registered in `Zend\Mvc\Service\ServiceManagerConfig`, and the other is internal
40+
logic in `Zend\Mvc\Controller\ControllerManager`. In both cases, the logic was
41+
updated due to changes in the v3 version of zend-eventmanager.
42+
43+
Previously each would check if the instance's `getEventManager()` method
44+
returned an event manager instance, and, if so, inject the shared event manager:
45+
46+
```php
47+
$events = $instance->getEventManager();
48+
if ($events instanceof EventManagerInterface) {
49+
$events->setSharedManager($container->get('SharedEventManager'));
50+
}
51+
```
52+
53+
In zend-eventmanager v3, event manager's are now injected with the shared
54+
manager at instantiation, and no setter exists for providing the shared manager.
55+
As such, the above logic changed to:
56+
57+
```php
58+
$events = $instance->getEventManager();
59+
if (! $events || ! $events->getSharedManager()) {
60+
$instance->setEventManager($container->get('EventManager'));
61+
}
62+
```
63+
64+
In other words, it re-injects with a new event manager instance if the instance
65+
pulled does not have a shared manager composed.
66+
67+
This likely will not cause regressions in existing code, but may be something to
68+
be aware of if you were previously depending on lazy-loaded event manager
69+
state.

doc/bookdown.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"title": "zend-mvc: MVC application provider",
3+
"content": [
4+
{"Intro": "../README.md"},
5+
{"Migration Guide": "book/migration.md"}
6+
],
7+
"target": "./html"
8+
}

src/Application.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Zend\EventManager\EventManagerAwareInterface;
1313
use Zend\EventManager\EventManagerInterface;
1414
use Zend\ServiceManager\ServiceManager;
15+
use Zend\Stdlib\RequestInterface;
1516
use Zend\Stdlib\ResponseInterface;
1617

1718
/**
@@ -106,15 +107,18 @@ class Application implements
106107
* @param mixed $configuration
107108
* @param ServiceManager $serviceManager
108109
*/
109-
public function __construct($configuration, ServiceManager $serviceManager)
110-
{
110+
public function __construct(
111+
$configuration,
112+
ServiceManager $serviceManager,
113+
EventManagerInterface $events,
114+
RequestInterface $request,
115+
ResponseInterface $response
116+
) {
111117
$this->configuration = $configuration;
112118
$this->serviceManager = $serviceManager;
113-
114-
$this->setEventManager($serviceManager->get('EventManager'));
115-
116-
$this->request = $serviceManager->get('Request');
117-
$this->response = $serviceManager->get('Response');
119+
$this->setEventManager($events);
120+
$this->request = $request;
121+
$this->response = $response;
118122
}
119123

120124
/**
@@ -145,19 +149,20 @@ public function bootstrap(array $listeners = [])
145149
$listeners = array_unique(array_merge($this->defaultListeners, $listeners));
146150

147151
foreach ($listeners as $listener) {
148-
$events->attach($serviceManager->get($listener));
152+
$serviceManager->get($listener)->attach($events);
149153
}
150154

151155
// Setup MVC Event
152156
$this->event = $event = new MvcEvent();
157+
$event->setName(MvcEvent::EVENT_BOOTSTRAP);
153158
$event->setTarget($this);
154-
$event->setApplication($this)
155-
->setRequest($this->request)
156-
->setResponse($this->response)
157-
->setRouter($serviceManager->get('Router'));
159+
$event->setApplication($this);
160+
$event->setRequest($this->request);
161+
$event->setResponse($this->response);
162+
$event->setRouter($serviceManager->get('Router'));
158163

159164
// Trigger bootstrap events
160-
$events->trigger(MvcEvent::EVENT_BOOTSTRAP, $event);
165+
$events->triggerEvent($event);
161166
return $this;
162167
}
163168

@@ -297,13 +302,15 @@ public function run()
297302
};
298303

299304
// Trigger route event
300-
$result = $events->trigger(MvcEvent::EVENT_ROUTE, $event, $shortCircuit);
305+
$event->setName(MvcEvent::EVENT_ROUTE);
306+
$result = $events->triggerEventUntil($shortCircuit, $event);
301307
if ($result->stopped()) {
302308
$response = $result->last();
303309
if ($response instanceof ResponseInterface) {
310+
$event->setName(MvcEvent::EVENT_FINISH);
304311
$event->setTarget($this);
305312
$event->setResponse($response);
306-
$events->trigger(MvcEvent::EVENT_FINISH, $event);
313+
$events->triggerEvent($event);
307314
$this->response = $response;
308315
return $this;
309316
}
@@ -314,14 +321,16 @@ public function run()
314321
}
315322

316323
// Trigger dispatch event
317-
$result = $events->trigger(MvcEvent::EVENT_DISPATCH, $event, $shortCircuit);
324+
$event->setName(MvcEvent::EVENT_DISPATCH);
325+
$result = $events->triggerEventUntil($shortCircuit, $event);
318326

319327
// Complete response
320328
$response = $result->last();
321329
if ($response instanceof ResponseInterface) {
330+
$event->setName(MvcEvent::EVENT_FINISH);
322331
$event->setTarget($this);
323332
$event->setResponse($response);
324-
$events->trigger(MvcEvent::EVENT_FINISH, $event);
333+
$events->triggerEvent($event);
325334
$this->response = $response;
326335
return $this;
327336
}
@@ -353,8 +362,13 @@ protected function completeRequest(MvcEvent $event)
353362
{
354363
$events = $this->events;
355364
$event->setTarget($this);
356-
$events->trigger(MvcEvent::EVENT_RENDER, $event);
357-
$events->trigger(MvcEvent::EVENT_FINISH, $event);
365+
366+
$event->setName(MvcEvent::EVENT_RENDER);
367+
$events->triggerEvent($event);
368+
369+
$event->setName(MvcEvent::EVENT_FINISH);
370+
$events->triggerEvent($event);
371+
358372
return $this;
359373
}
360374
}

src/Controller/AbstractController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ public function dispatch(Request $request, Response $response = null)
109109
$this->response = $response;
110110

111111
$e = $this->getEvent();
112-
$e->setRequest($request)
113-
->setResponse($response)
114-
->setTarget($this);
112+
$e->setName(MvcEvent::EVENT_DISPATCH);
113+
$e->setRequest($request);
114+
$e->setResponse($response);
115+
$e->setTarget($this);
115116

116-
$result = $this->getEventManager()->trigger(MvcEvent::EVENT_DISPATCH, $e, function ($test) {
117+
$result = $this->getEventManager()->triggerEventUntil(function ($test) {
117118
return ($test instanceof Response);
118-
});
119+
}, $e);
119120

120121
if ($result->stopped()) {
121122
return $result->last();

src/Controller/ControllerManager.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Zend\Mvc\Controller;
1111

1212
use Zend\EventManager\EventManagerAwareInterface;
13-
use Zend\EventManager\EventManagerInterface;
13+
use Zend\EventManager\SharedEventManagerInterface;
1414
use Zend\Mvc\Exception;
1515
use Zend\ServiceManager\AbstractPluginManager;
1616
use Zend\ServiceManager\ConfigInterface;
@@ -73,10 +73,8 @@ public function injectControllerDependencies($controller, ServiceLocatorInterfac
7373
// is why the shared EM injection needs to happen; the conditional
7474
// will always pass.
7575
$events = $controller->getEventManager();
76-
if (!$events instanceof EventManagerInterface) {
76+
if (! $events || ! $events->getSharedManager() instanceof SharedEventManagerInterface) {
7777
$controller->setEventManager($parentLocator->get('EventManager'));
78-
} else {
79-
$events->setSharedManager($parentLocator->get('SharedEventManager'));
8078
}
8179
}
8280

src/Controller/Plugin/Forward.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ 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) {
182-
$currentCallback = $currentEvent->getCallback();
182+
$currentCallback = $currentEvent;
183183

184184
// If we have an array, grab the object
185185
if (is_array($currentCallback)) {
@@ -193,7 +193,7 @@ protected function detachProblemListeners(SharedEvents $sharedEvents)
193193

194194
foreach ($classArray as $class) {
195195
if ($currentCallback instanceof $class) {
196-
$sharedEvents->detach($id, $currentEvent);
196+
$sharedEvents->detach($currentEvent, $id);
197197
$results[$id][$eventName][] = $currentEvent;
198198
}
199199
}

0 commit comments

Comments
 (0)