Welcome Guest, Not a member yet? Register   Sign In
Loading libraries from subdirs
#1

[eluser]Spockz[/eluser]
As I noticed loading libraries from subdirs isn't possible. So I altered some code to make it work. However I'm still with 1.6.3 and I didn't test this with 1.7.x. Here is the code I altered. I hope this adds something useful to CI:

/System/libraries/Loader.php
Code:
* 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
        $class = str_replace(EXT, '', $class);
        
        // Split the classname in a path and file section
        $classPathParts = explode('/', str_replace('\\', '/', $class));
        $classFile = array_pop($classPathParts);
        $classPath = implode('/', $classPathParts).(count($classPathParts) > 0 ? '/' : '');
        // --
        
        // We'll test for both lowercase and capitalized versions of the file name
        foreach (array(ucfirst($classFile), strtolower($classFile)) as $classFile)
        {
            $subclass = APPPATH.'libraries/'.$classPath.config_item('subclass_prefix').$classFile.EXT;

            // Is this a class extension request?            
            if (file_exists($subclass))
            {
                $baseclass = BASEPATH.'libraries/'.$classPath.ucfirst($classFile).EXT;
                
                if ( ! file_exists($baseclass))
                {
                    log_message('error', "Unable to load the requested class: ".$classPath.$classFile);
                    show_error("Unable to load the requested class: ".$classPath.$classFile);
                }

                // Safety:  Was the class already loaded by a previous call?
                if (in_array($subclass, $this->_ci_classes))
                {
                    $is_duplicate = TRUE;
                    log_message('debug', $classPath.$classFile." class already loaded. Second attempt ignored.");
                    return;
                }
    
                include_once($baseclass);                
                include_once($subclass);
                $this->_ci_classes[] = $subclass;
    
                return $this->_ci_init_class($classPath.$classFile, config_item('subclass_prefix'), $params);            
            }
        
            // Lets search for the requested library file and load it.
            $is_duplicate = FALSE;        
            for ($i = 1; $i < 3; $i++)
            {
                $path = ($i % 2) ? APPPATH : BASEPATH;    
                $filepath = $path.'libraries/'.$classPath.$classFile.EXT;
                
                // Does the file exist?  No?  Bummer...
                if ( ! file_exists($filepath))
                {
                    continue;
                }
                
                // Safety:  Was the class already loaded by a previous call?
                if (in_array($filepath, $this->_ci_classes))
                {
                    $is_duplicate = TRUE;
                    log_message('debug', $classPath.$classFile." class already loaded. Second attempt ignored.");
                    return;
                }
                
                include_once($filepath);
                $this->_ci_classes[] = $filepath;
                return $this->_ci_init_class($classFile, '', $params);
            }
        } // END FOREACH
        
        // 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: ".$classPath.$classFile);
            show_error("Unable to load the requested class: ".$classPath.$classFile);
        }
    }
#2

[eluser]louis w[/eluser]
You should upgrade, this functionality is built into the latest release of CI.
#3

[eluser]Spockz[/eluser]
Ah ok. I'll wait until the database problems are fixed. However I'll release a CodeIgniter/Doctrine bundle soon.
#4

[eluser]louis w[/eluser]
What DB probs? Was not aware of them.
#5

[eluser]Spockz[/eluser]
There were problems with escaping. But those might be fixed now in SVN. And we got some people in the irc channel having problems with it. So that gave me the impression there was something seriously wrong. But maybe I was wrong in that.
#6

[eluser]louis w[/eluser]
Ohh ok. Well thanks for the fyi, I will watch for it.
I pretty busy so have not been watching the forums for a while. Might have missed it.




Theme © iAndrew 2016 - Forum software by © MyBB