Some documentation improvements
[project/xautoload.git] / xautoload.api.php
1 <?php
2
3 /**
4 * @file
5 * Hooks provided by X Autoload.
6 */
7
8
9 /**
10 * Implements hook_xautoload()
11 *
12 * Register additional classes, namespaces, autoload patterns, that are not
13 * already registered by default.
14 *
15 * @param xautoload_InjectedAPI_hookXautoload $api
16 *
17 * Object with a number of methods, which are documented at the class
18 * definition of xautoload_InjectedAPI_hookXautoload.
19 *
20 * The object already knows which module we are at, so we don't need
21 * drupal_get_path().
22 *
23 * TODO: The $api object should be specified by an interface.
24 */
25 function hook_xautoload($api) {
26
27 // Declare a foreign namespace in (module dir)/lib/ForeignNamespace/
28 $api->namespaceRoot('ForeignNamespace');
29
30 // Declare a foreign namespace in (module dir)/vendor/ForeignNamespace/
31 $api->namespaceRoot('ForeignNamespace', 'vendor');
32
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);
36 }
37
38
39 /**
40 * Implements hook_libraries_info()
41 *
42 * Allows to register PSR-0 (or other) class folders for your libraries.
43 * (those things living in sites/all/libraries)
44 *
45 * The original documentation for this hook is at libraries module,
46 * libraries.api.php
47 *
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.
52 *
53 * TODO: The $api object should be specified by an interface.
54 *
55 * @return array
56 * Same as explained in libraries module, but with added key 'xautoload'.
57 */
58 function mymodule_libraries_info() {
59
60 return array(
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',
65 'version' => '1.0',
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');
71 },
72 ),
73 );
74 }