1
0
Fork 0

Fixed error, when composer.phar was broken, if it compiled inside folder, that has /composer in path

pull/6651/merge
Fedir Kryvytskyi 2017-09-06 21:25:12 +02:00 committed by Jordi Boggiano
parent 9fd4f22ba2
commit dc509b236f
1 changed files with 16 additions and 2 deletions

View File

@ -164,10 +164,24 @@ class Compiler
$util->save($pharFile, \Phar::SHA1); $util->save($pharFile, \Phar::SHA1);
} }
/**
* @param \SplFileInfo $file
* @return string
*/
private function getRelativeFilePath($file)
{
$realPath = $file->getRealPath();
$pathPrefix = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR;
$pos = strpos($realPath, $pathPrefix);
$relativePath = ($pos !== false) ? substr_replace($realPath, '', $pos, strlen($pathPrefix)) : $realPath;
return strtr($relativePath, '\\', '/');
}
private function addFile($phar, $file, $strip = true) private function addFile($phar, $file, $strip = true)
{ {
$path = strtr(str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/'); $path = $this->getRelativeFilePath($file);
$content = file_get_contents($file); $content = file_get_contents($file);
if ($strip) { if ($strip) {
$content = $this->stripWhitespace($content); $content = $this->stripWhitespace($content);