|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Bundle\DoctrineBundle; |
|
13 |
|
14 use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
|
15 use Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass; |
|
16 use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17 use Symfony\Component\HttpKernel\Bundle\Bundle; |
|
18 |
|
19 /** |
|
20 * Bundle. |
|
21 * |
|
22 * @author Fabien Potencier <fabien@symfony.com> |
|
23 * @author Jonathan H. Wage <jonwage@gmail.com> |
|
24 */ |
|
25 class DoctrineBundle extends Bundle |
|
26 { |
|
27 public function build(ContainerBuilder $container) |
|
28 { |
|
29 parent::build($container); |
|
30 |
|
31 $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); |
|
32 } |
|
33 |
|
34 public function boot() |
|
35 { |
|
36 // force Doctrine annotations to be loaded |
|
37 // should be removed when a better solution is found in Doctrine |
|
38 class_exists('Doctrine\ORM\Mapping\Driver\AnnotationDriver'); |
|
39 |
|
40 // Register an autoloader for proxies to avoid issues when unserializing them |
|
41 // when the ORM is used. |
|
42 if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) { |
|
43 $namespace = $this->container->getParameter('doctrine.orm.proxy_namespace'); |
|
44 $dir = $this->container->getParameter('doctrine.orm.proxy_dir'); |
|
45 |
|
46 spl_autoload_register(function($class) use ($namespace, $dir) { |
|
47 if (0 === strpos($class, $namespace)) { |
|
48 $className = substr($class, strlen($namespace) +1); |
|
49 $file = $dir.DIRECTORY_SEPARATOR.$className.'.php'; |
|
50 |
|
51 if (!file_exists($file)) { |
|
52 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)); |
|
53 } |
|
54 |
|
55 require $file; |
|
56 } |
|
57 }); |
|
58 } |
|
59 } |
|
60 } |