aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz/FrontController.php
diff options
context:
space:
mode:
authorGravatar Clément <clement@selfhost.fr> 2017-02-15 14:14:03 +0100
committerGravatar Clément <clement@selfhost.fr> 2017-02-15 14:14:03 +0100
commit5a1bb1393b4496eb35a2ffb3cc63d41c9dc1e2e5 (patch)
tree67028e45792c575c25c92616633f64cc7a4a13eb /lib/Minz/FrontController.php
parent7e949d50320317b5c3b5a2da2bdaf324e794b2f7 (diff)
parent5f637bd816b7323885bfe1751a1724ee59a822f6 (diff)
Merge remote-tracking branch 'FreshRSS/master'
Diffstat (limited to 'lib/Minz/FrontController.php')
-rw-r--r--lib/Minz/FrontController.php89
1 files changed, 57 insertions, 32 deletions
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php
index 80eda8877..f9eff3db6 100644
--- a/lib/Minz/FrontController.php
+++ b/lib/Minz/FrontController.php
@@ -24,50 +24,67 @@
*/
class Minz_FrontController {
protected $dispatcher;
- protected $router;
-
- private $useOb = true;
/**
* Constructeur
- * Initialise le router et le dispatcher
+ * Initialise le dispatcher, met à jour la Request
*/
public function __construct () {
- if (LOG_PATH === false) {
- $this->killApp ('Path not found: LOG_PATH');
- }
-
try {
- Minz_Configuration::init ();
+ Minz_Configuration::register('system',
+ DATA_PATH . '/config.php',
+ DATA_PATH . '/config.default.php');
+ $this->setReporting();
- Minz_Request::init ();
+ Minz_Request::init();
- $this->router = new Minz_Router ();
- $this->router->init ();
- } catch (Minz_RouteNotFoundException $e) {
- Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
- Minz_Error::error (
- 404,
- array ('error' => array ($e->getMessage ()))
+ $url = $this->buildUrl();
+ $url['params'] = array_merge (
+ $url['params'],
+ Minz_Request::fetchPOST ()
);
+ Minz_Request::forward ($url);
} catch (Minz_Exception $e) {
- Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
+ Minz_Log::error($e->getMessage());
$this->killApp ($e->getMessage ());
}
- $this->dispatcher = Minz_Dispatcher::getInstance ($this->router);
+ $this->dispatcher = Minz_Dispatcher::getInstance();
}
/**
- * Démarre l'application (lance le dispatcher et renvoie la réponse
+ * Retourne un tableau représentant l'url passée par la barre d'adresses
+ * @return tableau représentant l'url
+ */
+ private function buildUrl() {
+ $url = array ();
+
+ $url['c'] = Minz_Request::fetchGET (
+ 'c',
+ Minz_Request::defaultControllerName ()
+ );
+ $url['a'] = Minz_Request::fetchGET (
+ 'a',
+ Minz_Request::defaultActionName ()
+ );
+ $url['params'] = Minz_Request::fetchGET ();
+
+ // post-traitement
+ unset ($url['params']['c']);
+ unset ($url['params']['a']);
+
+ return $url;
+ }
+
+ /**
+ * Démarre l'application (lance le dispatcher et renvoie la réponse)
*/
public function run () {
try {
- $this->dispatcher->run ($this->useOb);
- Minz_Response::send ();
+ $this->dispatcher->run();
} catch (Minz_Exception $e) {
try {
- Minz_Log::record ($e->getMessage (), Minz_Log::ERROR);
+ Minz_Log::error($e->getMessage());
} catch (Minz_PermissionDeniedException $e) {
$this->killApp ($e->getMessage ());
}
@@ -97,14 +114,22 @@ class Minz_FrontController {
exit ('### Application problem ###<br />'."\n".$txt);
}
- public function useOb() {
- return $this->useOb;
- }
-
- /**
- * Use ob_start('ob_gzhandler') or not.
- */
- public function _useOb($ob) {
- return $this->useOb = (bool)$ob;
+ private function setReporting() {
+ $conf = Minz_Configuration::get('system');
+ switch($conf->environment) {
+ case 'production':
+ error_reporting(E_ALL);
+ ini_set('display_errors','Off');
+ ini_set('log_errors', 'On');
+ break;
+ case 'development':
+ error_reporting(E_ALL);
+ ini_set('display_errors','On');
+ ini_set('log_errors', 'On');
+ break;
+ case 'silent':
+ error_reporting(0);
+ break;
+ }
}
}