You are here

function _psr0_paths_for_name in psr0 autoloader 7

Get the path to project $name.

Guesses whether this project is a module or profile.

Parameters

string $name: Name of the project.

bool $tests: Whether we are looking for the Tests sub-namespace.

Return value

array Array of possible path prefixes for this project name.

1 call to _psr0_paths_for_name()
psr0_autoloader in ./psr0.module
An spl class autoloader function implementing PSR-4.

File

./psr0.module, line 25
Registers a simple PSR-4 autoloader.

Code

function _psr0_paths_for_name($name, $tests) {

  // Use the advanced drupal_static() pattern, since this is called very often.
  $cname = $tests ? "main:{$name}" : "tests:{$name}";
  static $paths;
  if (!isset($paths)) {
    $paths =& drupal_static(__FUNCTION__, array());
  }
  if (isset($paths[$cname])) {
    return $paths[$cname];
  }
  $modules = system_list('module_enabled');
  if (isset($modules[$name])) {
    $paths[$cname] = array();
    $module_path = DRUPAL_ROOT . '/' . dirname($modules[$name]->filename);
    if ($tests) {
      if (file_exists($module_path . '/lib/Tests/')) {
        $paths[$cname][] = $module_path . '/lib/Tests/';
      }
      if (file_exists($module_path . '/src/Tests/')) {
        $paths[$cname][] = $module_path . '/src/Tests/';
      }
      $module_path .= '/tests';
    }
    if (file_exists($module_path . '/lib/')) {
      $paths[$cname][] = $module_path . '/lib/';
    }
    if (file_exists($module_path . '/src/')) {
      $paths[$cname][] = $module_path . '/src/';
    }
    return $paths[$cname];
  }
  return array();
}