Skip to content
This repository
Browse code

merged branch stof/doctrine_autoload (PR #3584)

Commits
-------

878c239 Fixed autoloader leakage in tests

Discussion
----------

Doctrine autoload

The autoloader for proxies is now unregistered on shutdown to avoid
having several instances registered at the same time in tests.
  • Loading branch information...
commit e335fa208c1c44202651f760503816869994ea86 2 parents b062cc7 + 878c239
Fabien Potencier fabpot authored

Showing 1 changed file with 13 additions and 2 deletions. Show diff stats Hide diff stats

  1. +13 2 src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php
15 src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php
@@ -24,6 +24,8 @@
24 24 */
25 25 class DoctrineBundle extends Bundle
26 26 {
  27 + private $autoloader;
  28 +
27 29 public function build(ContainerBuilder $container)
28 30 {
29 31 parent::build($container);
@@ -44,7 +46,7 @@ class_exists('Doctrine\ORM\Mapping\Driver\AnnotationDriver');
44 46 $dir = $this->container->getParameter('doctrine.orm.proxy_dir');
45 47 $container =& $this->container;
46 48
47   - spl_autoload_register(function($class) use ($namespace, $dir, &$container) {
  49 + $this->autoloader = function($class) use ($namespace, $dir, &$container) {
48 50 if (0 === strpos($class, $namespace)) {
49 51 $className = substr($class, strlen($namespace) +1);
50 52 $file = $dir.DIRECTORY_SEPARATOR.$className.'.php';
@@ -78,7 +80,16 @@ class_exists('Doctrine\ORM\Mapping\Driver\AnnotationDriver');
78 80
79 81 require $file;
80 82 }
81   - });
  83 + };
  84 + spl_autoload_register($this->autoloader);
  85 + }
  86 + }
  87 +
  88 + public function shutdown()
  89 + {
  90 + if (null !== $this->autoloader) {
  91 + spl_autoload_unregister($this->autoloader);
  92 + $this->autoloader = null;
82 93 }
83 94 }
84 95 }

0 comments on commit e335fa2

Please sign in to comment.
Something went wrong with that request. Please try again.