1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basis\Provider; |
4
|
|
|
|
5
|
|
|
use Basis\Application; |
6
|
|
|
use Basis\Cache; |
7
|
|
|
use Basis\Config; |
8
|
|
|
use Basis\Context; |
9
|
|
|
use Basis\Converter; |
10
|
|
|
use Basis\Dispatcher; |
11
|
|
|
use Basis\Filesystem; |
12
|
|
|
use Basis\Framework; |
13
|
|
|
use Basis\Http; |
14
|
|
|
use Basis\Lock; |
15
|
|
|
use Basis\Service; |
16
|
|
|
use GuzzleHttp\Client as GuzzleHttpClient; |
17
|
|
|
use League\Container\ServiceProvider\AbstractServiceProvider; |
18
|
|
|
use Predis\Client as PredisClient; |
19
|
|
|
|
20
|
|
|
class CoreProvider extends AbstractServiceProvider |
21
|
|
|
{ |
22
|
|
|
protected $provides = [ |
23
|
|
|
Cache::class, |
24
|
|
|
Config::class, |
25
|
|
|
Converter::class, |
26
|
|
|
Dispatcher::class, |
27
|
|
|
Framework::class, |
28
|
|
|
Http::class, |
29
|
|
|
Lock::class, |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
public function register() |
33
|
|
|
{ |
34
|
|
View Code Duplication |
$this->getContainer()->share(Config::class, function () { |
|
|
|
|
35
|
|
|
$app = $this->getContainer()->get(Application::class); |
36
|
|
|
$framework = $this->getContainer()->get(Framework::class); |
37
|
|
|
$fs = $this->getContainer()->get(Filesystem::class); |
38
|
|
|
$converter = $this->getContainer()->get(Converter::class); |
39
|
|
|
return new Config($app, $framework, $fs, $converter); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$this->getContainer()->share(Cache::class, function () { |
43
|
|
|
$fs = $this->getContainer()->get(Filesystem::class); |
44
|
|
|
$converter = $this->getContainer()->get(Converter::class); |
45
|
|
|
return new Cache($fs, $converter); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$this->getContainer()->share(Lock::class, function () { |
49
|
|
|
$redis = $this->getContainer()->get(PredisClient::class); |
50
|
|
|
return new Lock($redis); |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
$this->getContainer()->share(Converter::class, function () { |
54
|
|
|
return new Converter(); |
55
|
|
|
}); |
56
|
|
|
|
57
|
1 |
|
$this->getContainer()->share(Dispatcher::class, function () { |
58
|
1 |
|
$context = $this->getContainer()->get(Context::class); |
59
|
1 |
|
$client = $this->getContainer()->get(GuzzleHttpClient::class); |
60
|
1 |
|
$service = $this->getContainer()->get(Service::class); |
61
|
1 |
|
return new Dispatcher($client, $context, $service); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
$this->getContainer()->share(Framework::class, function () { |
65
|
|
|
return new Framework($this->getContainer(), dirname(dirname(__DIR__))); |
|
|
|
|
66
|
|
|
}); |
67
|
|
|
|
68
|
1 |
|
$this->getContainer()->share(Http::class, function () { |
69
|
1 |
|
return new Http($this->getContainer()->get(Application::class)); |
70
|
|
|
}); |
71
|
|
|
|
72
|
1 |
|
$this->getContainer()->share(Context::class, function () { |
73
|
1 |
|
return new Context($this->getContainer()->get(Application::class)); |
|
|
|
|
74
|
|
|
}); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.