Created
March 29, 2019 12:07
-
-
Save sasezaki/fe4ec28002d79ad5ffea421cbf25f0ea to your computer and use it in GitHub Desktop.
test for BEAR\Package\Compiler::getRelativePath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// test for BEAR\Package\Compiler::getRelativePath | |
namespace ver192 { | |
function getRelativePath(string $rootDir, string $file) | |
{ | |
// $dir = realpath($rootDir); | |
$dir = $rootDir; | |
if (strpos($file, $dir) !== false) { | |
return str_replace("{$dir}", "__DIR__ . '", $file); | |
} | |
return "'" . $file; | |
} | |
} | |
namespace Head { | |
function getRelativePath(string $rootDir, string $file) : string | |
{ | |
// $dir = (string) realpath($rootDir); | |
$dir = $rootDir; | |
if (strpos($file, $dir) !== false) { | |
return (string) preg_replace('#^' . preg_quote($dir, '#') . '#', "__DIR__ . '", $file); | |
} | |
return "'" . $file; | |
} | |
} | |
namespace { | |
var_dump(ver192\getRelativePath('/app', '/app/vendor/bear/app-meta/src/AbstractAppMeta.php')); // string(63) "__DIR__ . '/vendor/bear__DIR__ . '-meta/src/AbstractAppMeta.php" | |
var_dump(Head\getRelativePath('/app', '/app/vendor/bear/app-meta/src/AbstractAppMeta.php')); // string(56) "__DIR__ . '/vendor/bear/app-meta/src/AbstractAppMeta.php" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment