1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Cart; |
5
|
|
|
|
6
|
|
|
use Cart\Contracts\CartDriverContract; |
7
|
|
|
use Cart\Contracts\ServiceProviderContract; |
8
|
|
|
use Illuminate\Container\Container; |
9
|
|
|
use Illuminate\Config\Repository; |
10
|
|
|
use Symfony\Component\Finder\Finder; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Kernel |
14
|
|
|
* |
15
|
|
|
* @package Cart |
16
|
|
|
*/ |
17
|
|
|
class Kernel |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Container |
21
|
|
|
*/ |
22
|
|
|
protected $app; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $configPath = __DIR__. '/../config'; |
28
|
|
|
/** |
29
|
|
|
* @var CartDriverContract |
30
|
|
|
*/ |
31
|
|
|
protected $currentDriver; |
32
|
|
|
|
33
|
|
|
protected $coreServices = [ |
34
|
|
|
'config.singleton' => Repository::class, |
35
|
|
|
]; |
36
|
|
|
|
37
|
3 |
|
public function __construct() |
38
|
|
|
{ |
39
|
3 |
|
$this->app = Container::getInstance(); |
40
|
3 |
|
} |
41
|
|
|
|
42
|
2 |
|
public function bootstrapping($mode = 'base') : void |
43
|
|
|
{ |
44
|
|
|
switch ($mode) { |
45
|
2 |
|
case 'base': |
46
|
2 |
|
$this->loadCoreServiceProvider(); |
47
|
2 |
|
$this->loadConfigurationFiles(); |
48
|
2 |
|
$this->loadServiceProvider(); |
49
|
2 |
|
break; |
50
|
|
|
case 'laravel': |
51
|
|
|
$this->loadCoreServiceProvider(); |
52
|
|
|
$this->loadServiceProvider(); |
53
|
|
|
} |
54
|
2 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get type storage (Note: in config file) |
58
|
|
|
*/ |
59
|
1 |
|
public function getStorage() : CartDriverContract |
60
|
|
|
{ |
61
|
1 |
|
return $this->app->make(config('cart.storage')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Load configuration from config folder |
66
|
|
|
*/ |
67
|
2 |
|
public function loadConfigurationFiles() : void |
68
|
|
|
{ |
69
|
2 |
|
$repository = $this->app->make('config'); |
70
|
|
|
|
71
|
2 |
|
foreach ($this->getConfigurationFiles() as $key => $path) { |
72
|
2 |
|
$repository->set($key, require $path); |
|
|
|
|
73
|
|
|
} |
74
|
2 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get all of the configuration files for the application. |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
2 |
|
protected function getConfigurationFiles() : array |
81
|
|
|
{ |
82
|
2 |
|
$files = []; |
83
|
|
|
|
84
|
2 |
|
$configPath = realpath($this->configPath); |
85
|
|
|
|
86
|
2 |
|
foreach (Finder::create()->files()->name('*.php')->in($configPath) as $file) { |
87
|
2 |
|
$files[basename($file->getFilename(), '.php')] = $file->getRealPath(); |
88
|
|
|
} |
89
|
|
|
|
90
|
2 |
|
return $files; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Load mandatory services for application |
95
|
|
|
*/ |
96
|
2 |
|
protected function loadCoreServiceProvider() : void |
97
|
|
|
{ |
98
|
2 |
|
foreach ($this->coreServices as $abstract => $service) { |
99
|
2 |
|
list($abstract, $type) = explode('.', $abstract); |
100
|
|
|
|
101
|
2 |
|
if (app()->resolved($abstract) === false) { |
102
|
1 |
|
if ($type == 'singleton') { |
103
|
1 |
|
$this->app->singleton($abstract, $service); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
2 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Load service provider from config file |
111
|
|
|
*/ |
112
|
2 |
|
protected function loadServiceProvider() : void |
113
|
|
|
{ |
114
|
2 |
|
foreach (config('cart.services') as $services) { |
115
|
|
|
/** @var ServiceProviderContract */ |
116
|
2 |
|
(new $services)->register($this->app); |
117
|
|
|
} |
118
|
2 |
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.