fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

import() for app vendor directory #820

Closed daveganley closed 12 years ago

daveganley commented 12 years ago

When trying to import vendor libs using import a error occurs. It would be good if this was possible with something like this in the core base.php

if ( ! function_exists('import')) { function import($path, $folder = 'classes') { $path = str_replace('/', DIRECTORY_SEPARATOR, $path);

    if (is_file(COREPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php'))
    {
        require_once COREPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
    }
            elseif (is_file(APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php'))
    {
        require_once APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
    }
}

}

antitoxic commented 12 years ago

I found this via: http://fuelphp.com/forums/topics/view/7487

Does the import autoloads just one file? Is there much benefit to this compared to Autoloader::add_class or native require_once?

Edit: this can also be considered as related: http://fuelphp.com/forums/topics/view/7285

jschreuder commented 12 years ago

This is just duplicating native PHP require behavior without any advantage: require APPPATH.'vendor/lib/somefile.php is far superior to this.

Don't be afraid to use native PHP functionality when applicable: it's faster and less ambiguous code.