Added parameter $inDirectory to method Filesystem::findShortestPath
parent
afc04c9e53
commit
1f8c9eeb6c
|
@ -58,7 +58,7 @@ EOF;
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
|
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
|
||||||
$relVendorPath = $filesystem->findShortestPath(getcwd().'/inDir', $vendorPath);
|
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
|
||||||
$vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
$vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
||||||
|
|
||||||
$appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
|
$appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
|
||||||
|
@ -125,7 +125,7 @@ EOF;
|
||||||
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
||||||
foreach ($autoloads['classmap'] as $dir) {
|
foreach ($autoloads['classmap'] as $dir) {
|
||||||
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
|
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
|
||||||
$path = '/'.$filesystem->findShortestPath(getcwd().'/inDir', $path);
|
$path = '/'.$filesystem->findShortestPath(getcwd(), $path, true);
|
||||||
$classmapFile .= ' '.var_export($class, true).' => $baseDir . '.var_export($path, true).",\n";
|
$classmapFile .= ' '.var_export($class, true).' => $baseDir . '.var_export($path, true).",\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,9 +58,10 @@ class Filesystem
|
||||||
*
|
*
|
||||||
* @param string $from
|
* @param string $from
|
||||||
* @param string $to
|
* @param string $to
|
||||||
|
* @param Boolean $inDirectory if true, the source is considered to be in the directory
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function findShortestPath($from, $to)
|
public function findShortestPath($from, $to, $inDirectory = false)
|
||||||
{
|
{
|
||||||
if (!$this->isAbsolutePath($from) || !$this->isAbsolutePath($to)) {
|
if (!$this->isAbsolutePath($from) || !$this->isAbsolutePath($to)) {
|
||||||
throw new \InvalidArgumentException('from and to must be absolute paths');
|
throw new \InvalidArgumentException('from and to must be absolute paths');
|
||||||
|
@ -69,6 +70,10 @@ class Filesystem
|
||||||
$from = lcfirst(rtrim(strtr($from, '\\', '/'), '/'));
|
$from = lcfirst(rtrim(strtr($from, '\\', '/'), '/'));
|
||||||
$to = lcfirst(rtrim(strtr($to, '\\', '/'), '/'));
|
$to = lcfirst(rtrim(strtr($to, '\\', '/'), '/'));
|
||||||
|
|
||||||
|
if ($inDirectory) {
|
||||||
|
$from .= '/dummy_file';
|
||||||
|
}
|
||||||
|
|
||||||
if (dirname($from) === dirname($to)) {
|
if (dirname($from) === dirname($to)) {
|
||||||
return './'.basename($to);
|
return './'.basename($to);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,10 +58,10 @@ class FilesystemTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider providePathCouples
|
* @dataProvider providePathCouples
|
||||||
*/
|
*/
|
||||||
public function testFindShortestPath($a, $b, $expected)
|
public function testFindShortestPath($a, $b, $expected, $inDirectory = false)
|
||||||
{
|
{
|
||||||
$fs = new Filesystem;
|
$fs = new Filesystem;
|
||||||
$this->assertEquals($expected, $fs->findShortestPath($a, $b));
|
$this->assertEquals($expected, $fs->findShortestPath($a, $b, $inDirectory));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providePathCouples()
|
public function providePathCouples()
|
||||||
|
@ -69,8 +69,13 @@ class FilesystemTest extends TestCase
|
||||||
return array(
|
return array(
|
||||||
array('/foo/bar', '/foo/bar', "./bar"),
|
array('/foo/bar', '/foo/bar', "./bar"),
|
||||||
array('/foo/bar', '/foo/baz', "./baz"),
|
array('/foo/bar', '/foo/baz', "./baz"),
|
||||||
|
array('/foo/bar/', '/foo/baz', "./baz"),
|
||||||
|
array('/foo/bar', '/foo/bar', "./", true),
|
||||||
|
array('/foo/bar', '/foo/baz', "../baz", true),
|
||||||
|
array('/foo/bar/', '/foo/baz', "../baz", true),
|
||||||
array('/foo/bin/run', '/foo/vendor/acme/bin/run', "../vendor/acme/bin/run"),
|
array('/foo/bin/run', '/foo/vendor/acme/bin/run', "../vendor/acme/bin/run"),
|
||||||
array('/foo/bin/run', '/bar/bin/run', "/bar/bin/run"),
|
array('/foo/bin/run', '/bar/bin/run', "/bar/bin/run"),
|
||||||
|
array('/foo/bin/run', '/bar/bin/run', "/bar/bin/run", true),
|
||||||
array('c:/bin/run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"),
|
array('c:/bin/run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"),
|
||||||
array('c:\\bin\\run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"),
|
array('c:\\bin\\run', 'c:/vendor/acme/bin/run', "../vendor/acme/bin/run"),
|
||||||
array('c:/bin/run', 'd:/vendor/acme/bin/run', "d:/vendor/acme/bin/run"),
|
array('c:/bin/run', 'd:/vendor/acme/bin/run', "d:/vendor/acme/bin/run"),
|
||||||
|
@ -79,6 +84,7 @@ class FilesystemTest extends TestCase
|
||||||
array('/tmp/test', '/tmp', "./"),
|
array('/tmp/test', '/tmp', "./"),
|
||||||
array('C:/Temp/test/sub', 'C:\Temp', "../"),
|
array('C:/Temp/test/sub', 'C:\Temp', "../"),
|
||||||
array('/tmp/test/sub', '/tmp', "../"),
|
array('/tmp/test/sub', '/tmp', "../"),
|
||||||
|
array('/tmp/test/sub', '/tmp', "../../", true),
|
||||||
array('/tmp', '/tmp/test', "test"),
|
array('/tmp', '/tmp/test', "test"),
|
||||||
array('C:/Temp', 'C:\Temp\test', "test"),
|
array('C:/Temp', 'C:\Temp\test', "test"),
|
||||||
array('C:/Temp', 'c:\Temp\test', "test"),
|
array('C:/Temp', 'c:\Temp\test', "test"),
|
||||||
|
|
Loading…
Reference in New Issue