Browse Source

modified FrontController to get error layout from Router

master
Anton Grebnev 13 years ago
parent
commit
1d999bda3f
  1. 16
      app/FrontController.php
  2. 8
      tests/app/FrontControllerTest.php

16
app/FrontController.php

@ -41,8 +41,10 @@ class FrontController
/**
* Refuse cloning
*/
private function __clone(){}
private function __clone()
{
}
/**
* @return FrontController
*/
@ -126,14 +128,20 @@ class FrontController
}
}
return $html;
} catch(Exception $e) {
} catch (Exception $e) {
if (DEBUG == true) {
if (!headers_sent()) {
header('HTTP/1.0 500 Internal Server Error');
}
return ErrorHandler::showDebug($e);
}
$layout = new ErrorLayout();
$layout_class = $this->getRouter()->getErrorLayout();
/**
* @var ErrorLayout $layout
*/
$layout = new $layout_class();
$layout->setException($e);
return $layout->fetch(new ErrorAction($e));
}
}

8
tests/app/FrontControllerTest.php

@ -44,7 +44,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$this->getMock('View');
}
if (!class_exists('ErrorLayout')) {
$this->getMock('ErrorLayout', array('fetch'), array(), 'ErrorLayoutMock');
$this->getMock('ErrorLayout', array('fetch', 'setException'), array(), 'ErrorLayoutMock');
}
if (!class_exists('ErrorActionMock')) {
$this->getMock('ErrorAction', array(), array(), 'ErrorActionMock', false);
@ -190,7 +190,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'user');
$result = $controller->execute();
$this->assertEmpty($result);
$this->assertNull($result);
}
/**
* @runInSeparateProcess
@ -205,7 +205,7 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'NewAjax');
$result = $controller->execute();
$this->assertEmpty($result);
$this->assertNull($result);
}
private function setConstants($val = false)
@ -227,8 +227,6 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
return 'PHPViewMock';
case 'DefaultLayout':
return 'DefaultLayoutMock';
case 'userAction':
return 'userAction';
case 'ErrorAction':
return 'ErrorActionMock';
case 'ErrorLayout':

Loading…
Cancel
Save