protected function onPrepare($argv = null) { $scopes = $this->console->getAppCommandScopes(); $index = 0; foreach ($scopes as $ns => $path) { $path = convert_path_slash($path, KE_DS_UNIX); $this->scopes[$index] = $path; $this->console->println("[{$index}]", $ns, '->', $path); $index += 1; } }
function relative_path(string $target, string $source, string $plus = null, $slash = KE_DS_UNIX) { if ($slash !== KE_DS_UNIX && $slash !== KE_DS_WIN) { $slash = KE_DS_UNIX; } $source = convert_path_slash($source, $slash); $target = convert_path_slash($target, $slash); if (isset($plus)) { $plus = ltrim($plus, KE_PATH_NOISE); } list($source, $phar) = split_phar($source); $relative = $source; if (strlen($source) > 0) { $samePart = compare_path($source, $target, $slash); if (!empty($samePart)) { $samePart = preg_quote($samePart); $quoteSlash = preg_quote($slash); $regex = "#^({$quoteSlash}?{$samePart}{$quoteSlash}?)#i"; $sourceTail = preg_replace($regex, '', $source); $sourceTail = trim($sourceTail, KE_PATH_NOISE); $targetTail = preg_replace($regex, '', $target); $targetTail = trim($targetTail, KE_PATH_NOISE); $targetDepth = 0; if (strlen($targetTail) > 0) { $targetSplit = explode($slash, $targetTail); $targetDepth = count($targetSplit); } $relative = str_repeat($slash . '..', $targetDepth); if (strlen($sourceTail) > 0) { $relative .= $slash . $sourceTail; } } } if ($phar !== false) { $relative = 'phar://' . $relative; $relative .= $slash . $phar; } if (strlen($plus) > 0) { $relative .= $slash . convert_path_slash($plus); } return $relative; }