mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 08:20:53 +00:00
6c20d257e3
d3d18d442c
keep relative paths
32 lines
902 B
PHP
32 lines
902 B
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace RectorPrefix202209\Symplify\PackageBuilder\Composer;
|
|
|
|
use RectorPrefix202209\Composer\Autoload\ClassLoader;
|
|
use ReflectionClass;
|
|
/**
|
|
* @api
|
|
* @see \Symplify\PackageBuilder\Tests\Composer\VendorDirProviderTest
|
|
*/
|
|
final class VendorDirProvider
|
|
{
|
|
public function provide() : string
|
|
{
|
|
$rootFolder = \getenv('SystemDrive', \true) . \DIRECTORY_SEPARATOR;
|
|
$path = __DIR__;
|
|
while (\substr_compare($path, 'vendor', -\strlen('vendor')) !== 0 && $path !== $rootFolder) {
|
|
$path = \dirname($path);
|
|
}
|
|
if ($path !== $rootFolder) {
|
|
return $path;
|
|
}
|
|
return $this->reflectionFallback();
|
|
}
|
|
private function reflectionFallback() : string
|
|
{
|
|
$reflectionClass = new ReflectionClass(ClassLoader::class);
|
|
return \dirname($reflectionClass->getFileName(), 2);
|
|
}
|
|
}
|