-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedisBundle.php
50 lines (41 loc) · 1.32 KB
/
RedisBundle.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
<?php
declare(strict_types=1);
namespace Pandawa\Bundle\RedisBundle;
use Illuminate\Contracts\Redis\Factory;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Redis\RedisManager;
use Illuminate\Support\Arr;
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 RedisBundle extends Bundle implements HasPluginInterface, DeferrableProvider
{
protected array $deferred = [
'redis',
'redis.connection',
Factory::class,
];
public function register(): void
{
$this->app->singleton('redis', function ($app) {
$config = $app->make('config');
$options = [
...Arr::except($config->get('redis', []), ['connections']),
...$config->get('redis.connections', [])
];
return new RedisManager($app, $options['client'], $options);
});
$this->app->alias('redis', Factory::class);
}
public function plugins(): array
{
return [
new ImportConfigurationPlugin(),
new ImportServicesPlugin(),
];
}
}