For example, in a queuing application, you can define a class type called 'job':
Libraries::paths(array('job' => '{:library}\extensions\job\{:name}'));
Then, any classes you add to the extensions/job directory in your application will be
automatically detected when calling Libraries::locate('job'). Additionally, any matching
classes in the extensions/job directory of any plugin or vendor library you add to your
application will also be detected.
Supposing you wanted to have the option of further organizing jobs by class type (some jobs
are related to updating caches, others to sending notifications, etc.), you can specify
multiple paths per class type, with varying levels of specificity:
Libraries::paths(array('job' => array(
'{:library}\extensions\job\{:class}\{:name}',
'{:library}\extensions\job\{:name}'
)));
This allows you to, for example, have two different classes called Cleanup. One may be
located in app\extensions\job\Cleanup, while the other is in
app\extensions\job\cache\Cleanup. Calling: Libraries::locate('job'); will find
both classes, while Libraries::locate('job.cache'); will only find the second. You can
also find individual jobs by name: Libraries::locate('job', 'Cleanup');
See Libraries::locate() for more information on using built-in and user-defined paths to
look up classes.
In addition to adding custom class types, paths() allows you to redefine the naming and
organization of existing types. For example, if you wished to reference your model classes
as app\models\PostModel instead of app\models\Post, you can do the following:
Libraries::paths(array('models' => '{:library}\models\{:name}Model'));
Note, however, that this is a destructive, not an additive operation, and will
replace any existing paths defined for that type. If you wish to add a search path
for an existing type, you must do the following:
$existing = Libraries::paths('controllers');
Libraries::paths(array('controller' => array_merge(
array('{:library}\extensions\controllers\{:name}Controller'), (array) $existing
)));