5 * Hooks provided by X Autoload.
10 * Implements hook_xautoload()
12 * Register additional classes, namespaces, autoload patterns, that are not
13 * already registered by default.
15 * @param xautoload_InjectedAPI_hookXautoload $api
17 * Object with a number of methods, which are documented at the class
18 * definition of xautoload_InjectedAPI_hookXautoload.
20 * The object already knows which module we are at, so we don't need
23 * TODO: The $api object should be specified by an interface.
25 function hook_xautoload($api) {
27 // Declare a foreign namespace in (module dir)/lib/ForeignNamespace/
28 $api->namespaceRoot('ForeignNamespace');
30 // Declare a foreign namespace in (module dir)/vendor/ForeignNamespace/
31 $api->namespaceRoot('ForeignNamespace', 'vendor');
33 // Declare a foreign namespace in /home/username/lib/ForeignNamespace/,
34 // setting the $relative argument to FALSE.
35 $api->namespaceRoot('ForeignNamespace', '/home/username/lib', FALSE
);
40 * Implements hook_libraries_info()
42 * Allows to register PSR-0 (or other) class folders for your libraries.
43 * (those things living in sites/all/libraries)
45 * The original documentation for this hook is at libraries module,
48 * X Autoload extends the capabilities of this hook, by adding an "xautoload"
49 * key. This key takes a callback or closure function, which has the same
50 * signature as hook_xautoload($api).
51 * This means, you can use the same methods on the $api object.
53 * TODO: The $api object should be specified by an interface.
56 * Same as explained in libraries module, but with added key 'xautoload'.
58 function mymodule_libraries_info() {
61 'mymodule-test-lib' => array(
62 'name' => 'My test library',
63 'vendor url' => 'http://www.example.com',
64 'download url' => 'http://github.com/example/my-php-api',
66 'xautoload' => function($api) {
67 // Register a namespace with PSR-0 root in <library dir>/lib/
68 // Note: $api already knows the library directory.
69 // Note: We could omit the 'lib', as this is the default value.
70 $api->namespaceRoot('XALib\TestNamespace', 'lib');