From ff2363aee2a777a830f3ba68756f20b348b2f726 Mon Sep 17 00:00:00 2001 From: Vallabh Kansagara Date: Mon, 10 Aug 2015 11:34:11 +0530 Subject: [PATCH] ext defined as local constant to the class only. ext defined as a local constant to the class only and improved as self::EXT to call the specific defined constant to particular class. This is improvement to the library. --- Controllerlist.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Controllerlist.php b/Controllerlist.php index 654bb16..ee1839e 100644 --- a/Controllerlist.php +++ b/Controllerlist.php @@ -17,13 +17,23 @@ * * @author Peter Prins */ -class ControllerList { - + + +class ControllerList +{ + + /** * Codeigniter reference */ private $CI; - + + /** + * Define EXT as your controller file extension. + * Defining in class is more secure than defining global. + */ + const EXT = '.php'; + /** * Array that will hold the controller names and methods */ @@ -63,12 +73,12 @@ private function setControllers() { // if the value in the loop is a directory loop through that directory if(is_dir($controller)) { // Get name of directory - $dirname = basename($controller, EXT); + $dirname = basename($controller, self::EXT); // Loop through the subdirectory foreach(glob(APPPATH . 'controllers/'.$dirname.'/*') as $subdircontroller) { // Get the name of the subdir - $subdircontrollername = basename($subdircontroller, EXT); + $subdircontrollername = basename($subdircontroller, self::EXT); // Load the controller file in memory if it's not load already if(!class_exists($subdircontrollername)) { @@ -87,7 +97,7 @@ private function setControllers() { } else if(pathinfo($controller, PATHINFO_EXTENSION) == "php"){ // value is no directory get controller name - $controllername = basename($controller, EXT); + $controllername = basename($controller, self::EXT); // Load the class in memory (if it's not loaded already) if(!class_exists($controllername)) { @@ -110,4 +120,4 @@ private function setControllers() { } } } -// EOF \ No newline at end of file +// EOF