Skip to content

Commit

Permalink
Fixed taking proper dirname depth
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jul 25, 2019
1 parent 7a96267 commit 8a6a588
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/configs/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,25 @@ protected function writeFile(string $path, array $data): void
*/
protected function writePhpFile(string $path, $data, bool $withEnv, bool $withDefines): void
{
$depth = $this->findDepth();
static::putFile($path, $this->replaceMarkers(implode("\n\n", array_filter([
'header' => '<?php',
'baseDir' => '$baseDir = dirname(dirname(dirname(__DIR__)));',
'baseDir' => "\$baseDir = dirname(__DIR__, $depth);",
'BASEDIR' => "defined('COMPOSER_CONFIG_PLUGIN_BASEDIR') or define('COMPOSER_CONFIG_PLUGIN_BASEDIR', \$baseDir);",
'dotenv' => $withEnv ? "\$_ENV = array_merge((array) require __DIR__ . '/dotenv.php', (array) \$_ENV);" : '',
'defines' => $withDefines ? $this->builder->getConfig('defines')->buildRequires() : '',
'content' => is_array($data) ? $this->renderVars($data) : $data,
]))) . "\n");
}

private function findDepth()
{
$outDir = dirname($this->getOutputPath());
$diff = substr($outDir, strlen($this->getBaseDir()));

return substr_count($diff, '/');
}

/**
* @param array $vars array to be exported
* @return string
Expand Down Expand Up @@ -196,7 +205,7 @@ protected static function putFile($path, $content): void
*/
public function substituteOutputDirs(array $data): array
{
$dir = static::normalizePath(dirname(dirname(dirname($this->getOutputDir()))));
$dir = static::normalizePath($this->getBaseDir());

return static::substitutePaths($data, $dir, static::BASE_DIR_MARKER);
}
Expand Down Expand Up @@ -259,6 +268,11 @@ protected static function substitutePath($path, $dir, $alias): string
return $skippable . $result;
}

public function getBaseDir(): string
{
return dirname(__DIR__, 5);
}

public function getOutputDir(): string
{
return $this->builder->getOutputDir();
Expand Down

0 comments on commit 8a6a588

Please sign in to comment.