xautoload is a comprehensive and yet highly efficient PHP class loading suite.
Class loading for Drupal modules:
- D8-style PSR-0 module namespaces (out of the box).
- PSR-4 support, as planned for Drupal 8. (see "How to use" below)
- PHP 5.2 compatibility pattern ("PEAR-flat") with prefix/underscore class names instead of namespaces.
- Shortcut syntax for files directive in *.info file, if you stick with the D7 registry class loading.
Class loading for 3rd party libraries:
- Libraries API: Namespace registration for libraries directly from hook_libraries_info().
- Can register additional PSR-4 or PSR-0 namespace directories.
- Can scan downloaded libraries to build a classmap. (which will be cached)
- Can read and understand composer.json files from downloaded libraries.
- Can process composer-generated autoload files in a vendor/composer directory, to register all this stuff to the xautoload class loader.
- Early-bootstrap mode: The class loader can be available as early as you wish, if you include it in your settings.php (or even your index.php). But even without that, it is registered damn early in the request..
- Does not break even if you move the module to a different folder.
- (Optional) APC cache for classes (very much like Symfony / D8).
(using APC as a key-value store)
(also supports WinCache and XCache)
- Scales up to a large number of namespaces.
- Module namespaces registration is skipped if all classes are in APC cache, saving yet another few milliseconds.
Why would you need a class loader that is that flexible and powerful? Is it not enough to support basic PSR-0, and let strange libraries ship their own class loaders?
- the smaller the autoload stack, the better.
- those strange libraries can now all benefit from the APC cache.
Modules that use xautoload
Some of these modules have a compatibility fallback, to avoid having xautoload as an explicit requirement. Still, they should work better with xautoload enabled.
- Site Preview System (part of "Content staging initiative"). See http://drupal.org/node/1672604.
- Krumo NG
- Tell me about your module! Do it! I really want to know.
PHP 5.2 compatibility style:
- DQX AdminMenu
- Imagene gradient generator
- Node aspect pages
- Treewalk prev/next
- HTML tag
How to use
- Download / install / enable.
- Optionally, enable APC cache on admin/config/development/performance.
- Add as a dependency in your modules that need it.
dependencies = xautoload (>= 7.x-4.0)
Now create your PSR-0 class files, e.g.
- Optionally, enable PSR-4 support for your modulename.module:
(it is your choice if the files should be in 'lib', 'src' or something else, like 'psr4'.
Now create your PSR-4 class files, e.g.
- More documentation
Wanted: Co-Maintainers for "soft tasks"
I am happy to do all the heavy coding and thinking on this module. Or, I really enjoy it!
But it would be great to have a second person on the boat to help with documentation, testing, brainstorming, support requests, and promoting the module to a wider audience.
- Maintenance status: Seeking co-maintainer(s)
- Development status: Under active development
- Module categories: Developer, Third-party Integration
- Reported installs: 2,102 sites currently report using this module. View usage statistics.
- Downloads: 15,526
- Automated tests: Enabled
- Last modified: February 10, 2014