wiki:rfc/autoload is not used any more and exists only for history. Post new tickets on the Github account. n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Version 3 (modified by laurentj, 9 years ago) (diff)


Autoload in modules

implemented in Jelix 1.4


Bring the ability to declare an autoloader or to declare class mapping, in a module.


We won't have to use jClasses to use some class eavily used. (however, jClasses is very interesting for dependency injection etc., and to use some classes not used very often).

We should move some classes of Jelix in their own modules. For example, we could move classes of lib/jelix/auth/ to the jauth modules. It's more consistent and ease probably futur improvements.


We should add a class which is an autoloader. It should have methods to declare class mapping (path of a class file -> class name) and path corresponding to namespace, following the PSR-0 specification.

(Works have been already done in a branch of Laurentj's repository).

declaring autoloader

We should have a way, in a module, to declare some class mapping, or an autoloader (or both).

Several solutions:

1) having in module.xml some tags like <classautoload name="foo" path="classes/dir/foo.php" /> During the configuration compilation, the compiler could load every module.xml, extract all autoloads information and store it into the compiled configuration file (so no need to read all module.xml at each action).

2) having an autoload.php file in the module. its responsibility is to declare class mapping into the main autoloader of jelix, and if needed, to provide its own autoloader. During configuration compilation, all path of all autoload.php file are stored in the compiled configuration file, so Jelix don't have to discover all autoload.php file.

The first solution is probably better in term of performance, because there isn't many file to include at startup.


(open a discussion in the forum or in the mailing list)