forked from neo4j-php/neo4j-symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeo4jBundle.php
46 lines (40 loc) · 1.36 KB
/
Neo4jBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Neo4j\Neo4jBundle;
use Neo4j\Neo4jBundle\DependencyInjection\Neo4jExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class Neo4jBundle extends Bundle
{
private $autoloader;
public function getContainerExtension()
{
return new Neo4jExtension();
}
public function boot()
{
// Register an autoloader for proxies to avoid issues when unserializing them when the OGM is used.
if ($this->container->has('neo4j.entity_manager')) {
// See https://github.com/symfony/symfony/pull/3419 for usage of references
$container = &$this->container;
$this->autoloader = function ($class) use (&$container) {
if (0 === strpos($class, 'neo4j_ogm_proxy')) {
$cacheDir = $container->getParameter('kernel.cache_dir').DIRECTORY_SEPARATOR.'neo4j';
$file = $cacheDir.DIRECTORY_SEPARATOR.$class.'.php';
if (file_exists($file)) {
require_once $file;
}
}
};
spl_autoload_register($this->autoloader);
}
}
public function shutdown()
{
if (null === $this->autoloader) {
return;
}
spl_autoload_unregister($this->autoloader);
}
}