Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into cach…
Browse files Browse the repository at this point in the history
…e_beta2

Conflicts:
	library/Zend/Cache/Cache.php
  • Loading branch information
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 1,184 deletions.
36 changes: 33 additions & 3 deletions src/ClassMapAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,45 @@ protected function loadMapFromFile($location)
throw new Exception\InvalidArgumentException('Map file provided does not exist');
}

$location = realpath($location);
if (!$path = static::realPharPath($location)) {
$path = realpath($location);
}

if (in_array($location, $this->mapsLoaded)) {
if (in_array($path, $this->mapsLoaded)) {
// Already loaded this map
return $this;
}

$map = include $location;
$map = include $path;

return $map;
}

/**
* Resolve the real_path() to a file within a phar.
*
* @see https://bugs.php.net/bug.php?id=52769
* @param string $path
* @return string
*/
public static function realPharPath($path)
{
if (strpos($path, 'phar:///') !== 0) {
return;
}

$parts = explode('/', str_replace(array('/','\\'), '/', substr($path, 8)));
$parts = array_values(array_filter($parts, function($p) { return ($p !== '' && $p !== '.'); }));

array_walk($parts, function ($value, $key) use(&$parts) {
if ($value === '..') {
unset($parts[$key], $parts[$key-1]);
$parts = array_values($parts);
}
});

if (file_exists($realPath = 'phar:///' . implode('/', $parts))) {
return $realPath;
}
}
}
Loading

0 comments on commit 0bc1e16

Please sign in to comment.