Passed
Push — master ( 48c9d3...068249 )
by Peter
02:10
created

Listeners::getBindings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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