From 8a6a5884a66e2ef84ad40784a45cc33916fd9345 Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Thu, 25 Jul 2019 17:53:27 +0000 Subject: [PATCH] Fixed taking proper dirname depth --- src/configs/Config.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/configs/Config.php b/src/configs/Config.php index b2a574e..875b75e 100644 --- a/src/configs/Config.php +++ b/src/configs/Config.php @@ -143,9 +143,10 @@ 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' => ' '$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() : '', @@ -153,6 +154,14 @@ protected function writePhpFile(string $path, $data, bool $withEnv, bool $withDe ]))) . "\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 @@ -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); } @@ -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();