Passed
Push — master ( 1b7182...8b2fed )
by Peter
02:40
created

FileFinderBootstrapper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerBindings() 0 8 1
A getBindings() 0 5 1
A registerResourcePaths() 0 19 4
1
<?php
2
3
namespace AbterPhp\Framework\Bootstrappers\Filesystem;
4
5
use AbterPhp\Framework\Constant\Env;
6
use AbterPhp\Framework\Filesystem\FileFinder;
7
use AbterPhp\Framework\Filesystem\IFileFinder;
8
use AbterPhp\Framework\Module\Manager;
9
use League\Flysystem\Adapter\Local;
10
use League\Flysystem\Filesystem;
11
use Opulence\Ioc\Bootstrappers\Bootstrapper;
12
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper;
13
use Opulence\Ioc\IContainer;
14
15
class FileFinderBootstrapper extends Bootstrapper implements ILazyBootstrapper
16
{
17
    /**
18
     * @return array
19
     */
20
    public function getBindings(): array
21
    {
22
        return [
23
            FileFinder::class,
24
            IFileFinder::class,
25
        ];
26
    }
27
28
    /**
29
     * @param IContainer $container
30
     */
31
    public function registerBindings(IContainer $container)
32
    {
33
        $fileFinder = new FileFinder();
34
35
        $this->registerResourcePaths($fileFinder);
36
37
        $container->bindInstance(FileFinder::class, $fileFinder);
38
        $container->bindInstance(IFileFinder::class, $fileFinder);
39
    }
40
41
    /**
42
     * @param FileFinder $fileFinder
43
     */
44
    private function registerResourcePaths(FileFinder $fileFinder)
45
    {
46
        /** @var Manager $abterModuleManager */
47
        global $abterModuleManager;
48
49
        $assetsPaths = $abterModuleManager->getAssetsPaths();
50
51
        foreach ($assetsPaths as $key => $paths) {
52
            foreach ($paths as $path) {
53
                if (!$path) {
54
                    continue;
55
                }
56
                $fileFinder->registerFilesystem(new Filesystem(new Local($path)), $key);
57
            }
58
        }
59
60
        $dirPublic = rtrim(getenv(Env::DIR_PUBLIC), DIRECTORY_SEPARATOR);
61
62
        $fileFinder->registerFilesystem(new Filesystem(new Local($dirPublic)));
63
    }
64
}
65