Skip to content

Commit

Permalink
copy fixes from branch... rebase is a mess
Browse files Browse the repository at this point in the history
  • Loading branch information
markushausammann committed Oct 16, 2018
1 parent f2aae92 commit db592e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 82 deletions.
59 changes: 17 additions & 42 deletions src/ZendSentry/Mvc/View/Console/ExceptionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*
* @package ZendSentry\Mvc\View\Console\ExceptionStrategy
* @license New BSD License {@link /docs/LICENSE}
* @copyright Copyright (c) 2013, cloud solutions OÜ
* @copyright Copyright (c) 2016, cloud solutions OÜ
*/

namespace ZendSentry\Mvc\View\Console;

use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\Mvc\Application;
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ResponseInterface;
Expand All @@ -25,7 +25,7 @@
*
* @package ZendSentry\Mvc\View\Console\ExceptionStrategy
*/
class ExceptionStrategy implements ListenerAggregateInterface
class ExceptionStrategy extends AbstractListenerAggregate
{
/**
* Display exceptions?
Expand Down Expand Up @@ -60,37 +60,14 @@ class ExceptionStrategy implements ListenerAggregateInterface
EOT;

/**
* @var \Zend\Stdlib\CallbackHandler[]
* {@inheritDoc}
*/
protected $listeners = array();

/**
* Attach the aggregate to the specified event manager
*
* @param EventManagerInterface $events
* @return void
*/
public function attach(EventManagerInterface $events)
public function attach(EventManagerInterface $events, $priority = 1)
{
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareExceptionViewModel'));
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareExceptionViewModel'));
}

/**
* Detach aggregate listeners from the specified event manager
*
* @param EventManagerInterface $events
* @return void
*/
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $listener) {
if ($events->detach($listener)) {
unset($this->listeners[$index]);
}
}
}

/**
* Flag: display exceptions in error pages?
*
Expand All @@ -112,7 +89,7 @@ public function displayExceptions()
{
return $this->displayExceptions;
}

/**
* Get current template for message that will be shown in Console.
*
Expand All @@ -125,10 +102,8 @@ public function getMessage()

/**
* Set the default exception message
*
* @param string $defaultExceptionMessage
*
* @return $this
* @return self
*/
public function setDefaultExceptionMessage($defaultExceptionMessage)
{
Expand Down Expand Up @@ -194,7 +169,7 @@ public function prepareExceptionViewModel(MvcEvent $e)
default:
// Prepare error message
$exception = $e->getParam('exception');

// Log exception to sentry by triggering an exception event
$e->getApplication()->getEventManager()->trigger('logException', $this, array('exception' => $exception));

Expand All @@ -213,14 +188,14 @@ public function prepareExceptionViewModel(MvcEvent $e)
':stack',
':previous',
), array(
get_class($exception),
$exception->getMessage(),
$exception->getCode(),
$exception->getFile(),
$exception->getLine(),
$exception->getTraceAsString(),
$exception->getPrevious(),
),
get_class($exception),
$exception->getMessage(),
$exception->getCode(),
$exception->getFile(),
$exception->getLine(),
$exception->getTraceAsString(),
$exception->getPrevious(),
),
$this->message
);
} else {
Expand All @@ -238,4 +213,4 @@ public function prepareExceptionViewModel(MvcEvent $e)
break;
}
}
}
}
53 changes: 13 additions & 40 deletions src/ZendSentry/Mvc/View/Http/ExceptionStrategy.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

/**
* cloud solutions ZendSentry
* Bright Answer ZendSentry
*
* This source file is part of the cloud solutions ZendSentry package
* This source file is part of the Bright Answer ZendSentry package
*
* @package ZendSentry\Mvc\View\Http\ExceptionStrategy
* @license New BSD License {@link /docs/LICENSE}
* @copyright Copyright (c) 2011, cloud solutions OÜ
* @license MIT License {@link /docs/LICENSE}
* @copyright Copyright (c) 2016, cloud solutions OÜ
*/

namespace ZendSentry\Mvc\View\Http;

use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\Http\Response as HttpResponse;
use Zend\Mvc\Application;
use Zend\Mvc\MvcEvent;
Expand All @@ -26,14 +26,14 @@
*
* @package ZendSentry\Mvc\View\Http\ExceptionStrategy
*/
class ExceptionStrategy implements ListenerAggregateInterface
class ExceptionStrategy extends AbstractListenerAggregate
{
/**
* Display exceptions?
* @var bool
*/
protected $displayExceptions = false;

/**
* Default Exception Message
* @var string
Expand All @@ -44,40 +44,17 @@ class ExceptionStrategy implements ListenerAggregateInterface
* Name of exception template
* @var string
*/
protected $exceptionTemplate = 'error/index';

/**
* @var \Zend\Stdlib\CallbackHandler[]
*/
protected $listeners = array();
protected $exceptionTemplate = 'error';

/**
* Attach the aggregate to the specified event manager
*
* @param EventManagerInterface $events
* @return void
* {@inheritDoc}
*/
public function attach(EventManagerInterface $events)
public function attach(EventManagerInterface $events, $priority = 1)
{
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareExceptionViewModel'));
$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareExceptionViewModel'));
}

/**
* Detach aggregate listeners from the specified event manager
*
* @param EventManagerInterface $events
* @return void
*/
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $listener) {
if ($events->detach($listener)) {
unset($this->listeners[$index]);
}
}
}

/**
* Flag: display exceptions in error pages?
*
Expand All @@ -102,10 +79,8 @@ public function displayExceptions()

/**
* Set the default exception message
*
* @param string $defaultExceptionMessage
*
* @return $this
* @return self
*/
public function setDefaultExceptionMessage($defaultExceptionMessage)
{
Expand Down Expand Up @@ -166,7 +141,7 @@ public function prepareExceptionViewModel(MvcEvent $e)
case Application::ERROR_EXCEPTION:
default:
// check if there really is an exception
// zf2 also throw normal errors, for example: error-route-unauthorized
// ZF also throws normal errors, for example: error-route-unauthorized
// if there is no exception we have nothing to log
if ($e->getParam('exception') == null) {
return;
Expand All @@ -189,15 +164,13 @@ public function prepareExceptionViewModel(MvcEvent $e)
$response->setStatusCode(500);
$e->setResponse($response);
} else {
/** @noinspection PhpUndefinedMethodInspection */
$statusCode = $response->getStatusCode();
if ($statusCode === 200) {
/** @noinspection PhpUndefinedMethodInspection */
$response->setStatusCode(500);
}
}

break;
}
}
}
}

0 comments on commit db592e6

Please sign in to comment.