From 4ee4f16ffe06e247d2cb79a2054ab5d5315d82b2 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 15 Dec 2013 11:24:14 +0100 Subject: Problème de casse renommage répertoire MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Minz/Dispatcher.php | 138 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 lib/Minz/Dispatcher.php (limited to 'lib/Minz/Dispatcher.php') diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php new file mode 100644 index 000000000..2898b5f00 --- /dev/null +++ b/lib/Minz/Dispatcher.php @@ -0,0 +1,138 @@ + +*/ + +/** + * Le Dispatcher s'occupe d'initialiser le Controller et d'executer l'action + * déterminée dans la Request + * C'est un singleton + */ +class Minz_Dispatcher { + const CONTROLLERS_PATH_NAME = '/Controllers'; + + /* singleton */ + private static $instance = null; + + private $router; + private $controller; + + /** + * Récupère l'instance du Dispatcher + */ + public static function getInstance ($router) { + if (is_null (self::$instance)) { + self::$instance = new Minz_Dispatcher ($router); + } + return self::$instance; + } + + /** + * Constructeur + */ + private function __construct ($router) { + $this->router = $router; + } + + /** + * Lance le controller indiqué dans Request + * Remplit le body de Response à partir de la Vue + * @exception Minz_Exception + */ + public function run () { + $cache = new Minz_Cache(); + // Le ob_start est dupliqué : sans ça il y a un bug sous Firefox + // ici on l'appelle avec 'ob_gzhandler', après sans. + // Vraisemblablement la compression fonctionne mais c'est sale + // J'ignore les effets de bord :( + ob_start ('ob_gzhandler'); + + if (Minz_Cache::isEnabled () && !$cache->expired ()) { + ob_start (); + $cache->render (); + $text = ob_get_clean(); + } else { + while (Minz_Request::$reseted) { + Minz_Request::$reseted = false; + + try { + $this->createController ('FreshRSS_' . Minz_Request::controllerName () . '_Controller'); + $this->controller->init (); + $this->controller->firstAction (); + $this->launchAction ( + Minz_Request::actionName () + . 'Action' + ); + $this->controller->lastAction (); + + if (!Minz_Request::$reseted) { + ob_start (); + $this->controller->view ()->build (); + $text = ob_get_clean(); + } + } catch (Minz_Exception $e) { + throw $e; + } + } + + if (Minz_Cache::isEnabled ()) { + $cache->cache ($text); + } + } + + Minz_Response::setBody ($text); + } + + /** + * Instancie le Controller + * @param $controller_name le nom du controller à instancier + * @exception ControllerNotExistException le controller n'existe pas + * @exception ControllerNotActionControllerException controller n'est + * > pas une instance de ActionController + */ + private function createController ($controller_name) { + $filename = APP_PATH . self::CONTROLLERS_PATH_NAME . '/' + . $controller_name . '.php'; + + if (!class_exists ($controller_name)) { + throw new Minz_ControllerNotExistException ( + $controller_name, + Minz_Exception::ERROR + ); + } + $this->controller = new $controller_name ($this->router); + + if (! ($this->controller instanceof Minz_ActionController)) { + throw new Minz_ControllerNotActionControllerException ( + $controller_name, + Minz_Exception::ERROR + ); + } + } + + /** + * Lance l'action sur le controller du dispatcher + * @param $action_name le nom de l'action + * @exception ActionException si on ne peut pas exécuter l'action sur + * le controller + */ + private function launchAction ($action_name) { + if (!Minz_Request::$reseted) { + if (!is_callable (array ( + $this->controller, + $action_name + ))) { + throw new Minz_ActionException ( + get_class ($this->controller), + $action_name, + Minz_Exception::ERROR + ); + } + call_user_func (array ( + $this->controller, + $action_name + )); + } + } +} -- cgit v1.2.3 From 4d6ab45b03031e1c13ac2d3589364a43a0fe5578 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 30 Dec 2013 12:43:39 +0100 Subject: Micro-optimisation : évite is_null et quelques if/else MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contribue à https://github.com/marienfressinaud/FreshRSS/issues/303 --- app/Models/Category.php | 2 +- app/Models/Entry.php | 6 +----- app/Models/Feed.php | 32 +++++++++++--------------------- lib/Minz/Dispatcher.php | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) (limited to 'lib/Minz/Dispatcher.php') diff --git a/app/Models/Category.php b/app/Models/Category.php index e70d1303f..8e1e44ef8 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -48,7 +48,7 @@ class FreshRSS_Category extends Minz_Model { return $this->nbNotRead; } public function feeds () { - if (is_null ($this->feeds)) { + if ($this->feeds === null) { $feedDAO = new FreshRSS_FeedDAO (); $this->feeds = $feedDAO->listByCategory ($this->id ()); $this->nbFeed = 0; diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ab9605eb1..83f68ce78 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -38,11 +38,7 @@ class FreshRSS_Entry extends Minz_Model { return $this->title; } public function author () { - if (is_null ($this->author)) { - return ''; - } else { - return $this->author; - } + return $this->author === null ? '' : $this->author; } public function content () { return $this->content; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 32f8546dd..f38828a42 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -44,11 +44,7 @@ class FreshRSS_Feed extends Minz_Model { return $this->category; } public function entries () { - if (!is_null ($this->entries)) { - return $this->entries; - } else { - return array (); - } + return $this->entries === null ? array() : $this->entries; } public function name () { return $this->name; @@ -140,10 +136,7 @@ class FreshRSS_Feed extends Minz_Model { $this->category = $value >= 0 ? $value : 0; } public function _name ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->name = $value; + $this->name = $value === null ? '' : $value; } public function _website ($value, $validate=true) { if ($validate) { @@ -155,10 +148,7 @@ class FreshRSS_Feed extends Minz_Model { $this->website = $value; } public function _description ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->description = $value; + $this->description = $value === null ? '' : $value; } public function _lastUpdate ($value) { $this->lastUpdate = $value; @@ -190,7 +180,7 @@ class FreshRSS_Feed extends Minz_Model { } public function load ($loadDetails = false) { - if (!is_null ($this->url)) { + if ($this->url !== null) { if (CACHE_PATH === false) { throw new Minz_FileNotExistException ( 'CACHE_PATH', @@ -253,7 +243,7 @@ class FreshRSS_Feed extends Minz_Model { // si on a utilisé l'auto-discover, notre url va avoir changé $subscribe_url = $feed->subscribe_url (); - if (!is_null ($subscribe_url) && $subscribe_url != $this->url) { + if ($subscribe_url !== null && $subscribe_url !== $this->url) { if ($this->httpAuth != '') { // on enlève les id si authentification HTTP $subscribe_url = preg_replace ('#((.+)://)((.+)@)(.+)#', '${1}${5}', $subscribe_url); @@ -263,7 +253,7 @@ class FreshRSS_Feed extends Minz_Model { if ($loadDetails) { $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8'); - $this->_name (!is_null ($title) ? $title : $this->url); + $this->_name ($title === null ? $this->url : $title); $this->_website(html_only_entity_decode($feed->get_link())); $this->_description(html_only_entity_decode($feed->get_description())); @@ -286,7 +276,7 @@ class FreshRSS_Feed extends Minz_Model { // gestion des tags (catégorie == tag) $tags_tmp = $item->get_categories (); $tags = array (); - if (!is_null ($tags_tmp)) { + if ($tags_tmp !== null) { foreach ($tags_tmp as $tag) { $tags[] = html_only_entity_decode ($tag->get_label ()); } @@ -308,10 +298,10 @@ class FreshRSS_Feed extends Minz_Model { $entry = new FreshRSS_Entry ( $this->id (), $item->get_id (), - !is_null ($title) ? $title : '', - !is_null ($author) ? html_only_entity_decode ($author->name) : '', - !is_null ($content) ? $content : '', - !is_null ($link) ? $link : '', + $title === null ? '' : $title, + $author === null ? '' : html_only_entity_decode ($author->name), + $content === null ? '' : $content, + $link === null ? '' : $link, $date ? $date : time () ); $entry->_tags ($tags); diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index 2898b5f00..c2c5e7f65 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -22,7 +22,7 @@ class Minz_Dispatcher { * Récupère l'instance du Dispatcher */ public static function getInstance ($router) { - if (is_null (self::$instance)) { + if (self::$instance === null) { self::$instance = new Minz_Dispatcher ($router); } return self::$instance; -- cgit v1.2.3 From b4c477ca41a7ecaa6364dd6a97603829b14b11ef Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 2 Jan 2014 01:47:03 +0100 Subject: actualize_script compatible multi-utilisateur MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Messages plus verbeux dans actualize_script * Ajout d'un message syslog lorsque SimplePie fait une requête HTTP * Minz_Session ne fermait pas les sessions complètement. * Nouvelle option dans Minz_Dispatcher et Minz_FrontController pour ne pas utiliser ob_gzhandler. Contribue à https://github.com/marienfressinaud/FreshRSS/issues/126 --- app/actualize_script.php | 36 ++++++++++++++++++++++++++---------- app/views/feed/actualize.phtml | 2 +- lib/Minz/Dispatcher.php | 23 +++++++++++++++++------ lib/Minz/FrontController.php | 15 ++++++++++++++- lib/Minz/ModelPdo.php | 5 +++++ lib/Minz/Session.php | 2 +- lib/SimplePie/SimplePie/File.php | 1 + 7 files changed, 65 insertions(+), 19 deletions(-) (limited to 'lib/Minz/Dispatcher.php') diff --git a/app/actualize_script.php b/app/actualize_script.php index efe21fab6..e0f995afe 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -3,24 +3,40 @@ require(dirname(__FILE__) . '/../constants.php'); //TODO: check if already running -$_GET['c'] = 'feed'; -$_GET['a'] = 'actualize'; -$_GET['force'] = true; -$_SERVER['HTTP_HOST'] = ''; - require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -$freshRSS = new FreshRSS (); +session_cache_limiter(''); +ob_implicit_flush(false); +ob_start(); +echo 'Results: ', "\n"; //Buffered $users = listUsers(); shuffle($users); -foreach ($users as $user) { +foreach ($users as $myUser) { + syslog(LOG_INFO, 'FreshRSS actualize ' . $myUser); + fwrite(STDOUT, 'Actualize ' . $myUser . "...\n"); //Unbuffered + echo $myUser, ' '; //Buffered + + $_GET['c'] = 'feed'; + $_GET['a'] = 'actualize'; + $_GET['ajax'] = 1; + $_GET['force'] = true; + $_SERVER['HTTP_HOST'] = ''; + + $freshRSS = new FreshRSS(); + $freshRSS->_useOb(false); + Minz_Session::init('FreshRSS'); - Minz_Session::_param('currentUser', $user); + Minz_Session::_param('currentUser', $myUser); + $freshRSS->init(); $freshRSS->run(); - //invalidateHttpCache(); - touch(LOG_PATH . '/' . $user . '.log'); + + invalidateHttpCache(); Minz_Session::unset_session(true); + Minz_ModelPdo::clean(); } +syslog(LOG_INFO, 'FreshRSS actualize done.'); +ob_end_flush(); +fwrite(STDOUT, 'Done.' . "\n"); diff --git a/app/views/feed/actualize.phtml b/app/views/feed/actualize.phtml index a0aba9318..d86bac9de 100644 --- a/app/views/feed/actualize.phtml +++ b/app/views/feed/actualize.phtml @@ -1 +1 @@ -OK \ No newline at end of file +OK diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index c2c5e7f65..71dfe8ac6 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -40,19 +40,26 @@ class Minz_Dispatcher { * Remplit le body de Response à partir de la Vue * @exception Minz_Exception */ - public function run () { + public function run ($ob = true) { $cache = new Minz_Cache(); // Le ob_start est dupliqué : sans ça il y a un bug sous Firefox // ici on l'appelle avec 'ob_gzhandler', après sans. // Vraisemblablement la compression fonctionne mais c'est sale // J'ignore les effets de bord :( - ob_start ('ob_gzhandler'); + if ($ob) { + ob_start ('ob_gzhandler'); + } if (Minz_Cache::isEnabled () && !$cache->expired ()) { - ob_start (); + if ($ob) { + ob_start (); + } $cache->render (); - $text = ob_get_clean(); + if ($ob) { + $text = ob_get_clean(); + } } else { + $text = ''; //TODO: Clean this code while (Minz_Request::$reseted) { Minz_Request::$reseted = false; @@ -67,9 +74,13 @@ class Minz_Dispatcher { $this->controller->lastAction (); if (!Minz_Request::$reseted) { - ob_start (); + if ($ob) { + ob_start (); + } $this->controller->view ()->build (); - $text = ob_get_clean(); + if ($ob) { + $text = ob_get_clean(); + } } } catch (Minz_Exception $e) { throw $e; diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php index 8e9c511a6..7b8526bc8 100644 --- a/lib/Minz/FrontController.php +++ b/lib/Minz/FrontController.php @@ -26,6 +26,8 @@ class Minz_FrontController { protected $dispatcher; protected $router; + private $useOb = true; + /** * Constructeur * Initialise le router et le dispatcher @@ -61,7 +63,7 @@ class Minz_FrontController { */ public function run () { try { - $this->dispatcher->run (); + $this->dispatcher->run ($this->useOb); Minz_Response::send (); } catch (Minz_Exception $e) { try { @@ -94,4 +96,15 @@ class Minz_FrontController { } exit ('### Application problem ###
'."\n".$txt); } + + public function useOb() { + return $this->useOb; + } + + /** + * Use ob_start('ob_gzhandler') or not. + */ + public function _useOb($ob) { + return $this->useOb = (bool)$ob; + } } diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index a643da1f0..831df13a2 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -93,6 +93,11 @@ class Minz_ModelPdo { $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); return $res[0]; } + + public static function clean() { + self::$sharedBd = null; + self::$sharedPrefix = ''; + } } class FreshPDO extends PDO { diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php index 3f6ed88a3..37faff0fb 100644 --- a/lib/Minz/Session.php +++ b/lib/Minz/Session.php @@ -60,7 +60,7 @@ class Minz_Session { public static function unset_session ($force = false) { $language = self::param ('language'); - session_unset (); + session_destroy(); self::$session = array (); if (!$force) { diff --git a/lib/SimplePie/SimplePie/File.php b/lib/SimplePie/SimplePie/File.php index 063ad955e..cf926cf5a 100644 --- a/lib/SimplePie/SimplePie/File.php +++ b/lib/SimplePie/SimplePie/File.php @@ -77,6 +77,7 @@ class SimplePie_File $this->useragent = $useragent; if (preg_match('/^http(s)?:\/\//i', $url)) { + syslog(LOG_INFO, 'SimplePie GET ' . $url); //FreshRSS if ($useragent === null) { $useragent = ini_get('user_agent'); -- cgit v1.2.3