Listeners::getResourceDir()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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