Skip to content

Commit 16e98c9

Browse files
ikwattroNyholm
authored andcommitted
register an autoloader for proxies to avoid issues when unserialising (#40)
* register an autoloader for proxies to avoid issues when unserialising * fix case where container is not initalized * removed ignore * fixed boot * re-add getContainerExtension method
1 parent 4c7e7c6 commit 16e98c9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Neo4jBundle.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,37 @@
1010
*/
1111
class Neo4jBundle extends Bundle
1212
{
13+
private $autoloader;
14+
1315
public function getContainerExtension()
1416
{
1517
return new Neo4jExtension();
1618
}
19+
20+
public function boot()
21+
{
22+
// Register an autoloader for proxies to avoid issues when unserializing them when the OGM is used.
23+
if ($this->container->has('neo4j.entity_manager')) {
24+
// See https://github.com/symfony/symfony/pull/3419 for usage of references
25+
$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+
spl_autoload_register($this->autoloader);
36+
}
37+
}
38+
39+
public function shutdown()
40+
{
41+
if (null === $this->autoloader) {
42+
return;
43+
}
44+
spl_autoload_unregister($this->autoloader);
45+
}
1746
}

0 commit comments

Comments
 (0)