You are here

function ClassFinder::registerPrefixRoot in X Autoload 7.4

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

Register a PEAR-style root path for a given class prefix.

Parameters

string $prefix: Prefix, e.g. "My_Prefix", for classes like "My_Prefix_SomeClass". This does ALSO cover the class named "My_Prefix" itself.

string $root_path: Root path, e.g. "../lib" or "../src", so that classes can be placed e.g. My_Prefix_SomeClass -> ../lib/My/Prefix/SomeClass.php My_Prefix -> ../lib/My/Prefix.php

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::registerPrefixRoot

File

lib/ClassFinder/ClassFinder.php, line 190

Class

ClassFinder

Namespace

Drupal\xautoload\ClassFinder

Code

function registerPrefixRoot($prefix, $root_path, $behavior = NULL) {
  if (!isset($behavior)) {
    $behavior = $this->defaultBehavior;
  }
  $logical_base_path = Util::prefixLogicalPath($prefix);
  $deep_path = strlen($root_path) ? rtrim($root_path, '/') . '/' . $logical_base_path : $logical_base_path;
  $this->prefixMap
    ->registerDeepPath($logical_base_path, $deep_path, $behavior);
  if (strlen($prefix)) {

    // We assume that the class named $prefix is also found at this path.
    $filepath = substr($deep_path, 0, -1) . '.php';
    $this
      ->registerClass($prefix, $filepath);
  }
}