function composer_manager_relative_dir in Composer Manager 6.2
Same name and namespace in other branches
- 6 composer_manager.writer.inc \composer_manager_relative_dir()
- 7.2 composer_manager.writer.inc \composer_manager_relative_dir()
- 7 composer_manager.writer.inc \composer_manager_relative_dir()
Gets the path of the "to" directory relative to the "from" directory.
Parameters
array $dir_to: The absolute path of the directory that the relative path refers to.
array $dir_from: The absolute path of the directory from which the relative path is being calculated.
Return value
string
2 calls to composer_manager_relative_dir()
- composer_manager_relative_autoload_path in ./
composer_manager.writer.inc - Returns the path for the autoloaded directory or class relative to the directory containing the composer.json file.
- composer_manager_relative_vendor_dir in ./
composer_manager.writer.inc - Returns the vendor directory relative to the composer file directory.
File
- ./
composer_manager.writer.inc, line 302 - Functions related to the creation of the consolidated composer.json file.
Code
function composer_manager_relative_dir($dir_to, $dir_from) {
$dirs_to = explode('/', ltrim($dir_to, '/'));
$dirs_from = explode('/', ltrim($dir_from, '/'));
// Strip the matching directories so that both arrays are relative to a common
// position. The count of the $dirs_from array tells us how many levels up we
// need to traverse from the directory containing the composer.json file, and
// $dirs_to is relative to the common position.
foreach ($dirs_to as $pos => $dir) {
if (!isset($dirs_from[$pos]) || $dirs_to[$pos] != $dirs_from[$pos]) {
break;
}
unset($dirs_to[$pos], $dirs_from[$pos]);
}
$path = str_repeat('../', count($dirs_from)) . join('/', $dirs_to);
if (PHP_OS == 'WINNT') {
$path = preg_replace('%..\\/([a-zA-Z])%i', '${1}', $path, 1);
}
return $path;
}