1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Mvc; |
4
|
|
|
|
5
|
|
|
use ByTIC\PackageBase\BaseBootableServiceProvider; |
6
|
|
|
use Nip\Mvc\Modules\ModulesManager; |
7
|
|
|
use Nip\Mvc\Sections\SectionsManager; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MvcServiceProvider |
11
|
|
|
* @package Nip\Mvc |
12
|
|
|
*/ |
13
|
|
|
class MvcServiceProvider extends BaseBootableServiceProvider |
14
|
|
|
{ |
15
|
|
|
public const NAME = 'mvc'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
1 |
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
1 |
|
public function register() |
21
|
1 |
|
{ |
22
|
1 |
|
$this->registerModules(); |
23
|
|
|
$this->registerSections(); |
24
|
1 |
|
} |
25
|
|
|
|
26
|
|
|
protected function registerModules() |
27
|
1 |
|
{ |
28
|
1 |
|
$this->getContainer()->share('mvc.modules', function () { |
29
|
1 |
|
return $this->createModulesProvider(); |
30
|
|
|
}); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
1 |
|
* @return ModulesManager |
35
|
|
|
*/ |
36
|
1 |
|
protected function createModulesProvider() |
37
|
1 |
|
{ |
38
|
|
|
if ($this->getContainer()->has(Modules::class)) { |
39
|
|
|
return $this->getContainer()->get(Modules::class); |
40
|
|
|
} |
41
|
|
|
if ($this->getContainer()->has(ModulesManager::class)) { |
42
|
|
|
return $this->getContainer()->get(ModulesManager::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return new ModulesManager(); |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
protected function registerSections() |
49
|
1 |
|
{ |
50
|
1 |
|
$this->getContainer()->share('mvc.sections', function () { |
51
|
1 |
|
return $this->createSectionsManager(); |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
1 |
|
* @return SectionsManager |
57
|
|
|
*/ |
58
|
1 |
|
protected function createSectionsManager() |
59
|
1 |
|
{ |
60
|
|
|
if ($this->getContainer()->has(SectionsManager::class)) { |
61
|
|
|
return $this->getContainer()->get(SectionsManager::class); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return new SectionsManager(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritdoc |
69
|
|
|
*/ |
70
|
|
|
public function provides() |
71
|
|
|
{ |
72
|
|
|
return ['mvc.modules', 'mvc.sections']; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|