Completed
Push — master ( 4c7e7c...16e98c )
by Tobias
04:42
created

Neo4jBundle::boot()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 7.1753

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 5
cts 12
cp 0.4167
rs 9.2
cc 4
eloc 10
nc 2
nop 0
crap 7.1753
1
<?php
2
3
namespace Neo4j\Neo4jBundle;
4
5
use Neo4j\Neo4jBundle\DependencyInjection\Neo4jExtension;
6
use Symfony\Component\HttpKernel\Bundle\Bundle;
7
8
/**
9
 * @author Tobias Nyholm <[email protected]>
10
 */
11
class Neo4jBundle extends Bundle
12
{
13
    private $autoloader;
14
15 1
    public function getContainerExtension()
16
    {
17 1
        return new Neo4jExtension();
18
    }
19
20 1
    public function boot()
21
    {
22
        // Register an autoloader for proxies to avoid issues when unserializing them when the OGM is used.
23 1
        if ($this->container->has('neo4j.entity_manager')) {
24
            // See https://github.com/symfony/symfony/pull/3419 for usage of references
25 1
            $container = &$this->container;
26
            $this->autoloader = function ($class) use (&$container) {
27
                if (0 === strpos($class, 'neo4j_ogm_proxy')) {
28
                    $cacheDir = $container->getParameter('kernel.cache_dir').DIRECTORY_SEPARATOR.'neo4j';
29
                    $file = $cacheDir.DIRECTORY_SEPARATOR.$class.'.php';
30
                    if (file_exists($file)) {
31
                        require_once $file;
32
                    }
33
                }
34
            };
35 1
            spl_autoload_register($this->autoloader);
36
        }
37 1
    }
38
39 1
    public function shutdown()
40
    {
41 1
        if (null === $this->autoloader) {
42
            return;
43
        }
44 1
        spl_autoload_unregister($this->autoloader);
45 1
    }
46
}
47