Exemple #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()));
     }
 }
    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();
    }
Exemple #3
0
 public static function forWidget($cogname, $widget_dashed)
 {
     $template = Config::get('templates/default');
     $view = new static();
     $view->setPath(COGS . "{$cogname}/Widgets/{$template}/");
     $view->setFile($widget_dashed);
     return $view;
 }
 /**
  * Do not use this constructor, use the factory method instead
  * @final
  * @param array $database_params in order to construct an EntityManager
  */
 protected final function __construct(array $database_params)
 {
     $connection = DriverManager::getConnection($database_params);
     // constructing an EntityManager
     parent::__construct($connection, Setup::createAnnotationMetadataConfiguration(array(COGS), Config::get('development', false)), $connection->getEventManager());
     if (isset($database_params['logging']) && $database_params['logging']) {
         $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger();
         $this->getConnection()->getConfiguration()->setSQLLogger($logger);
     }
 }