4 class xautoload_ClassFinder_NamespaceOrPrefix
extends xautoload_ClassFinder_Prefix
{
6 protected
$namespaceMap;
8 function __construct() {
10 $this->namespaceMap
= new
xautoload_ClassFinder_Helper_RecursiveMapEvaluator();
13 function registerNamespaceRoot($namespace, $root_path, $lazy_check = TRUE
) {
14 $subdir = str_replace('\\', DIRECTORY_SEPARATOR
, $namespace);
20 : ($root_path . DIRECTORY_SEPARATOR .
$subdir)
22 $this->registerNamespaceDeepLocation($namespace, $deep_path, $lazy_check);
25 function registerNamespaceDeep($namespace, $path, $lazy_check = TRUE
) {
26 $this->registerNamespaceDeepLocation($namespace, $path, $lazy_check);
30 * Register a filesystem location for a given namespace.
32 function registerNamespaceDeepLocation($namespace, $path, $lazy_check = TRUE
) {
33 $path_prefix_symbolic = str_replace('\\', DIRECTORY_SEPARATOR
, $namespace .
'\\');
34 $this->namespaceMap
->registerDeepPath($path_prefix_symbolic, $path .
'/', $lazy_check);
37 function registerNamespaceHandler($namespace, $handler) {
38 $path_prefix_symbolic =
40 ?
str_replace('\\', DIRECTORY_SEPARATOR
, $namespace .
'\\')
43 $this->namespaceMap
->registerNamespaceHandler($path_prefix_symbolic, $handler);
47 * Finds the path to the file where the class is defined.
49 * @param string $class
50 * The name of the class
54 function findFile($api, $class) {
56 if ('\\' == $class[0]) {
57 $class = substr($class, 1);
60 if (false
!== $pos = strrpos($class, '\\')) {
61 // namespaced class name
62 if ($class{$pos + 1} === '_') return;
63 $path_prefix_symbolic = str_replace('\\', DIRECTORY_SEPARATOR
, substr($class, 0, $pos + 1));
64 $path_suffix = str_replace('_', DIRECTORY_SEPARATOR
, substr($class, $pos + 1)) .
'.php';
65 return $this->namespaceMap
->findFile_rec($api, $path_prefix_symbolic, $path_suffix);
68 // class name with prefix
69 return parent
::findFile($api, $class);