Skip to content

Commit

Permalink
feat: add path helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jul 30, 2023
1 parent c1b7b99 commit 29e8740
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions RockMigrations.module.php
Expand Up @@ -4133,6 +4133,33 @@ public function traceFile($find): string
return '';
}

/**
* Return the given path and make sure it has
* - normalised separators
* - no multiple slashes
* - optionally a trailing slash
*
* /foo///bar///baz --> /foo/bar/baz
*
* This is great for quickly joining paths where you might not know if they
* have trailing slashes or not:
*
* $rm->path(
* $config->paths->root.
* "\foo\bar\".
* "/baz.php"
* );
* --> /var/www/html/foo/bar/baz.php
*/
public function path(string $path, $slash = null): string
{
$path = Paths::normalizeSeparators($path);
if ($slash === true) $path .= "/";
elseif ($slash === false) $path = rtrim($path, "/");
while (strpos($path, "//")) $path = str_replace("//", "/", $path);
return $path;
}

/**
* trigger migrate() method if it exists
*/
Expand Down

0 comments on commit 29e8740

Please sign in to comment.