mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Miscellaneous - getProjectRootPath() method - returns project's root path
This commit is contained in:
@@ -1473,4 +1473,37 @@ class Miscellaneous
|
|||||||
|
|
||||||
return $invertedColor;
|
return $invertedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns project's root path.
|
||||||
|
* Looks for directory that contains composer.json.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getProjectRootPath()
|
||||||
|
{
|
||||||
|
$projectRootPath = '';
|
||||||
|
|
||||||
|
$fileName = 'composer.json';
|
||||||
|
$directoryPath = __DIR__;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Path of directory it's not the path of last directory?
|
||||||
|
*/
|
||||||
|
while (DIRECTORY_SEPARATOR !== $directoryPath) {
|
||||||
|
$filePath = static::concatenatePaths($directoryPath, $fileName);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Is here file we are looking for?
|
||||||
|
* Maybe it's a project's root path
|
||||||
|
*/
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
$projectRootPath = $directoryPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
$directoryPath = dirname($directoryPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $projectRootPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -742,6 +742,11 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
self::assertSame($expected, Miscellaneous::fillMissingZeros($number, $length, $before));
|
self::assertSame($expected, Miscellaneous::fillMissingZeros($number, $length, $before));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetProjectRootPath()
|
||||||
|
{
|
||||||
|
self::assertNotEmpty(Miscellaneous::getProjectRootPath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user