|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Bootstrappers\Navigation; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Event; |
|
8
|
|
|
use AbterPhp\Framework\Constant\Navigation as NavConstant; |
|
9
|
|
|
use AbterPhp\Framework\Events\NavigationReady; |
|
10
|
|
|
use AbterPhp\Framework\I18n\ITranslator; |
|
11
|
|
|
use AbterPhp\Framework\Navigation\Navigation; |
|
12
|
|
|
use Opulence\Events\Dispatchers\IEventDispatcher; |
|
13
|
|
|
use Opulence\Ioc\Bootstrappers\Bootstrapper; |
|
14
|
|
|
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper; |
|
15
|
|
|
use Opulence\Ioc\IContainer; |
|
16
|
|
|
use Opulence\Ioc\IocException; |
|
17
|
|
|
|
|
18
|
|
|
class NavigationBootstrapper extends Bootstrapper implements ILazyBootstrapper |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var string[][] */ |
|
21
|
|
|
protected array $bindingIntents = [ |
|
22
|
|
|
NavConstant::NAVBAR => [Navigation::INTENT_NAVBAR], |
|
23
|
|
|
NavConstant::PRIMARY => [Navigation::INTENT_PRIMARY], |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getBindings(): array |
|
30
|
|
|
{ |
|
31
|
|
|
return array_keys($this->bindingIntents); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param IContainer $container |
|
36
|
|
|
* |
|
37
|
|
|
* @throws IocException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function registerBindings(IContainer $container): void |
|
40
|
|
|
{ |
|
41
|
|
|
/** @var ITranslator $translator */ |
|
42
|
|
|
$translator = $container->resolve(ITranslator::class); |
|
43
|
|
|
|
|
44
|
|
|
/** @var IEventDispatcher $eventDispatcher */ |
|
45
|
|
|
$eventDispatcher = $container->resolve(IEventDispatcher::class); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($this->bindingIntents as $name => $intents) { |
|
48
|
|
|
$navigation = new Navigation($intents); |
|
49
|
|
|
|
|
50
|
|
|
$container->bindInstance($name, $navigation); |
|
51
|
|
|
|
|
52
|
|
|
$eventDispatcher->dispatch(Event::NAVIGATION_READY, new NavigationReady($navigation)); |
|
53
|
|
|
|
|
54
|
|
|
$navigation->setTranslator($translator); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|