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\Runner; |
12
|
|
|
use Basis\Filesystem; |
13
|
|
|
use Basis\Framework; |
14
|
|
|
use Basis\Http; |
15
|
|
|
use Basis\Lock; |
16
|
|
|
use Basis\Service; |
17
|
|
|
use GuzzleHttp\Client as GuzzleHttpClient; |
18
|
|
|
use League\Container\ServiceProvider\AbstractServiceProvider; |
19
|
|
|
use Predis\Client as PredisClient; |
20
|
|
|
|
21
|
|
|
class CoreProvider extends AbstractServiceProvider |
22
|
|
|
{ |
23
|
|
|
protected $provides = [ |
24
|
|
|
Cache::class, |
25
|
|
|
Config::class, |
26
|
|
|
Converter::class, |
27
|
|
|
Dispatcher::class, |
28
|
|
|
Framework::class, |
29
|
|
|
Http::class, |
30
|
|
|
Lock::class, |
31
|
|
|
Runner::class, |
32
|
|
|
]; |
33
|
|
|
|
34
|
56 |
|
public function register() |
35
|
|
|
{ |
36
|
|
|
$this->getContainer()->share(Config::class, function () { |
37
|
|
|
$app = $this->getContainer()->get(Application::class); |
38
|
|
|
$framework = $this->getContainer()->get(Framework::class); |
39
|
|
|
$fs = $this->getContainer()->get(Filesystem::class); |
40
|
|
|
$converter = $this->getContainer()->get(Converter::class); |
41
|
|
|
return new Config($app, $framework, $fs, $converter); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
$this->getContainer()->share(Cache::class, function () { |
45
|
|
|
$fs = $this->getContainer()->get(Filesystem::class); |
46
|
|
|
$converter = $this->getContainer()->get(Converter::class); |
47
|
|
|
return new Cache($fs, $converter); |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
$this->getContainer()->share(Lock::class, function () { |
51
|
|
|
$redis = $this->getContainer()->get(PredisClient::class); |
52
|
|
|
return new Lock($redis); |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
$this->getContainer()->share(Converter::class, function () { |
56
|
|
|
return new Converter(); |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
$this->getContainer()->share(Dispatcher::class, function () { |
60
|
56 |
|
$app = $this->getContainer()->get(Application::class); |
61
|
56 |
|
return new Dispatcher($app); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
$this->getContainer()->share(Framework::class, function () { |
65
|
|
|
return new Framework($this->getContainer(), dirname(dirname(__DIR__))); |
|
|
|
|
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
$this->getContainer()->share(Http::class, function () { |
69
|
3 |
|
return new Http($this->getContainer()->get(Application::class)); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
$this->getContainer()->share(Runner::class, function () { |
73
|
56 |
|
return new Runner($this->getContainer()->get(Application::class)); |
74
|
|
|
}); |
75
|
|
|
|
76
|
|
|
$this->getContainer()->share(Context::class, function () { |
77
|
5 |
|
return new Context($this->getContainer()->get(Application::class)); |
78
|
|
|
}); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.