Skip to content

Commit

Permalink
Absolutize paths harder
Browse files Browse the repository at this point in the history
  • Loading branch information
Szczepan Hołyszewski committed Jun 23, 2020
1 parent 0465d92 commit 00f85ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/classes/Obey/Front/InputResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InputResolver

public function resolve(Unit $unit)
{
$inputPattern = Path::cat($this->getRootDir(), $unit->getGroup()->getInputPattern());
$inputPattern = Path::norm(Path::cat(getcwd(), $this->getRootDir(), $unit->getGroup()->getInputPattern()));
$inputFile = str_replace('*', $unit->getName(), $inputPattern);
$unit->setInputFile($inputFile);
}
Expand Down
5 changes: 3 additions & 2 deletions src/classes/Obey/Front/OutputResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class OutputResolver

public function resolve(Unit $unit)
{
$outputPattern = Path::cat(
$outputPattern = PAth::norm(Path::cat(
getcwd(),
$this->getOutputDir(),
$unit->getGroup()->getSubDir(),
$this->getOutputNameTemplate()
);
));
$outputFile = str_replace('{}', $unit->getName(), $outputPattern);
$unit->setOutputFile($outputFile);
}
Expand Down
9 changes: 7 additions & 2 deletions src/classes/Obey/PathHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ public static function cat(?string ...$fragments) : string
{
$nonNullFragments = array_filter($fragments,fn($v) => null!==$v);
if (0===count($nonNullFragments)) return ".";
$absoluteTail = [];
foreach($nonNullFragments as $fragment) {
if (self::isAbsolute($fragment)) $absoluteTail=[$fragment];
else $absoluteTail[] = $fragment;
}
$explodedFragments = [
self::split($nonNullFragments[0]),
...array_map(fn($fragment) => self::split($fragment,false), array_slice($nonNullFragments,1))
self::split($absoluteTail[0]),
...array_map(fn($fragment) => self::split($fragment,false), array_slice($absoluteTail,1))
];
$segments = array_merge(...$explodedFragments);
if (!count($segments)) return ".";
Expand Down

0 comments on commit 00f85ab

Please sign in to comment.