From dea1f10d6d6e672d2a9e955f00d6475b68cefa28 Mon Sep 17 00:00:00 2001 From: Will Mendes Date: Tue, 7 Aug 2012 13:27:06 -0300 Subject: [PATCH] Checking existence of backslash and recursivity function Checking existence of backslash and recursivity function. Previously the file called functions 'ltrim ()' and 'rtrim ()' PHP, but if there were no backslash an error like 'Warning'; --- application/core/MY_Loader.php | 94 +++++++++++++++++----------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/application/core/MY_Loader.php b/application/core/MY_Loader.php index 9b2ee39..29d2ecf 100644 --- a/application/core/MY_Loader.php +++ b/application/core/MY_Loader.php @@ -93,53 +93,55 @@ function spark($spark, $autoload = array()) { $this->spark($s); } + }else{ + // + $length = strlen($spark); + if( ($length > 0) && (($spark[0] == '/') || ($spark[$length-1] == '/')) ) + $spark = trim($spark, '/'); + + $spark_path = SPARKPATH . $spark . '/'; + $parts = explode('/', $spark); + $spark_slug = strtolower($parts[0]); + + # If we've already loaded this spark, bail + if(array_key_exists($spark_slug, $this->_ci_loaded_sparks)) + { + return true; + } + + # Check that it exists. CI Doesn't check package existence by itself + if(!file_exists($spark_path)) + { + show_error("Cannot find spark path at $spark_path"); + } + + if(count($parts) == 2) + { + $this->_ci_loaded_sparks[$spark_slug] = $spark; + } + + $this->add_package_path($spark_path); + + foreach($autoload as $type => $read) + { + if($type == 'library') + $this->library($read); + elseif($type == 'model') + $this->model($read); + elseif($type == 'config') + $this->config($read); + elseif($type == 'helper') + $this->helper($read); + elseif($type == 'view') + $this->view($read); + else + show_error ("Could not autoload object of type '$type' ($read) for spark $spark"); + } + + // Looks for a spark's specific autoloader + $this->ci_autoloader($spark_path); } - - $spark = ltrim($spark, '/'); - $spark = rtrim($spark, '/'); - - $spark_path = SPARKPATH . $spark . '/'; - $parts = explode('/', $spark); - $spark_slug = strtolower($parts[0]); - - # If we've already loaded this spark, bail - if(array_key_exists($spark_slug, $this->_ci_loaded_sparks)) - { - return true; - } - - # Check that it exists. CI Doesn't check package existence by itself - if(!file_exists($spark_path)) - { - show_error("Cannot find spark path at $spark_path"); - } - - if(count($parts) == 2) - { - $this->_ci_loaded_sparks[$spark_slug] = $spark; - } - - $this->add_package_path($spark_path); - - foreach($autoload as $type => $read) - { - if($type == 'library') - $this->library($read); - elseif($type == 'model') - $this->model($read); - elseif($type == 'config') - $this->config($read); - elseif($type == 'helper') - $this->helper($read); - elseif($type == 'view') - $this->view($read); - else - show_error ("Could not autoload object of type '$type' ($read) for spark $spark"); - } - - // Looks for a spark's specific autoloader - $this->ci_autoloader($spark_path); - + return true; }