Neo4jBundle::boot()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 7.1753

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 5
cts 12
cp 0.4167
rs 9.6666
c 0
b 0
f 0
cc 4
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