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

Neo4jBundle   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 57.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 36
ccs 11
cts 19
cp 0.5789
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainerExtension() 0 4 1
A boot() 0 18 4
A shutdown() 0 7 2
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