Skip to content

Commit a789bba

Browse files
author
Adam Grabek
committed
Strategy listener fixes
1 parent da39c3c commit a789bba

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

Module.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
namespace ZF\ApiProblem;
88

99
use Zend\EventManager\EventManagerInterface;
10+
use Zend\Mvc\Application;
1011
use Zend\Mvc\ResponseSender\SendResponseEvent;
1112
use Zend\Mvc\MvcEvent;
1213
use Zend\Mvc\SendResponseListener;
1314
use Zend\ServiceManager\ServiceLocatorInterface;
1415
use ZF\ApiProblem\Listener\ApiProblemListener;
1516
use ZF\ApiProblem\Listener\SendApiProblemResponseListener;
17+
use ZF\ApiProblem\View\ApiProblemStrategy;
1618

1719
/**
1820
* ZF2 module
@@ -64,7 +66,6 @@ public function onBootstrap($e)
6466
$sendResponseListener = $serviceManager->get('SendResponseListener');
6567

6668

67-
6869
$apiProblemListener->attach($eventManager);
6970
$eventManager->attach(MvcEvent::EVENT_RENDER, [$this, 'onRender'], 100);
7071

@@ -84,16 +85,20 @@ public function onBootstrap($e)
8485
*/
8586
public function onRender($e)
8687
{
88+
/** @var Application $app */
8789
$app = $e->getTarget();
8890
$services = $app->getServiceManager();
8991

9092
if ($services->has('View')) {
9193
$view = $services->get('View');
94+
/** @var EventManagerInterface $events */
9295
$events = $view->getEventManager();
9396

9497
// register at high priority, to "beat" normal json strategy registered
9598
// via view manager, as well as HAL strategy.
96-
$events->attach($services->get('ZF\ApiProblem\ApiProblemStrategy'), 400);
99+
/** @var ApiProblemStrategy $apiProblemStrategy */
100+
$apiProblemStrategy = $services->get(ApiProblemStrategy::class);
101+
$apiProblemStrategy->attach($events, 400);
97102
}
98103
}
99104
}

config/module.config.php

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,45 @@
44
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com)
55
*/
66

7-
return array(
8-
'service_manager' => array(
9-
'aliases' => array(
10-
'ZF\ApiProblem\ApiProblemListener' => 'ZF\ApiProblem\Listener\ApiProblemListener',
11-
'ZF\ApiProblem\RenderErrorListener' => 'ZF\ApiProblem\Listener\RenderErrorListener',
12-
'ZF\ApiProblem\ApiProblemRenderer' => 'ZF\ApiProblem\View\ApiProblemRenderer',
13-
'ZF\ApiProblem\ApiProblemStrategy' => 'ZF\ApiProblem\View\ApiProblemStrategy',
14-
),
15-
'factories' => array(
16-
'ZF\ApiProblem\Listener\ApiProblemListener' => 'ZF\ApiProblem\Factory\ApiProblemListenerFactory',
17-
'ZF\ApiProblem\Listener\RenderErrorListener' => 'ZF\ApiProblem\Factory\RenderErrorListenerFactory',
18-
'ZF\ApiProblem\Listener\SendApiProblemResponseListener' => 'ZF\ApiProblem\Factory\SendApiProblemResponseListenerFactory',
19-
'ZF\ApiProblem\View\ApiProblemRenderer' => 'ZF\ApiProblem\Factory\ApiProblemRendererFactory',
20-
'ZF\ApiProblem\View\ApiProblemStrategy' => 'ZF\ApiProblem\Factory\ApiProblemStrategyFactory',
21-
)
22-
),
7+
use ZF\ApiProblem\Factory\ApiProblemListenerFactory;
8+
use ZF\ApiProblem\Factory\ApiProblemRendererFactory;
9+
use ZF\ApiProblem\Factory\ApiProblemStrategyFactory;
10+
use ZF\ApiProblem\Factory\RenderErrorListenerFactory;
11+
use ZF\ApiProblem\Factory\SendApiProblemResponseListenerFactory;
12+
use ZF\ApiProblem\Listener\ApiProblemListener;
13+
use ZF\ApiProblem\Listener\RenderErrorListener;
14+
use ZF\ApiProblem\Listener\SendApiProblemResponseListener;
15+
use ZF\ApiProblem\View\ApiProblemRenderer;
16+
use ZF\ApiProblem\View\ApiProblemStrategy;
2317

24-
'view_manager' => array(
18+
return [
19+
'service_manager' => [
20+
'aliases' => [
21+
'ZF\ApiProblem\ApiProblemListener' => ApiProblemListener::class,
22+
'ZF\ApiProblem\RenderErrorListener' => RenderErrorListener::class,
23+
'ZF\ApiProblem\ApiProblemRenderer' => ApiProblemRenderer::class,
24+
'ZF\ApiProblem\ApiProblemStrategy' => ApiProblemStrategy::class,
25+
],
26+
'factories' => [
27+
ApiProblemListener::class => ApiProblemListenerFactory::class,
28+
RenderErrorListener::class => RenderErrorListenerFactory::class,
29+
SendApiProblemResponseListener::class => SendApiProblemResponseListenerFactory::class,
30+
ApiProblemRenderer::class => ApiProblemRendererFactory::class,
31+
ApiProblemStrategy::class => ApiProblemStrategyFactory::class,
32+
],
33+
],
34+
35+
'view_manager' => [
2536
// Enable this in your application configuration in order to get full
2637
// exception stack traces in your API-Problem responses.
27-
'display_exceptions' => false,
28-
),
38+
'display_exceptions' => FALSE,
39+
],
2940

30-
'zf-api-problem' => array(
41+
'zf-api-problem' => [
3142
// Accept types that should allow ApiProblem responses
3243
// 'accept_filters' => $stringOrArray,
3344

3445
// Array of controller service names that should enable the ApiProblem render.error listener
3546
//'render_error_controllers' => array(),
36-
)
37-
);
47+
],
48+
];

0 commit comments

Comments
 (0)