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

BundleLoader::registerBundles()   A

Complexity

Conditions 3
Paths 4

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 12
Code Lines 7

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 2
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