X Autoload: Namespace registration interface

This is part of a series about
X Autoload

Currently the xautoload_ClassFinder_NamespaceOrPrefix does support these registration methods:

<?php
   
/<strong>
     *
Register a PSR-0 root path for a given namespace.
     *
     *
Example:
     *  
$finder->registerNamespaceDeep('abc\def', 'x/yz');
     *  
$finder->findFile('abc\def\Some_Class');
     *  
// this will attempt to find the file in
    
*   // 'x/yz/abc/def/Some/Class.php
    
*
     * @
param string $namespace
    
* @param string $root_path
    
* @param boolean $lazy_check
    
*   If we are not sure that the directory at
    
*   $root_path/$namespace_path does actually exist,
     *  
we can pass TRUE here. If the first class lookup
    
*   in this location fails, we will check if the
    
*   directory does exist at all, and if not, remove
    
*   the mapping.
     */
    function
registerNamespaceRoot($namespace, $root_path, $lazy_check = TRUE);

    /</
strong>
     *
Register a PSR-0-NG path for a given namespace.
     *
     *
Example:
     *  
$finder->registerNamespaceDeep('abc\def', 'x/yz');
     *  
$finder->findFile('abc\def\Some_Class');
     *  
// this will attempt to find the file in
    
*   // 'x/yz/Some/Class.php
    
*/
    function
registerNamespaceDeep($namespace, $path, $lazy_check = TRUE);

    /<
strong>
     *
Register a handler/plugin for a given namespace.
     */
    function
registerNamespaceHandler($prefix, $handler);

    /</
strong>
     *
Register a PEAR path for a given prefix.
     */
    function
registerPrefixRoot($prefix, $root_path, $lazy_check);

    /<
strong>
     *
Register a PEAR-NG path for a given prefix.
     */
    function
registerPrefixDeep($prefix, $deep_path, $lazy_check = TRUE);

    /</
strong>
     *
Register a handler/plugin for a given prefix.
     */
    function
registerPrefixHandler($prefix, $handler);
?>

Compared to symfony's UniversalClassLoader, we are feature-complete, except for:

  • We don't have any getter methods. (And I am not planning to add, unless someone can tell me what they are good for).
  • Our priority/weight options for registered namespaces work differently. By default, the deepest registered namespace has highest priority. Then, for the same namespace, paths have priority over plugins.
    This might all change in a future release, to have a more flexible weight mechanism.
  • The "fallback" registration. Instead, you simply register an empty namespace or prefix.

Compared to Composer's ClassLoader, there is two things missing:

  • A class map. For us, this is going to live in a separate class.
  • The "setUseIncludePath". For us, this can be added as a handler/plugin.