Skip to content

Commit db592e6

Browse files
copy fixes from branch... rebase is a mess
1 parent f2aae92 commit db592e6

File tree

2 files changed

+30
-82
lines changed

2 files changed

+30
-82
lines changed

src/ZendSentry/Mvc/View/Console/ExceptionStrategy.php

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*
88
* @package ZendSentry\Mvc\View\Console\ExceptionStrategy
99
* @license New BSD License {@link /docs/LICENSE}
10-
* @copyright Copyright (c) 2013, cloud solutions OÜ
10+
* @copyright Copyright (c) 2016, cloud solutions OÜ
1111
*/
1212

1313
namespace ZendSentry\Mvc\View\Console;
1414

15+
use Zend\EventManager\AbstractListenerAggregate;
1516
use Zend\EventManager\EventManagerInterface;
16-
use Zend\EventManager\ListenerAggregateInterface;
1717
use Zend\Mvc\Application;
1818
use Zend\Mvc\MvcEvent;
1919
use Zend\Stdlib\ResponseInterface;
@@ -25,7 +25,7 @@
2525
*
2626
* @package ZendSentry\Mvc\View\Console\ExceptionStrategy
2727
*/
28-
class ExceptionStrategy implements ListenerAggregateInterface
28+
class ExceptionStrategy extends AbstractListenerAggregate
2929
{
3030
/**
3131
* Display exceptions?
@@ -60,37 +60,14 @@ class ExceptionStrategy implements ListenerAggregateInterface
6060
EOT;
6161

6262
/**
63-
* @var \Zend\Stdlib\CallbackHandler[]
63+
* {@inheritDoc}
6464
*/
65-
protected $listeners = array();
66-
67-
/**
68-
* Attach the aggregate to the specified event manager
69-
*
70-
* @param EventManagerInterface $events
71-
* @return void
72-
*/
73-
public function attach(EventManagerInterface $events)
65+
public function attach(EventManagerInterface $events, $priority = 1)
7466
{
7567
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareExceptionViewModel'));
7668
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareExceptionViewModel'));
7769
}
7870

79-
/**
80-
* Detach aggregate listeners from the specified event manager
81-
*
82-
* @param EventManagerInterface $events
83-
* @return void
84-
*/
85-
public function detach(EventManagerInterface $events)
86-
{
87-
foreach ($this->listeners as $index => $listener) {
88-
if ($events->detach($listener)) {
89-
unset($this->listeners[$index]);
90-
}
91-
}
92-
}
93-
9471
/**
9572
* Flag: display exceptions in error pages?
9673
*
@@ -112,7 +89,7 @@ public function displayExceptions()
11289
{
11390
return $this->displayExceptions;
11491
}
115-
92+
11693
/**
11794
* Get current template for message that will be shown in Console.
11895
*
@@ -125,10 +102,8 @@ public function getMessage()
125102

126103
/**
127104
* Set the default exception message
128-
*
129105
* @param string $defaultExceptionMessage
130-
*
131-
* @return $this
106+
* @return self
132107
*/
133108
public function setDefaultExceptionMessage($defaultExceptionMessage)
134109
{
@@ -194,7 +169,7 @@ public function prepareExceptionViewModel(MvcEvent $e)
194169
default:
195170
// Prepare error message
196171
$exception = $e->getParam('exception');
197-
172+
198173
// Log exception to sentry by triggering an exception event
199174
$e->getApplication()->getEventManager()->trigger('logException', $this, array('exception' => $exception));
200175

@@ -213,14 +188,14 @@ public function prepareExceptionViewModel(MvcEvent $e)
213188
':stack',
214189
':previous',
215190
), array(
216-
get_class($exception),
217-
$exception->getMessage(),
218-
$exception->getCode(),
219-
$exception->getFile(),
220-
$exception->getLine(),
221-
$exception->getTraceAsString(),
222-
$exception->getPrevious(),
223-
),
191+
get_class($exception),
192+
$exception->getMessage(),
193+
$exception->getCode(),
194+
$exception->getFile(),
195+
$exception->getLine(),
196+
$exception->getTraceAsString(),
197+
$exception->getPrevious(),
198+
),
224199
$this->message
225200
);
226201
} else {
@@ -238,4 +213,4 @@ public function prepareExceptionViewModel(MvcEvent $e)
238213
break;
239214
}
240215
}
241-
}
216+
}

src/ZendSentry/Mvc/View/Http/ExceptionStrategy.php

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
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

1313
namespace ZendSentry\Mvc\View\Http;
1414

15+
use Zend\EventManager\AbstractListenerAggregate;
1516
use Zend\EventManager\EventManagerInterface;
16-
use Zend\EventManager\ListenerAggregateInterface;
1717
use Zend\Http\Response as HttpResponse;
1818
use Zend\Mvc\Application;
1919
use Zend\Mvc\MvcEvent;
@@ -26,14 +26,14 @@
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

Comments
 (0)