Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Strategy listener fixes
  • Loading branch information
Adam Grabek committed Jun 7, 2016
commit a789bbaf24735eae85bab5f6e1ce8ffe1f8fad10
9 changes: 7 additions & 2 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
namespace ZF\ApiProblem;

use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Application;
use Zend\Mvc\ResponseSender\SendResponseEvent;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\SendResponseListener;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZF\ApiProblem\Listener\ApiProblemListener;
use ZF\ApiProblem\Listener\SendApiProblemResponseListener;
use ZF\ApiProblem\View\ApiProblemStrategy;

/**
* ZF2 module
Expand Down Expand Up @@ -64,7 +66,6 @@ public function onBootstrap($e)
$sendResponseListener = $serviceManager->get('SendResponseListener');



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

Expand All @@ -84,16 +85,20 @@ public function onBootstrap($e)
*/
public function onRender($e)
{
/** @var Application $app */
$app = $e->getTarget();
$services = $app->getServiceManager();

if ($services->has('View')) {
$view = $services->get('View');
/** @var EventManagerInterface $events */
$events = $view->getEventManager();

// register at high priority, to "beat" normal json strategy registered
// via view manager, as well as HAL strategy.
$events->attach($services->get('ZF\ApiProblem\ApiProblemStrategy'), 400);
/** @var ApiProblemStrategy $apiProblemStrategy */
$apiProblemStrategy = $services->get(ApiProblemStrategy::class);
$apiProblemStrategy->attach($events, 400);
}
}
}
55 changes: 33 additions & 22 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,45 @@
* @copyright Copyright (c) 2014 Zend Technologies USA Inc. (http://www.zend.com)
*/

return array(
'service_manager' => array(
'aliases' => array(
'ZF\ApiProblem\ApiProblemListener' => 'ZF\ApiProblem\Listener\ApiProblemListener',
'ZF\ApiProblem\RenderErrorListener' => 'ZF\ApiProblem\Listener\RenderErrorListener',
'ZF\ApiProblem\ApiProblemRenderer' => 'ZF\ApiProblem\View\ApiProblemRenderer',
'ZF\ApiProblem\ApiProblemStrategy' => 'ZF\ApiProblem\View\ApiProblemStrategy',
),
'factories' => array(
'ZF\ApiProblem\Listener\ApiProblemListener' => 'ZF\ApiProblem\Factory\ApiProblemListenerFactory',
'ZF\ApiProblem\Listener\RenderErrorListener' => 'ZF\ApiProblem\Factory\RenderErrorListenerFactory',
'ZF\ApiProblem\Listener\SendApiProblemResponseListener' => 'ZF\ApiProblem\Factory\SendApiProblemResponseListenerFactory',
'ZF\ApiProblem\View\ApiProblemRenderer' => 'ZF\ApiProblem\Factory\ApiProblemRendererFactory',
'ZF\ApiProblem\View\ApiProblemStrategy' => 'ZF\ApiProblem\Factory\ApiProblemStrategyFactory',
)
),
use ZF\ApiProblem\Factory\ApiProblemListenerFactory;
use ZF\ApiProblem\Factory\ApiProblemRendererFactory;
use ZF\ApiProblem\Factory\ApiProblemStrategyFactory;
use ZF\ApiProblem\Factory\RenderErrorListenerFactory;
use ZF\ApiProblem\Factory\SendApiProblemResponseListenerFactory;
use ZF\ApiProblem\Listener\ApiProblemListener;
use ZF\ApiProblem\Listener\RenderErrorListener;
use ZF\ApiProblem\Listener\SendApiProblemResponseListener;
use ZF\ApiProblem\View\ApiProblemRenderer;
use ZF\ApiProblem\View\ApiProblemStrategy;

'view_manager' => array(
return [
'service_manager' => [
'aliases' => [
'ZF\ApiProblem\ApiProblemListener' => ApiProblemListener::class,
'ZF\ApiProblem\RenderErrorListener' => RenderErrorListener::class,
'ZF\ApiProblem\ApiProblemRenderer' => ApiProblemRenderer::class,
'ZF\ApiProblem\ApiProblemStrategy' => ApiProblemStrategy::class,
],
'factories' => [
ApiProblemListener::class => ApiProblemListenerFactory::class,
RenderErrorListener::class => RenderErrorListenerFactory::class,
SendApiProblemResponseListener::class => SendApiProblemResponseListenerFactory::class,
ApiProblemRenderer::class => ApiProblemRendererFactory::class,
ApiProblemStrategy::class => ApiProblemStrategyFactory::class,
],
],

'view_manager' => [
// Enable this in your application configuration in order to get full
// exception stack traces in your API-Problem responses.
'display_exceptions' => false,
),
'display_exceptions' => FALSE,
],

'zf-api-problem' => array(
'zf-api-problem' => [
// Accept types that should allow ApiProblem responses
// 'accept_filters' => $stringOrArray,

// Array of controller service names that should enable the ApiProblem render.error listener
//'render_error_controllers' => array(),
)
);
],
];