Skip to content
Permalink
Browse files

Move default renderer check to getRenderer().

  • Loading branch information...
ADmad authored and dereuromark committed Nov 27, 2016
1 parent 40b39d1 commit f4f8100920bbda5ffda85202bea31e7c5c6913bf
Showing with 20 additions and 9 deletions.
  1. +20 −9 src/Error/Middleware/ErrorHandlerMiddleware.php
@@ -17,6 +17,7 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\InstanceConfigTrait;
use Cake\Error\ExceptionRenderer;
use Cake\Log\Log;
use Exception;
@@ -51,22 +52,28 @@ class ErrorHandlerMiddleware
'trace' => false,
];
/**
* Exception render.
*
* @var \Cake\Error\ExceptionRenderer|string|null
*/
protected $exceptionRenderer;
/**
* Constructor
*
* @param string|callable|null $renderer The renderer or class name
* @param string|callable|null $exceptionRenderer The renderer or class name
* to use or a callable factory. If null, Configure::read('Error.exceptionRenderer')
* will be used.
* @param array $config Configuration options to use. If empty, `Configure::read('Error')`
* will be used.
*/
public function __construct($renderer = null, array $config = [])
public function __construct($exceptionRenderer = null, array $config = [])
{
if ($renderer === null) {
$renderer = Configure::read('Error.exceptionRenderer');
if ($exceptionRenderer) {
$this->exceptionRenderer = $exceptionRenderer;
}
$this->renderer = $renderer ?: 'Cake\Error\ExceptionRenderer';
$config = $config ?: Configure::read('Error');
$this->config($config);
}
@@ -125,15 +132,19 @@ public function handleException($exception, $request, $response)
*/
protected function getRenderer($exception)
{
if (is_string($this->renderer)) {
$class = App::className($this->renderer, 'Error');
if (!$this->exceptionRenderer) {
$this->exceptionRenderer = $this->config('exceptionRender') ?: ExceptionRenderer::class;
}
if (is_string($this->exceptionRenderer)) {
$class = App::className($this->exceptionRenderer, 'Error');
if (!$class) {
throw new Exception("The '{$this->renderer}' renderer class could not be found.");
throw new Exception("The '{$this->exceptionRenderer}' renderer class could not be found.");
}
return new $class($exception);
}
$factory = $this->renderer;
$factory = $this->exceptionRenderer;
return $factory($exception);
}

0 comments on commit f4f8100

Please sign in to comment.
You can’t perform that action at this time.