Advertisement
vanchelo

Untitled

Dec 18th, 2013
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <?php
  2. try {
  3.  
  4.     /**
  5.      * Read the configuration
  6.      */
  7.     $config = include __DIR__ . '/../config/config.php';
  8.  
  9.     $loader = new Loader();
  10.  
  11.     $loader->registerNamespaces(array(
  12.         'Libs' => __DIR__ . '/../library/',
  13.     ));
  14.  
  15.     $loader->register();
  16.  
  17.     /**
  18.      * Include services
  19.      */
  20.     require __DIR__ . '/../config/services.php';
  21.  
  22.     /**
  23.      * Handle the request
  24.      */
  25.     $application = new Application();
  26.  
  27.     /**
  28.      * Assign the DI
  29.      * @var Phalcon\DI\FactoryDefault $di
  30.      */
  31.     $application->setDI($di);
  32.  
  33.     /**
  34.      * Include modules
  35.      */
  36.     require __DIR__ . '/../config/modules.php';
  37.  
  38.     echo $application->handle()->getContent();
  39.  
  40. } catch (Phalcon\Exception $e) {
  41.    // remove view contents from buffer
  42.    ob_clean();
  43.  
  44.    $errorCode = 500;
  45.    $errorView = __DIR__ . '/../apps/commons/views/error.phtml';
  46.  
  47.    switch (true) {
  48.        // 401 UNAUTHORIZED
  49.        case $e->getCode() == 401:
  50.            $errorCode = 401;
  51.            break;
  52.  
  53.        // 403 FORBIDDEN
  54.        case $e->getCode() == 403:
  55.            $errorCode = 403;
  56.            break;
  57.  
  58.        // 404 NOT FOUND
  59.        case $e->getCode() == 404:
  60.        case ($e instanceof Phalcon\Mvc\View\Exception):
  61.        case ($e instanceof Phalcon\Mvc\Dispatcher\Exception):
  62.        case ($e instanceof Phalcon\DI\Exception):
  63.            $errorCode = 404;
  64.            break;
  65.    }
  66.  
  67.    // Get error view contents. Since we are including the view
  68.    // file here you can use PHP and local vars inside the error view.
  69.    ob_start();
  70.    include_once $errorView;
  71.    $contents = ob_get_contents();
  72.    ob_end_clean();
  73.  
  74.    // send view to header
  75.    $di->getShared('response')
  76.        ->resetHeaders()
  77.        ->setStatusCode($errorCode, null)
  78.        ->setContent($contents)
  79.        ->send();
  80. } catch (PDOException $e){
  81.    echo $e->getMessage();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement