Skip to content

Commit bdb4b61

Browse files
committed
feat: AssetManager
getAssets -> assets
1 parent 2135c30 commit bdb4b61

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

src/Core/src/Traits/WithAssets.php

+20-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MoonShine\Core\Traits;
66

7+
use MoonShine\Contracts\AssetManager\AssetElementContract;
78
use MoonShine\Contracts\AssetManager\AssetManagerContract;
89

910
/**
@@ -21,28 +22,38 @@ public function getAssetManager(): AssetManagerContract
2122
return $this->getCore()->getContainer(AssetManagerContract::class);
2223
}
2324

25+
/**
26+
* @return list<AssetElementContract>
27+
*/
28+
protected function assets(): array
29+
{
30+
return [];
31+
}
32+
33+
/**
34+
* @return list<AssetElementContract>
35+
*/
2436
public function getAssets(): array
2537
{
2638
if (! $this->shouldUseAssets()) {
2739
return [];
2840
}
2941

30-
return $this->assets;
31-
}
32-
33-
public function addAssets(array $assets): static
34-
{
35-
$this->getAssetManager()->add($assets);
36-
37-
return $this;
42+
return array_merge(
43+
$this->assets,
44+
$this->assets(),
45+
);
3846
}
3947

4048
protected function shouldUseAssets(): bool
4149
{
4250
return true;
4351
}
4452

45-
public function pushAssets(array $assets): static
53+
/**
54+
* @param list<AssetElementContract> $assets
55+
*/
56+
public function addAssets(array $assets): static
4657
{
4758
$this->assets = array_merge($this->assets, $assets);
4859

src/UI/src/Components/Layout/Favicon.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
* web-manifest: string,
2727
* } $assets
2828
*/
29-
public function assets(array $assets): self
29+
public function customAssets(array $assets): self
3030
{
3131
$this->customAssets = $assets;
3232

src/UI/src/Components/MoonShineComponent.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public function __construct(
3838
if (! $this->isConsoleMode()) {
3939
$this->resolveAssets();
4040
}
41+
42+
$this->booted();
43+
}
44+
45+
protected function booted(): void
46+
{
47+
//
4148
}
4249

4350
public static function consoleMode(bool $enable = true): void
@@ -71,7 +78,7 @@ public function withAttributes(array $attributes): static
7178
/** @phpstan-ignore-next-line */
7279
$this->attributes = $this->attributes ?: $this->newAttributeBag();
7380
$this->attributes->setAttributes(
74-
array_merge($this->attributes->jsonSerialize(), $attributes)
81+
array_merge($this->attributes->jsonSerialize(), $attributes),
7582
);
7683

7784
return $this;

tests/Feature/ComponentsEqualsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function renderBlade(string $alias, array $parameters = [], array $attributes =
165165

166166
it('favicon', function () {
167167
compare(
168-
Favicon::make()->assets(['test.js'])->bodyColor('#fff'),
168+
Favicon::make()->customAssets(['test.js'])->bodyColor('#fff'),
169169
['custom-assets' => ['test.js'], 'body-color' => '#fff']
170170
);
171171
});

0 commit comments

Comments
 (0)