You are here

function ClassFinder::registerPrefixesRoot in X Autoload 7.4

Same name and namespace in other branches
  1. 7.5 src/ClassFinder/ClassFinder.php \Drupal\xautoload\ClassFinder\ClassFinder::registerPrefixesRoot()

Register an array of PEAR-style deep paths for given class prefixes.

Note: This actually goes beyond PEAR style, because it also allows "shallow" PEAR-like structures like my_library_Some_Class -> (library dir)/src/Some/Class.php instead of my_library_Some_Class -> (library dir)/src/my/library/Some/Class.php via $finder->registerPrefixDeep('my_library', "$library_dir/src");

Parameters

string[] $map: Associative array, the keys are the prefixes, the values are the directories. This does NOT cover the class named $prefix itself.

DirectoryBehaviorInterface $behavior: If TRUE, then we are not sure if the directory at $path actually exists. If during the process we find the directory to be nonexistent, we unregister the path.

Overrides ExtendedClassFinderInterface::registerPrefixesRoot

File

lib/ClassFinder/ClassFinder.php, line 215

Class

ClassFinder

Namespace

Drupal\xautoload\ClassFinder

Code

function registerPrefixesRoot($map, $behavior = NULL) {
  if (!isset($behavior)) {
    $behavior = $this->defaultBehavior;
  }
  $deep_map = array();
  foreach ($map as $prefix => $root_path) {
    $logical_base_path = Util::prefixLogicalPath($prefix);
    $deep_path = strlen($root_path) ? rtrim($root_path, '/') . '/' . $logical_base_path : $logical_base_path;
    $deep_map[$logical_base_path][$deep_path] = $behavior;

    // Register the class with name $prefix.
    if (strlen($prefix)) {
      $filepath = substr($deep_path, 0, -1) . '.php';
      $this->classes[$prefix][$filepath] = TRUE;
    }
  }
  $this->prefixMap
    ->registerDeepPaths($deep_map);
}