Skip to content

Commit

Permalink
Fixed the classmap autoloader to work under Windows in Phar files.
Browse files Browse the repository at this point in the history
(Example path: 'phar://D:/GDrive/zs-client.phar/module/Client/autoload_classmap.php')
  • Loading branch information
Slavey Karadzhov committed Feb 11, 2014
1 parent 2b718e2 commit 4dfad98
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions library/Zend/Loader/ClassMapAutoloader.php
Expand Up @@ -197,11 +197,12 @@ protected function loadMapFromFile($location)
*/
public static function realPharPath($path)
{
if (strpos($path, 'phar:///') !== 0) {
if (!preg_match('|^phar:(/{2,3})|',$path, $match)) {
return;
}

$parts = explode('/', str_replace(array('/', '\\'), '/', substr($path, 8)));
$prefixLength = 5 + strlen($match[1]);
$parts = explode('/', str_replace(array('/', '\\'), '/', substr($path, $prefixLength)));
$parts = array_values(array_filter($parts, function ($p) {
return ($p !== '' && $p !== '.');
}));
Expand All @@ -213,7 +214,7 @@ public static function realPharPath($path)
}
});

if (file_exists($realPath = 'phar:///' . implode('/', $parts))) {
if (file_exists($realPath = str_pad('phar:', $prefixLength, '/') . implode('/', $parts))) {
return $realPath;
}
}
Expand Down

0 comments on commit 4dfad98

Please sign in to comment.