Merge remote-tracking branch 'fredemmott/hh-support'

main
Jordi Boggiano 10 years ago
commit a6531f6fd3

@ -291,8 +291,22 @@ class ClassLoader
return $this->classMap[$class]; return $this->classMap[$class];
} }
$file = $this->findFileWithExtension($class, '.php');
if ($file === null && defined('HHVM_VERSION')) {
// Indicates a Hack file (hacklang.org)
$file = $this->findFileWithExtension($class, '.hh');
}
if ($file === null) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
}
return $file;
}
private function findFileWithExtension($class, $ext) {
// PSR-4 lookup // PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0]; $first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) { if (isset($this->prefixLengthsPsr4[$first])) {
@ -321,7 +335,7 @@ class ClassLoader
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else { } else {
// PEAR-like class name // PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . '.php'; $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
} }
if (isset($this->prefixesPsr0[$first])) { if (isset($this->prefixesPsr0[$first])) {
@ -348,8 +362,7 @@ class ClassLoader
return $file; return $file;
} }
// Remember that this class does not exist. return null;
return $this->classMap[$class] = false;
} }
} }

@ -54,7 +54,7 @@ class ClassMapGenerator
if (is_file($path)) { if (is_file($path)) {
$path = array(new \SplFileInfo($path)); $path = array(new \SplFileInfo($path));
} elseif (is_dir($path)) { } elseif (is_dir($path)) {
$path = Finder::create()->files()->followLinks()->name('/\.(php|inc)$/')->in($path); $path = Finder::create()->files()->followLinks()->name('/\.(php|inc|hh)$/')->in($path);
} else { } else {
throw new \RuntimeException( throw new \RuntimeException(
'Could not scan for classes inside "'.$path. 'Could not scan for classes inside "'.$path.
@ -68,7 +68,7 @@ class ClassMapGenerator
foreach ($path as $file) { foreach ($path as $file) {
$filePath = $file->getRealPath(); $filePath = $file->getRealPath();
if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc'))) { if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc', 'hh'))) {
continue; continue;
} }

Loading…
Cancel
Save