Пример #1
0
 /**
  * Main function
  * Launches core classes of the framework
  * @static
  */
 public static function run()
 {
     date_default_timezone_set('UTC');
     Autoloader::register(ROOT, LIB, DOCTRINE);
     // Register contraint classes to use in the annotations of controllers
     Addendum::registerNamespaces('Cognosys\\Constraints');
     Config::load(CONFIG . 'main.yml');
     if (Config::get('development')) {
         error_reporting(E_ALL | E_STRICT);
     }
     Mail::configure(Config::get('mail'));
     $request = null;
     $response = null;
     try {
         $request = new Request(Config::get('root'));
         // redirects the execution to a controller
         // according to the request parameters
         $response = new Response($request, Config::get('routes'), Config::get('cogs'));
         $controller = Controller::factory($request, $response, Config::get('database'));
         Widget::controller($controller);
         // allow widgets to access controller
         $controller->setDecorator(Config::get('templates/default'));
         $controller->run();
     } catch (Error $e) {
         $e->handle($request, $response, Config::get('templates/error'));
     } catch (Exception $e) {
         //TODO: handle everything else
         echo "An unexpected error occured!<br><br>";
         echo "{$e->getMessage()}<br>";
         var_dump(nl2br($e->getTraceAsString()));
     }
 }
Пример #2
0
    public function handle($request, $response, $template)
    {
        $now = new DateTime();
        $time = $now->format(DateTime::RFC850);
        $trace = TextUtil::tabify($this->getTraceAsString(), 1);
        $request = $request ? TextUtil::tabify($request, 1) : '(No request information)';
        $response = $response ? TextUtil::tabify($response, 1) : '(No response information)';
        $view = new View($request, $response);
        $view->setDecorator($template);
        $this->message = <<<EOT
{$this->message}

* Time: {$time}
* File: {$this->file}
* Line: {$this->line}
* Trace:
\t{$trace}

* Request:
\t{$request}

* Response:
\t{$response}
EOT;
        if (Config::get('development')) {
            $this->message = "<pre>{$this->message}</pre>";
            $view->setText($this->message);
        } else {
            Mail::send(Config::get('developers'), 'Application error', $this->message, Mail::PRIORITY_HIGH);
            $view->setText('An email has been sent to the developers to resolve the issue.' . ' Thank you.');
        }
        $view->render();
        $view->show();
    }