MY_Loader::_ci_load_library PHP Method

_ci_load_library() protected method

Internal CI Library Loader
protected _ci_load_library ( string $class, mixed $params = NULL, string $object_name = NULL ) : void
$class string Class name to load
$params mixed Optional parameters to pass to the class constructor
$object_name string Optional object name to assign to
return void
    protected function _ci_load_library($class, $params = NULL, $object_name = 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('.php', '', trim($class, '/'));
        // Was the path included with the class name?
        // We look for a slash to determine this
        if (($last_slash = strrpos($class, '/')) !== FALSE) {
            // Extract the path
            $subdir = substr($class, 0, ++$last_slash);
            // Get the filename from the path
            $class = substr($class, $last_slash);
        } else {
            $subdir = '';
        }
        $class = ucfirst($class);
        // Is this a stock library? There are a few special conditions if so ...
        if (file_exists(BASEPATH . 'libraries/' . $subdir . $class . '.php')) {
            return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
        }
        // Let's search for the requested library file and load it.
        foreach ($this->_ci_library_paths as $path) {
            // BASEPATH has already been checked for
            if ($path === BASEPATH) {
                continue;
            }
            $filepath = $path . 'libraries/' . $subdir . $class . '.php';
            // Safety: Was the class already loaded by a previous call?
            if (class_exists($class, FALSE)) {
                if (!empty($this->_ci_module_path)) {
                    $CI = $this->get_instance();
                    if (!isset($CI->{$class})) {
                        return $this->_ci_init_library($class, '', $params, $object_name);
                    }
                }
                // Before we deem this to be a duplicate request, let's see
                // if a custom object name is being supplied. If so, we'll
                // return a new instance of the object
                if ($object_name !== NULL) {
                    $CI = $this->get_instance();
                    if (!isset($CI->{$object_name})) {
                        return $this->_ci_init_library($class, '', $params, $object_name);
                    }
                }
                log_message('debug', $class . ' class already loaded. Second attempt ignored.');
                return;
            } elseif (!file_exists($filepath)) {
                continue;
            }
            include_once $filepath;
            return $this->_ci_init_library($class, '', $params, $object_name);
        }
        // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
        if ($subdir === '') {
            return $this->_ci_load_library($class . '/' . $class, $params, $object_name);
        }
        // If we got this far we were unable to find the requested class.
        log_message('error', 'Unable to load the requested class: ' . $class);
        show_error('Unable to load the requested class: ' . $class);
    }