/** * Sets up key UserFrosting services: message stream, translator, and client-side validation adapter */ public function setupServices($locale) { //error_log("Setting up message stream"); /**** Message Stream Setup ****/ /* Set up persistent message stream for alerts. Do not use Slim's, it sucks. */ if (!isset($_SESSION['userfrosting']['alerts'])) { $_SESSION['userfrosting']['alerts'] = new \Fortress\MessageStream(); } $this->alerts = $_SESSION['userfrosting']['alerts']; /**** Translation setup ****/ $this->translator = new \Fortress\MessageTranslator(); /* Set the translation path and default language path. */ $this->translator->setTranslationTable($this->config("locales.path") . "/" . $locale . ".php"); $this->translator->setDefaultTable($this->config("locales.path") . "/en_US.php"); \Fortress\MessageStream::setTranslator($this->translator); // Once we have the translator, we can set up the client-side validation adapter too $this->jsValidator = new \Fortress\JqueryValidationAdapter($this->translator); }
$app->site->register('userfrosting', 'minify_js', "Minify JS", "toggle", [0 => "Off", 1 => "On"]); }, 1); /**** Session and User Setup ****/ $db_error = $app->setupUser(); /**** Message Stream Setup ****/ /* Set up persistent message stream for alerts. Do not use Slim's, it sucks. */ if (!isset($_SESSION['userfrosting']['alerts'])) { $_SESSION['userfrosting']['alerts'] = new \Fortress\MessageStream(); } $app->alerts = $_SESSION['userfrosting']['alerts']; /**** Translation setup ****/ $app->translator = new \Fortress\MessageTranslator(); /* Set the translation path and default language path. */ $app->translator->setTranslationTable($app->config("locales.path") . "/" . $app->user->locale . ".php"); $app->translator->setDefaultTable($app->config("locales.path") . "/en_US.php"); \Fortress\MessageStream::setTranslator($app->translator); /**** Error Handling Setup ****/ // Custom error-handler: send a generic message to the client, but put the specific error info in the error log. // A Slim application uses its built-in error handler if its debug setting is true; otherwise, it uses the custom error handler. $app->error(function (\Exception $e) use($app) { if ($app->alerts && is_object($app->alerts) && $app->translator) { $app->alerts->addMessageTranslated("danger", "SERVER_ERROR"); } error_log("Error in " . $e->getFile() . " on line " . $e->getLine() . ": " . $e->getMessage()); error_log($e->getTraceAsString()); }); // Also handle fatal errors register_shutdown_function("fatal_handler"); function fatal_handler() { global $app;