Skip to content

Commit

Permalink
Merge pull request #118 from Laravel-Backpack/store-the-file-with-ext…
Browse files Browse the repository at this point in the history
…ension-on-disk

store the file with the provided extension
  • Loading branch information
promatik authored Apr 29, 2024
2 parents d099226 + c83369c commit ca0f385
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/BassetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ public function loaded(): array
* @param string $asset
* @return string
*/
public function getPath(string $asset): string
public function getPath(string $asset, string $extension = null): string
{
return Str::of($this->basePath)
->append(str_replace([base_path().'/', base_path(), 'http://', 'https://', '://', '<', '>', ':', '"', '|', "\0", '*', '`', ';', "'", '+'], '', $asset))
->before('?')
->replace('/\\', '/');
->replace('/\\', '/')
->finish($extension ?? '');
}

/**
Expand Down Expand Up @@ -138,8 +139,12 @@ public function basset(string $asset, bool|string $output = true, array $attribu
{
$this->loader->start();

if ($extension) {
$extension = Str::start($extension, '.');
}

// Get asset path
$path = $this->getPath(is_string($output) ? $output : $asset);
$path = $this->getPath(is_string($output) ? $output : $asset, $extension);

if ($this->isLoaded($path)) {
return $this->loader->finish(StatusEnum::LOADED);
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/CacheMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(FilesystemAdapter $disk, string $basePath)

// Load map
if (File::exists($this->filePath)) {
$this->map = json_decode(File::get($this->filePath), true);
$this->map = json_decode(File::get($this->filePath), true) ?? [];
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Helpers/FileOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function write(string $path, array $attributes = [], string $extension =
return;
}

$path = (string) Str::of($path)->finish('.'.$extension);
echo Blade::render($template, [
'src' => $this->assetPath($path),
'args' => $this->prepareAttributes($attributes),
Expand Down

0 comments on commit ca0f385

Please sign in to comment.