Пример #1
0
 /**
  * Instantiates a class
  *
  * @access    private
  * @param    string
  * @param    string
  * @return    null
  */
 function _ci_init_class($class, $prefix = '', $config = FALSE)
 {
     $class = strtolower($class);
     // Is there an associated config file for this class?
     // {{{ Matchbox
     $module = $this->_matchbox->argument(3);
     if ($config === null) {
         if ($filepath = $this->_matchbox->find('config/' . $class . EXT, $module)) {
             include $filepath;
         }
     }
     // }}}
     if ($prefix == '') {
         $name = class_exists('CI_' . $class) ? 'CI_' . $class : $class;
     } else {
         $name = $prefix . $class;
     }
     // Set the variable name we will assign the class to
     $classvar = !isset($this->_ci_varmap[$class]) ? $class : $this->_ci_varmap[$class];
     // Instantiate the class
     $CI =& get_instance();
     if ($config !== NULL) {
         $CI->{$classvar} = new $name($config);
     } else {
         $CI->{$classvar} = new $name();
     }
 }
Пример #2
0
 /**
  * Load class
  *
  * This function loads the requested class.
  *
  * @access    private
  * @param     string    the item that is being loaded
  * @param    mixed    any additional parameters
  * @return     void
  */
 function _ci_load_class($class, $params = NULL)
 {
     // Get the class name, and while we're at it trim any slashes.
     // The directory path can be included as part of the class name,
     // but we don't want a leading slash
     $class = str_replace(EXT, '', trim($class, '/'));
     // Was the path included with the class name?
     // We look for a slash to determine this
     $subdir = '';
     if (strpos($class, '/') !== FALSE) {
         // explode the path so we can separate the filename from the path
         $x = explode('/', $class);
         // Reset the $class variable now that we know the actual filename
         $class = end($x);
         // Kill the filename from the array
         unset($x[count($x) - 1]);
         // Glue the path back together, sans filename
         $subdir = implode($x, '/') . '/';
     }
     // We'll test for both lowercase and capitalized versions of the file name
     foreach (array(ucfirst($class), strtolower($class)) as $class) {
         // {{{ Matchbox
         $module = $this->_matchbox->argument(2);
         if ($subclass = $this->_matchbox->find('libraries/' . $subdir . config_item('subclass_prefix') . $class . EXT, $module)) {
             $baseclass = $this->_matchbox->find('libraries/' . $class . EXT, $module, 2);
             // }}}
             if (!file_exists($baseclass)) {
                 log_message('error', "Unable to load the requested class: " . $class);
                 show_error("Unable to load the requested class: " . $class);
             }
             // Safety:  Was the class already loaded by a previous call?
             if (in_array($subclass, $this->_ci_classes)) {
                 $is_duplicate = TRUE;
                 log_message('debug', $class . " class already loaded. Second attempt ignored.");
                 return;
             }
             include $baseclass;
             include $subclass;
             $this->_ci_classes[] = $subclass;
             // {{{ Matchbox
             return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $module);
             // }}}
         }
         // Lets search for the requested library file and load it.
         $is_duplicate = FALSE;
         // {{{ Matchbox
         if ($filepath = $this->_matchbox->find('libraries/' . $subdir . $class . EXT, $module, 2)) {
             if (in_array($class, $this->_ci_classes)) {
                 $is_duplicate = true;
                 log_message('debug', $class . ' class already loaded. Second attempt ignored.');
                 return;
             }
             include $filepath;
             $this->_ci_classes[] = $class;
             return $this->_ci_init_class($class, '', $params, $module);
         }
         // }}}
     }
     // END FOREACH
     // One last attempt.  Maybe the library is in a subdirectory, but it wasn't specified?
     if ($subdir == '') {
         $path = strtolower($class) . '/' . $class;
         return $this->_ci_load_class($path, $params);
     }
     // If we got this far we were unable to find the requested class.
     // We do not issue errors if the load call failed due to a duplicate request
     if ($is_duplicate == FALSE) {
         log_message('error', "Unable to load the requested class: " . $class);
         show_error("Unable to load the requested class: " . $class);
     }
 }