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