11<?php
22
33/**
4- * cloud solutions ZendSentry
4+ * Bright Answer ZendSentry
55 *
6- * This source file is part of the cloud solutions ZendSentry package
6+ * This source file is part of the Bright Answer ZendSentry package
77 *
88 * @package ZendSentry\Mvc\View\Http\ExceptionStrategy
9- * @license New BSD License {@link /docs/LICENSE}
10- * @copyright Copyright (c) 2011 , cloud solutions OÜ
9+ * @license MIT License {@link /docs/LICENSE}
10+ * @copyright Copyright (c) 2016 , cloud solutions OÜ
1111 */
1212
1313namespace ZendSentry \Mvc \View \Http ;
1414
15+ use Zend \EventManager \AbstractListenerAggregate ;
1516use Zend \EventManager \EventManagerInterface ;
16- use Zend \EventManager \ListenerAggregateInterface ;
1717use Zend \Http \Response as HttpResponse ;
1818use Zend \Mvc \Application ;
1919use Zend \Mvc \MvcEvent ;
2626 *
2727 * @package ZendSentry\Mvc\View\Http\ExceptionStrategy
2828 */
29- class ExceptionStrategy implements ListenerAggregateInterface
29+ class ExceptionStrategy extends AbstractListenerAggregate
3030{
3131 /**
3232 * Display exceptions?
3333 * @var bool
3434 */
3535 protected $ displayExceptions = false ;
36-
36+
3737 /**
3838 * Default Exception Message
3939 * @var string
@@ -44,40 +44,17 @@ class ExceptionStrategy implements ListenerAggregateInterface
4444 * Name of exception template
4545 * @var string
4646 */
47- protected $ exceptionTemplate = 'error/index ' ;
48-
49- /**
50- * @var \Zend\Stdlib\CallbackHandler[]
51- */
52- protected $ listeners = array ();
47+ protected $ exceptionTemplate = 'error ' ;
5348
5449 /**
55- * Attach the aggregate to the specified event manager
56- *
57- * @param EventManagerInterface $events
58- * @return void
50+ * {@inheritDoc}
5951 */
60- public function attach (EventManagerInterface $ events )
52+ public function attach (EventManagerInterface $ events, $ priority = 1 )
6153 {
6254 $ this ->listeners [] = $ events ->attach (MvcEvent::EVENT_DISPATCH_ERROR , array ($ this , 'prepareExceptionViewModel ' ));
6355 $ this ->listeners [] = $ events ->attach (MvcEvent::EVENT_RENDER_ERROR , array ($ this , 'prepareExceptionViewModel ' ));
6456 }
6557
66- /**
67- * Detach aggregate listeners from the specified event manager
68- *
69- * @param EventManagerInterface $events
70- * @return void
71- */
72- public function detach (EventManagerInterface $ events )
73- {
74- foreach ($ this ->listeners as $ index => $ listener ) {
75- if ($ events ->detach ($ listener )) {
76- unset($ this ->listeners [$ index ]);
77- }
78- }
79- }
80-
8158 /**
8259 * Flag: display exceptions in error pages?
8360 *
@@ -102,10 +79,8 @@ public function displayExceptions()
10279
10380 /**
10481 * Set the default exception message
105- *
10682 * @param string $defaultExceptionMessage
107- *
108- * @return $this
83+ * @return self
10984 */
11085 public function setDefaultExceptionMessage ($ defaultExceptionMessage )
11186 {
@@ -166,7 +141,7 @@ public function prepareExceptionViewModel(MvcEvent $e)
166141 case Application::ERROR_EXCEPTION :
167142 default :
168143 // check if there really is an exception
169- // zf2 also throw normal errors, for example: error-route-unauthorized
144+ // ZF also throws normal errors, for example: error-route-unauthorized
170145 // if there is no exception we have nothing to log
171146 if ($ e ->getParam ('exception ' ) == null ) {
172147 return ;
@@ -189,15 +164,13 @@ public function prepareExceptionViewModel(MvcEvent $e)
189164 $ response ->setStatusCode (500 );
190165 $ e ->setResponse ($ response );
191166 } else {
192- /** @noinspection PhpUndefinedMethodInspection */
193167 $ statusCode = $ response ->getStatusCode ();
194168 if ($ statusCode === 200 ) {
195- /** @noinspection PhpUndefinedMethodInspection */
196169 $ response ->setStatusCode (500 );
197170 }
198171 }
199172
200173 break ;
201174 }
202175 }
203- }
176+ }
0 commit comments