Passed
Push — master ( 204000...ebf7d2 )
by Peter
02:06
created

ListenersBootstrapper::getBindings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\PropellerAdmin\Bootstrappers\Events;
6
7
use AbterPhp\Framework\Assets\AssetManager;
8
use AbterPhp\PropellerAdmin\Events\Listeners\AdminDecorator;
9
use AbterPhp\PropellerAdmin\Events\Listeners\LoginDecorator;
10
use Opulence\Framework\Configuration\Config;
11
use Opulence\Ioc\Bootstrappers\Bootstrapper;
12
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper;
13
use Opulence\Ioc\IContainer;
14
15
class ListenersBootstrapper extends Bootstrapper implements ILazyBootstrapper
16
{
17
    const MODULE_IDENTIFIER = 'AbterPhp\\PropellerAdmin';
18
19
    const PROPELLER_PATH = 'propeller/';
20
21
    /**
22
     * @return array
23
     */
24
    public function getBindings(): array
25
    {
26
        return [
27
            AdminDecorator::class,
28
            LoginDecorator::class,
29
        ];
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function registerBindings(IContainer $container)
36
    {
37
        $resourceDir = $this->getResourceDir();
38
39
        $header = file_get_contents($resourceDir . 'header.html');
40
        $footer = file_get_contents($resourceDir . 'footer.html');
41
42
        /** @var AssetManager $assetManager */
43
        $assetManager = $container->resolve(AssetManager::class);
44
45
        $adminDecorator = new AdminDecorator($assetManager, $header, $footer);
46
        $loginDecorator = new LoginDecorator($assetManager, $header, $footer);
47
48
        $container->bindInstance(AdminDecorator::class, $adminDecorator);
49
        $container->bindInstance(LoginDecorator::class, $loginDecorator);
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    protected function getResourceDir(): string
56
    {
57
        global $abterModuleManager;
58
59
        foreach ($abterModuleManager->getResourcePaths() as $id => $path) {
60
            if ($id !== static::MODULE_IDENTIFIER) {
61
                continue;
62
            }
63
64
            return sprintf('%s/%s', $path, static::PROPELLER_PATH);
65
        }
66
67
        return '';
68
    }
69
}
70