1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Laravel Cache Adapter for AWS Credential Caching. |
4
|
|
|
* |
5
|
|
|
* @author Luke Waite <[email protected]> |
6
|
|
|
* @copyright 2017 Luke Waite |
7
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
8
|
|
|
* |
9
|
|
|
* @link https://github.com/lukewaite/laravel-aws-cache-adapter |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LukeWaite\LaravelAwsCacheAdapter; |
13
|
|
|
|
14
|
|
|
use Illuminate\Cache\CacheManager; |
15
|
|
|
use Illuminate\Config\Repository; |
16
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
17
|
|
|
|
18
|
|
|
class ServiceProvider extends BaseServiceProvider |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
public function register() |
24
|
|
|
{ |
25
|
|
|
// |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Bootstrap any application services. |
30
|
|
|
* |
31
|
|
|
* @param CacheManager $manager |
32
|
|
|
* @param Repository $config |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function boot(CacheManager $manager, Repository $config) |
36
|
|
|
{ |
37
|
|
|
$this->publishes([ |
38
|
|
|
__DIR__ . '/../config/laravel-aws-cache.php' => config_path('laravel-aws-cache.php') |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
if (config('laravel-aws-cache.enable')) { |
42
|
|
|
$this->insertCredentialSetting($manager, $config); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function insertCredentialSetting(CacheManager $manager, Repository $config) |
47
|
|
|
{ |
48
|
|
View Code Duplication |
if (!empty(config('laravel-aws-cache.filesystems'))) { |
|
|
|
|
49
|
|
|
collect(explode(',', config('laravel-aws-cache.filesystems'))) |
50
|
|
|
->each(function ($filesystem) use ($manager, $config) { |
51
|
|
|
$config->set([ |
52
|
|
|
'filesystems.disks.' . $filesystem . '.credentials' => |
53
|
|
|
new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache')) |
54
|
|
|
]); |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
if (!empty(config('laravel-aws-cache.queues'))) { |
|
|
|
|
59
|
|
|
collect(explode(',', config('laravel-aws-cache.queues'))) |
60
|
|
|
->each(function ($queue) use ($manager, $config) { |
61
|
|
|
$config->set([ |
62
|
|
|
'queue.connections.' . $queue . '.credentials' => |
63
|
|
|
new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache')) |
64
|
|
|
]); |
65
|
|
|
}); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.