CodeIgniter Forums
Suggestion : SPL Autoload config - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Suggestion : SPL Autoload config (/showthread.php?tid=62909)



Suggestion : SPL Autoload config - djha - 09-07-2015

Hi,

Actually, loading a class is only possible by "CI_Loader" class.
It will be interesting to disable this feature and use "spl_autoload_register".

An option $config['spl_autoload'] with a function value (class & method) that allow to autoload your own classes.
Then you can decide the naming convention & folders hierarchy.

Possible custom naming example :

Code:
class "MY_Storage_Adapter_File" store in "MY/Storage/Adapter/File.php"
autoload : $file_path = str_replace('_', '/', $class);

That's mean PSR-0 or PSR-4 autoloading ...

M.


RE: Suggestion : SPL Autoload config - mwhitney - 09-08-2015

http://www.codeigniter.com/user_guide/general/autoloader.html

If you set $config['composer_autoload'] to a path to a file which registers your autoloader, CI3 will call the file in /system/core/CodeIgniter.php. Alternatively, if you just set the value to TRUE, it will attempt to find the file in APPPATH . 'vendor/autoload.php'.

While the intent of the configuration value is to register composer as an autoloader, you could configure any autoloader the same way, you just need a simple script that registers your autoloader.

As for disabling CI_Loader, that would just disable all of CI's system classes, since they don't follow the conventions required by most autoloaders.


RE: Suggestion : SPL Autoload config - djha - 09-08-2015

I register my autoload function in the file "vendor/autoload.php".
(previously, I used the pre_system hook).

Thanks,
M.