Skip to content

Commit

Permalink
still fixing to work in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Nov 30, 2017
1 parent 6621a38 commit 6796608
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Builder.php
Expand Up @@ -46,6 +46,7 @@ class Builder
*/
protected $vars = [];

const UNIX_DS = '/';
const OUTPUT_DIR_SUFFIX = '-output';
const BASE_DIR_MARKER = '<<<base-dir>>>';

Expand Down Expand Up @@ -247,14 +248,21 @@ protected static function putFile($path, $content)
*/
public function substituteOutputDirs($data)
{
$dir = static::normalizeDir(dirname(dirname(dirname($this->outputDir))));
$dir = static::normalizePath(dirname(dirname(dirname($this->outputDir))));

return static::substitutePaths($data, $dir, static::BASE_DIR_MARKER);
}

public static function normalizeDir($path, $ds = '/')
/**
* Normalizes given path with given directory separator.
* Default forced to Unix directory separator for substitutePaths to work properly in Windows.
* @param string $path path to be normalized
* @param string $ds directory separator.
* @return string
*/
public static function normalizePath($path, $ds = self::UNIX_DS)
{
return rtrim(strtr($path, '\/', $ds), $ds);
return rtrim(strtr($path, '/\\', $ds . $ds), $ds);
}

/**
Expand Down Expand Up @@ -286,11 +294,12 @@ public static function substitutePaths($data, $dir, $alias)
*/
protected static function substitutePath($path, $dir, $alias)
{
$dir .= self::UNIX_DS;
$skippable = 0 === strncmp($path, '?', 1) ? '?' : '';
if ($skippable) {
$path = substr($path, 1);
}
$result = (substr($path, 0, strlen($dir) + 1) === $dir . '/') ? $alias . substr($path, strlen($dir)) : $path;
$result = (substr($path, 0, strlen($dir)) === $dir) ? $alias . substr($path, strlen($dir) - 1) : $path;

return $skippable . $result;
}
Expand Down

0 comments on commit 6796608

Please sign in to comment.