Completed
Push — master ( f1eedc...1b618f )
by Adam
05:55
created

BundleLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace WellCommerce\Bundle\CoreBundle\Loader;
4
5
use Doctrine\Common\Collections\Collection;
6
use Symfony\Component\HttpKernel\KernelInterface;
7
use WellCommerce\Bundle\CoreBundle\Locator\BundleLocator;
8
9
/**
10
 * Class BundleLoader
11
 *
12
 * @author  Adam Piotrowski <[email protected]>
13
 */
14
final class BundleLoader
15
{
16
    /**
17
     * @var KernelInterface
18
     */
19
    protected $kernel;
20
    
21
    public function __construct(KernelInterface $kernel)
22
    {
23
        $this->kernel = $kernel;
24
    }
25
    
26
    public function registerBundles(Collection $collection, string $environment)
27
    {
28
        if (is_file($cache = $this->kernel->getCacheDir() . '/bundles.php')) {
29
            $bundleClasses = require $cache;
30
        } else {
31
            $bundleClasses = $this->getLocator()->getBundleClasses();
32
        }
33
        
34
        foreach ($bundleClasses as $bundleClass) {
35
            $collection->add(new $bundleClass);
36
        }
37
    }
38
    
39
    private function getLocator(): BundleLocator
40
    {
41
        return new BundleLocator($this->kernel);
42
    }
43
}
44