/** * Gestionnaire des erreurs de scripts Php * Peut stopper l'application en cas d'erreur bloquante * @param Number $pErrorLevel Niveau d'erreur * @param String $pErrorMessage Message renvoyé * @param String $pErrorFile Adresse du fichier qui a déclenché l'erreur * @param Number $pErrorLine Ligne où se trouve l'erreur * @param String $pErrorContext Contexte * @return void */ public static function errorHandler($pErrorLevel, $pErrorMessage, $pErrorFile, $pErrorLine, $pErrorContext) { $stopApplication = false; switch ($pErrorLevel) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: $stopApplication = true; $type = "error"; break; case E_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: $type = "warning"; break; case E_NOTICE: case E_USER_NOTICE: $type = "notice"; break; default: case self::E_USER_EXCEPTION: $stopApplication = true; $type = "error"; break; } $pErrorFile = pathinfo($pErrorFile); $pErrorFile = $pErrorFile["basename"]; if (preg_match('/href=/', $pErrorMessage, $matches)) { $pErrorMessage = preg_replace('/href=\'([a-z\\.\\-\\_]*)\'/', 'href=\'http://www.php.net/$1\' target=\'_blank\'', $pErrorMessage); } self::addToConsole($type, $pErrorMessage, $pErrorFile, $pErrorLine); if ($stopApplication) { if (!Core::debug()) { Logs::write($pErrorMessage . " " . $pErrorFile . " " . $pErrorLine . " " . $pErrorContext, $pErrorLevel); } Header::content_type("text/html", Configuration::$global_encoding); self::$open = true; self::render(true, true); Core::endApplication(); } }
/** * @static * @param DefaultController|null $pController * @param null $pAction * @param string $pTemplate * @return void */ public static function execute($pController = null, $pAction = null, $pTemplate = "") { if ($pController != "statique") { $pController->setTemplate(self::$controller, self::$action, $pTemplate); } if ($pAction != null) { $pController->{$pAction}(); } if (!Core::$request_async) { Header::content_type("text/html"); $pController->render(); if (Core::debug()) { Debugger::render(); } } else { $return = $pController->getGlobalVars(); $return = array_merge($return, Debugger::getGlobalVars()); if (isset($_POST) && isset($_POST["render"]) && $_POST["render"] != "false") { $return["html"] = $pController->render(false); } $response = SimpleJSON::encode($return); $type = "json"; self::performResponse($response, $type); } }
/** * Méthode public de rendu de la page en cours * @param bool $pDisplay * @return string */ public function render($pDisplay = true) { $smarty = new Smarty(); Core::setupSmarty($smarty); if (!$smarty->template_exists($this->template)) { if (Core::debug()) { trigger_error("Le template <b>" . $this->template . "</b> est introuvable", E_USER_ERROR); } else { Go::to404(); } } $conf = get_class_vars('core\\application\\Configuration'); $terms = Dictionary::terms(); $globalVars = $this->getGlobalVars(); $smarty->assign_by_ref("configuration", $conf); $smarty->assign_by_ref("request_async", Core::$request_async); $smarty->assign_by_ref("dictionary", $terms); foreach ($this->forms as $n => &$form) { $smarty->register_object("form_" . $n, $form, array("display", "name", "getValue", "getLabel", "getOptions", "isChecked")); } foreach ($globalVars as $n => &$v) { $smarty->assign_by_ref($n, $v); } if (!Core::debug()) { $smarty->load_filter('output', 'gzip'); } return $smarty->fetch($this->template, null, null, $pDisplay); }