From 6df76fcaf23cc3c2c4df8a758e5a02eb95342573 Mon Sep 17 00:00:00 2001 From: Criptos Date: Mon, 16 Sep 2013 01:11:11 -0500 Subject: [PATCH 1/7] Added lazyRoute function to allow to segment the load of information based on routes --- src/EpiRoute.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/EpiRoute.php b/src/EpiRoute.php index 3051d96..bf9095e 100644 --- a/src/EpiRoute.php +++ b/src/EpiRoute.php @@ -18,8 +18,11 @@ class EpiRoute { private static $instance; private $routes = array(); + private $lazyRoute = array(); + private $lazyRegexes = array(); private $regexes= array(); private $route = null; + const routeKey= '__route__'; const httpGet = 'GET'; const httpPost= 'POST'; @@ -94,6 +97,7 @@ public function delete($route, $callback, $isApi = false) */ public function load($file) { + print "si si la estsa cargando...
\n"; $file = Epi::getPath('config') . "/{$file}"; if(!file_exists($file)) { @@ -167,6 +171,15 @@ public function getRoute($route = false, $httpMethod = null) if($httpMethod === null) $httpMethod = $_SERVER['REQUEST_METHOD']; + + foreach($this->lazyRegexes as $ind => $regex) + { + if(preg_match($regex, $this->route)) + { + require_once $this->lazyRoute[$ind]['include']; + } + } + foreach($this->regexes as $ind => $regex) { @@ -254,6 +267,23 @@ private function addRoute($route, $callback, $method, $postprocess = false) if(Epi::getSetting('debug')) getDebug()->addMessage(__CLASS__, sprintf('Found %s : %s : %s', $method, $route, json_encode($callback))); } + + /** + * addLazyRoute($route, $filename) + * @name addLazyRoute + * @author Andres Tello + * @param string $route + * @param string $filename + * + */ + public function addLazyRoute($route=false, $include=false) + { + $this->lazyRoute[]=array('path'=>$route, 'include'=>$fileinclude); + $this->lazyRegexes[]= "#^{$route}/(.*)$#"; + if(EPi::GetSetting('debug')) + getDebug()->addMessage(__CLASS__, sprintf('Found lazyRoute : %s : %s ', $path, $include)); + } + } function getRoute() From 614444910d9ffb2970851f8f8198c07cdb7c1bd0 Mon Sep 17 00:00:00 2001 From: Criptos Date: Mon, 16 Sep 2013 01:15:29 -0500 Subject: [PATCH 2/7] Added explanation to getRoute()->lazyLoad("path", "filename"); --- docs/Route.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/Route.markdown b/docs/Route.markdown index a04ab25..274ebe5 100644 --- a/docs/Route.markdown +++ b/docs/Route.markdown @@ -119,6 +119,17 @@ To load your ini file you'll need to set the path to your config file and call t ---------------------------------------- +### Lazy Loadin routes from an external file + +When projects grow, loading all the routes and associate code becames to expensive, to avoid this, you can create a lazyload when a route is detected. + + getRoute()->lazyLoad("/path", "path/to/includefile"); + +This will provoke when a route to a /path is detected it will load the file pointed by includefile. +There you can load more routes. + +---------------------------------------- + ### Server side redirects You can perform server side redirects using this module. The `redirect()` method takes between 1 and 3 parameters. From ee4fa439208cf5cc0450556bd1847ab5539407b5 Mon Sep 17 00:00:00 2001 From: Criptos Date: Mon, 16 Sep 2013 01:20:22 -0500 Subject: [PATCH 3/7] Document fix and code cleaning --- docs/Route.markdown | 4 ++-- src/EpiRoute.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/Route.markdown b/docs/Route.markdown index 274ebe5..853aa01 100644 --- a/docs/Route.markdown +++ b/docs/Route.markdown @@ -119,11 +119,11 @@ To load your ini file you'll need to set the path to your config file and call t ---------------------------------------- -### Lazy Loadin routes from an external file +### Lazy Loading routes from an external file When projects grow, loading all the routes and associate code becames to expensive, to avoid this, you can create a lazyload when a route is detected. - getRoute()->lazyLoad("/path", "path/to/includefile"); + getRoute()->addLazyRoute("/path", "path/to/includefile"); This will provoke when a route to a /path is detected it will load the file pointed by includefile. There you can load more routes. diff --git a/src/EpiRoute.php b/src/EpiRoute.php index bf9095e..a5accc4 100644 --- a/src/EpiRoute.php +++ b/src/EpiRoute.php @@ -97,7 +97,6 @@ public function delete($route, $callback, $isApi = false) */ public function load($file) { - print "si si la estsa cargando...
\n"; $file = Epi::getPath('config') . "/{$file}"; if(!file_exists($file)) { From 6dce154d25291a73d1a94aca0a432d682469ba59 Mon Sep 17 00:00:00 2001 From: Criptos Date: Mon, 16 Sep 2013 01:50:05 -0500 Subject: [PATCH 4/7] *Shame on me* Variable nama change due no testing... :( --- src/EpiRoute.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EpiRoute.php b/src/EpiRoute.php index a5accc4..ef604ec 100644 --- a/src/EpiRoute.php +++ b/src/EpiRoute.php @@ -97,6 +97,7 @@ public function delete($route, $callback, $isApi = false) */ public function load($file) { + print "si si la estsa cargando...
\n"; $file = Epi::getPath('config') . "/{$file}"; if(!file_exists($file)) { @@ -277,7 +278,7 @@ private function addRoute($route, $callback, $method, $postprocess = false) */ public function addLazyRoute($route=false, $include=false) { - $this->lazyRoute[]=array('path'=>$route, 'include'=>$fileinclude); + $this->lazyRoute[]=array('path'=>$route, 'include'=>$include); $this->lazyRegexes[]= "#^{$route}/(.*)$#"; if(EPi::GetSetting('debug')) getDebug()->addMessage(__CLASS__, sprintf('Found lazyRoute : %s : %s ', $path, $include)); From ed56d902e34bfb36d647c15c5d938e6616345bca Mon Sep 17 00:00:00 2001 From: ANDRES TELLO Date: Thu, 10 Mar 2016 13:07:48 -0600 Subject: [PATCH 5/7] Update EpiSession.php Added delete and end interfaces as declared by documentation. --- src/EpiSession.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/EpiSession.php b/src/EpiSession.php index ff001da..b4ab211 100644 --- a/src/EpiSession.php +++ b/src/EpiSession.php @@ -48,6 +48,8 @@ interface EpiSessionInterface { public function get($key = null); public function set($key = null, $value = null); + public function delete($key = null); + public function end(); } if(!function_exists('getSession')) From b9ab0e906b04d2333981e7d9750f01de44de3bec Mon Sep 17 00:00:00 2001 From: ANDRES TELLO Date: Thu, 10 Mar 2016 13:08:57 -0600 Subject: [PATCH 6/7] Update EpiSession_Php.php Added function delete to unset variable of session, as documentation states --- src/EpiSession_Php.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/EpiSession_Php.php b/src/EpiSession_Php.php index e1ab103..04f2b3b 100644 --- a/src/EpiSession_Php.php +++ b/src/EpiSession_Php.php @@ -29,6 +29,13 @@ public function set($key = null, $value = null) $_SESSION[$key] = $value; return $value; } + + public function delete($key = null) + { + if(empty($key) || !isset($_SESSION[$key])) + return false; + unset $_SESSION[$key]; + } public function __construct() { From 75ae0dcdbf2a4e161a00f0e5d4d98e538137bc06 Mon Sep 17 00:00:00 2001 From: ANDRES TELLO Date: Thu, 10 Mar 2016 13:14:46 -0600 Subject: [PATCH 7/7] Update EpiSession.php Fix warning when EpiSession::employ() only return 1 element. --- src/EpiSession.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/EpiSession.php b/src/EpiSession.php index b4ab211..038b84d 100644 --- a/src/EpiSession.php +++ b/src/EpiSession.php @@ -57,6 +57,9 @@ public function end(); function getSession() { $employ = EpiSession::employ(); + if(sizeof($employ)==1) + $class=$employ; + else $class = array_shift($employ); if($employ && class_exists($class)) return EpiSession::getInstance($class, $employ);