-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCacheBundle.php
81 lines (68 loc) · 2.38 KB
/
CacheBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
declare(strict_types=1);
namespace Pandawa\Bundle\CacheBundle;
use Illuminate\Cache\Console\CacheTableCommand;
use Illuminate\Cache\Console\ClearCommand as CacheClearCommand;
use Illuminate\Cache\Console\ForgetCommand as CacheForgetCommand;
use Illuminate\Cache\RateLimiter;
use Illuminate\Contracts\Foundation\Application;
use Pandawa\Bundle\DependencyInjectionBundle\Plugin\ImportServicesPlugin;
use Pandawa\Bundle\FoundationBundle\Plugin\ImportConfigurationPlugin;
use Pandawa\Component\Foundation\Bundle\Bundle;
use Pandawa\Contracts\Foundation\HasPluginInterface;
/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
class CacheBundle extends Bundle implements HasPluginInterface
{
protected array $commands = [
'CacheClear' => CacheClearCommand::class,
'CacheForget' => CacheForgetCommand::class,
];
protected array $devCommands = [
'CacheTable' => CacheTableCommand::class,
];
public function configure(): void
{
$this->app->singleton(RateLimiter::class, function (Application $app) {
return new RateLimiter(
$app->make('cache')->driver(
$app['config']->get('cache.limiter')
)
);
});
$this->registerCommands();
}
public function plugins(): array
{
return [
new ImportConfigurationPlugin(),
new ImportServicesPlugin(),
];
}
protected function registerCommands(): void
{
foreach (array_keys([...$this->commands, ...$this->devCommands]) as $command) {
$this->{"register{$command}Command"}();
}
$this->app->loadConsoles(array_values([...$this->commands, ...$this->devCommands]));
}
protected function registerCacheForgetCommand(): void
{
$this->app->singleton(CacheForgetCommand::class, function ($app) {
return new CacheForgetCommand($app['cache']);
});
}
protected function registerCacheClearCommand(): void
{
$this->app->singleton(CacheClearCommand::class, function ($app) {
return new CacheClearCommand($app['cache'], $app['files']);
});
}
protected function registerCacheTableCommand(): void
{
$this->app->singleton(CacheTableCommand::class, function ($app) {
return new CacheTableCommand($app['files'], $app['composer']);
});
}
}