Skip to content

Commit 4137981

Browse files
authored
feat(view): add view:clear command (#1069)
1 parent 02aa357 commit 4137981

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\View\Commands;
6+
7+
use Tempest\Cache\CouldNotClearCache;
8+
use Tempest\Console\ConsoleCommand;
9+
use Tempest\Console\HasConsole;
10+
use Tempest\Container\Container;
11+
use Tempest\View\ViewCache;
12+
13+
final readonly class ClearViewCacheCommand
14+
{
15+
use HasConsole;
16+
17+
public function __construct(
18+
private Container $container,
19+
) {
20+
}
21+
22+
#[ConsoleCommand(name: 'view:clear', description: 'Clears the view cache')]
23+
public function __invoke(): void
24+
{
25+
$this->console->header('Clearing the view cache');
26+
27+
try {
28+
$this->container->get(ViewCache::class)->clear();
29+
$value = "<style='bold fg-green'>CLEARED</style>";
30+
} catch (CouldNotClearCache) {
31+
$value = "<style='bold fg-red'>FAILEd</style>";
32+
}
33+
34+
$this->console->keyValue(key: ViewCache::class, value: $value);
35+
}
36+
}

0 commit comments

Comments
 (0)