From b034bb01b833598a2ab822fa8376bb6a0f11405b Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 1 Apr 2024 23:24:40 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Reintroduce=20`normalizeApplicat?= =?UTF-8?q?ionPath`=20when=20registering=20default=20paths=20=F0=9F=8E=A8?= =?UTF-8?q?=20Improve=20the=20`usePaths`=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Roots/Acorn/Application.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Roots/Acorn/Application.php b/src/Roots/Acorn/Application.php index 37a8a4ad..0ce74eea 100644 --- a/src/Roots/Acorn/Application.php +++ b/src/Roots/Acorn/Application.php @@ -12,6 +12,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Collection; +use Illuminate\Support\Env; use Illuminate\Support\Facades\Facade; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; @@ -253,7 +254,9 @@ public function usePaths(array $paths) throw new Exception("The {$pathType} path type is not supported."); } - $this->{$supportedPaths[$pathType]} = $this->normalizePath($path); + $this->{$supportedPaths[$pathType]} = Str::startsWith($path, $this->absoluteCachePathPrefixes) + ? $path + : $this->basePath($path); } $this->bindPathsInContainer(); @@ -684,10 +687,10 @@ public function defaultPaths(): array $paths = []; foreach (['app', 'config', 'storage', 'resources', 'public'] as $path) { - $paths[$path] = $this->findPath($path); + $paths[$path] = $this->normalizeApplicationPath($path); } - $paths['bootstrap'] = "{$paths['storage']}/framework"; + $paths['bootstrap'] = $this->normalizeApplicationPath($path, "{$paths['storage']}/framework"); return $paths; } @@ -695,11 +698,18 @@ public function defaultPaths(): array /** * Normalize a relative or absolute path to an application directory. */ - protected function normalizePath(string $path): string + protected function normalizeApplicationPath(string $path, ?string $default = null): string { - return Str::startsWith($path, ['/', '\\']) - ? $path - : $this->basePath($path); + $key = strtoupper($path); + + if (is_null($env = Env::get("ACORN_{$key}_PATH"))) { + return $default + ?? (defined("ACORN_{$key}_PATH") ? constant("ACORN_{$key}_PATH") : $this->findPath($path)); + } + + return Str::startsWith($env, $this->absoluteCachePathPrefixes) + ? $env + : $this->basePath($env); } /** @@ -710,7 +720,7 @@ protected function findPath(string $path): string $path = trim($path, '\\/'); $searchPaths = [ - "{$this->basePath()}/{$path}", + $this->basePath($path), get_theme_file_path($path), ];