function psr0_autoloader in psr0 autoloader 7
An spl class autoloader function implementing PSR-4.
Includes the class definition of $fq_class if it can be found via PSR-4.
Parameters
string $fq_class: A fully qualified class name.
1 string reference to 'psr0_autoloader'
- psr0.module in ./
psr0.module - Registers a simple PSR-4 autoloader.
File
- ./
psr0.module, line 68 - Registers a simple PSR-4 autoloader.
Code
function psr0_autoloader($fq_class) {
$parts = explode('\\', $fq_class, 4);
$cnt = count($parts);
// Do nothing if this doesn't look like a PSR-4 class name.
if ($cnt < 3 || $parts[0] != 'Drupal') {
return;
}
$project_name = $parts[1];
$tests = $parts[2] == 'Tests' && $cnt == 4;
$class = $tests ? $parts[3] : implode('\\', array_slice($parts, 2));
$paths = _psr0_paths_for_name($project_name, $tests);
$file_part = strtr($class, '\\', '/') . '.php';
foreach ($paths as $p) {
$file = $p . $file_part;
if (file_exists($file)) {
require_once $file;
return;
}
}
}