Skip to content

Instantly share code, notes, and snippets.

@sasezaki
Created March 29, 2019 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasezaki/fe4ec28002d79ad5ffea421cbf25f0ea to your computer and use it in GitHub Desktop.
Save sasezaki/fe4ec28002d79ad5ffea421cbf25f0ea to your computer and use it in GitHub Desktop.
test for BEAR\Package\Compiler::getRelativePath
<?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