Exemple #1
0
 /**
  * Default mechanism for handling uncaught exceptions.
  * Will fetch the current controller instance or instantiate an ErrorController.
  * The error view template will be rendered.
  *
  * @uses Titon\Debug\Debugger
  *
  * @param \Exception $exception
  */
 public function handleError(Exception $exception)
 {
     if (class_exists('Titon\\Debug\\Debugger')) {
         Debugger::logException($exception);
     }
     // Get the controller
     try {
         $controller = Registry::get('titon.controller');
         if (!$controller instanceof Controller) {
             throw new MissingControllerException();
         }
     } catch (Exception $e) {
         $controller = new ErrorController();
         $controller->initialize();
     }
     // And the view
     try {
         $view = Registry::get('titon.view');
         if (!$view instanceof ViewInterface) {
             throw new MissingViewException();
         }
     } catch (Exception $e) {
         $view = new View();
         $view->addHelper('html', new HtmlHelper());
         $view->addHelper('block', new BlockHelper());
         $view->addHelper('asset', new AssetHelper(['webroot' => $this->getWebroot()]));
     }
     $controller->setView($view);
     $controller->setRequest($this->getRequest());
     $controller->setResponse($this->getResponse());
     $this->emit('mvc.preError', [$this, $controller, $exception]);
     $response = $controller->renderError($exception);
     $this->emit('mvc.postError', [$this, $controller, $exception, &$response]);
     $this->getResponse()->body($response)->respond();
     $this->emit('mvc.onShutdown', [$this]);
     exit;
 }
Exemple #2
0
<?php

require_once realpath(__DIR__ . '/../../../src/Loader.php');
Loader::classmap();
$app = new Application();
// By default but more clear
$app->setControllerPath(__DIR__ . '/../controllers');
$app->bootstrap("view", function () {
    $view = new View();
    $view->setViewPath(__DIR__ . '/../views');
    $view->addHelper("title", function ($part = false) {
        static $parts = array();
        static $delimiter = ' :: ';
        return $part === false ? implode($delimiter, $parts) : ($parts[] = $part);
    });
    return $view;
});
$app->bootstrap("layout", function () {
    $layout = new Layout();
    $layout->setViewPath(__DIR__ . '/../layouts');
    return $layout;
});
$app->run();
 public function testLayoutViewHelpersPass()
 {
     $this->object->bootstrap('layout', function () {
         $l = new Layout();
         $l->setScriptName("title-helper.phtml");
         $l->setViewPath(__DIR__ . '/layouts');
         return $l;
     });
     $this->object->bootstrap('view', function () {
         $v = new View();
         $v->setViewPath(__DIR__ . '/views');
         $v->addHelper("title", function ($part = false) {
             static $parts = array();
             static $delimiter = ' :: ';
             return $part === false ? implode($delimiter, $parts) : ($parts[] = $part);
         });
         return $v;
     });
     ob_start();
     $this->object->run(new Request("/general/title-helper"));
     $content = ob_get_contents();
     ob_end_clean();
     $this->assertEquals("<title>the title helper :: second</title>", $content);
 }