Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class MY_Loader extends CI_Loader {
  4.  
  5.  
  6.     function library_exist($class)
  7.     {
  8.  
  9.         // Get the class name, and while we're at it trim any slashes.
  10.         // The directory path can be included as part of the class name,
  11.         // but we don't want a leading slash
  12.         $class = str_replace(EXT, '', trim($class, '/'));
  13.  
  14.         // Was the path included with the class name?
  15.         // We look for a slash to determine this
  16.         $subdir = '';
  17.         if (strpos($class, '/') !== FALSE)
  18.         {
  19.             // explode the path so we can separate the filename from the path
  20.             $x = explode('/', $class);
  21.  
  22.             // Reset the $class variable now that we know the actual filename
  23.             $class = end($x);
  24.  
  25.             // Kill the filename from the array
  26.             unset($x[count($x)-1]);
  27.  
  28.             // Glue the path back together, sans filename
  29.             $subdir = implode($x, '/').'/';
  30.         }
  31.  
  32.  
  33.         // We'll test for both lowercase and capitalized versions of the file name
  34.         foreach (array(ucfirst($class), strtolower($class)) as $class)
  35.         {
  36.             // Lets search for the requested library file and load it.
  37.             for ($i = 1; $i < 3; $i++)
  38.             {
  39.                 $path = ($i % 2) ? APPPATH : BASEPATH;
  40.                 $filepath = $path.'libraries/'.$subdir.$class.EXT;
  41.  
  42.                 // Does the file exist?  No?  Bummer...
  43.                 if ( ! file_exists($filepath))
  44.                 {
  45.                     continue;
  46.                 }
  47.                 else
  48.                 {
  49.                     return TRUE;
  50.                 }
  51.             }
  52.         }
  53.  
  54.         // One last attempt.  Maybe the library is in a subdirectory, but it wasn't specified?
  55.         if ($subdir == '')
  56.         {
  57.             $path = strtolower($class).'/'.$class;
  58.             return $this->library_exist($path);
  59.         }
  60.  
  61.         return FALSE;
  62.  
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement