. */ namespace Volkszaehler\View; use Volkszaehler\View\HTTP; use Volkszaehler\Util; /** * superclass for all view classes * * @package default * @author Steffen Vogel * */ abstract class View { public $request; protected $response; public function __construct(HTTP\Request $request, HTTP\Response $response) { $this->request = $request; $this->response = $response; // error & exception handling by view set_exception_handler(array($this, 'exceptionHandler')); set_error_handler(array($this, 'errorHandler')); } /** * error & exception handling */ final public function errorHandler($errno, $errstr, $errfile, $errline) { $this->exceptionHandler(new \ErrorException($errstr, 0, $errno, $errfile, $errline)); } final public function exceptionHandler(\Exception $exception) { $this->addException($exception); //$this->status = STATUS_EXCEPTION; // TODO add status reporting to API $code = ($exception->getCode() == 0 && HTTP\Response::getCodeDescription($exception->getCode())) ? 400 : $exception->getCode(); $this->response->setCode($code); $this->render(); die(); } public function render() { $this->response->send(); } public function addException(\Exception $e) { echo $e; } public function addDebug(Util\Debug $debug) { } } ?>