forked from doctrine/DoctrineCouchDBBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoctrineCouchDBBundle.php
More file actions
83 lines (67 loc) · 3.45 KB
/
DoctrineCouchDBBundle.php
File metadata and controls
83 lines (67 loc) · 3.45 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*
* Doctrine CouchDB Bundle
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
namespace Doctrine\Bundle\CouchDBBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass;
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\DoctrineValidationPass;
class DoctrineCouchDBBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
$container->addCompilerPass(new DoctrineValidationPass('couchdb'));
}
public function boot()
{
// force Doctrine annotations to be loaded
// should be removed when a better solution is found in Doctrine
class_exists('Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver');
// Register an autoloader for proxies to avoid issues when unserializing them
// when the ORM is used.
if ($this->container->hasParameter('doctrine_couchdb.odm.proxy_namespace')) {
$namespace = $this->container->getParameter('doctrine_couchdb.odm.proxy_namespace');
$dir = $this->container->getParameter('doctrine_couchdb.odm.proxy_dir');
$container = $this->container;
spl_autoload_register(function($class) use ($namespace, $dir, $container) {
if (0 === strpos($class, $namespace)) {
$className = substr($class, strlen($namespace) +1);
$file = $dir.DIRECTORY_SEPARATOR.$className.'.php';
if (!is_file($file) && $container->getParameter('kernel.debug')) {
$originalClassName = substr($className, 0, -5);
$registry = $container->get('doctrine_couchdb');
// Tries to auto-generate the proxy file
foreach ($registry->getObjectManagers() as $manager) {
if ($manager->getConfiguration()->getAutoGenerateProxyClasses()) {
$classes = $manager->getMetadataFactory()->getAllMetadata();
foreach ($classes as $class) {
$name = str_replace('\\', '', $class->name);
if ($name == $originalClassName) {
$manager->getProxyFactory()->generateProxyClasses(array($class));
}
}
}
}
clearstatcache($file);
if (!is_file($file)) {
throw new \RuntimeException(sprintf('The proxy file "%s" does not exist. If you still have objects serialized in the session, you need to clear the session manually.', $file));
}
}
require $file;
}
});
}
}
}