Skip to content

Commit

Permalink
馃帹 Reintroduce normalizeApplicationPath when registering default paths
Browse files Browse the repository at this point in the history
馃帹 Improve the `usePaths` method
  • Loading branch information
Log1x committed Apr 2, 2024
1 parent 1914b36 commit b034bb0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/Roots/Acorn/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -684,22 +687,29 @@ 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;
}

/**
* 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);
}

/**
Expand All @@ -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),
];

Expand Down

0 comments on commit b034bb0

Please sign in to comment.