Skip to content

Commit

Permalink
Fixed proxy generation in the DoctrineBundle when using Doctrine >= 2…
Browse files Browse the repository at this point in the history
….2.0
  • Loading branch information
Martin Parsiegla committed Mar 14, 2012
1 parent 92c5785 commit 50cb486
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php
Expand Up @@ -15,6 +15,8 @@
use Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Doctrine\ORM\Version;
use Doctrine\Common\Util\ClassUtils;

/**
* Bundle.
Expand Down Expand Up @@ -49,11 +51,16 @@ class_exists('Doctrine\ORM\Mapping\Driver\AnnotationDriver');
$this->autoloader = function($class) use ($namespace, $dir, &$container) {
if (0 === strpos($class, $namespace)) {
$className = substr($class, strlen($namespace) +1);
$file = $dir.DIRECTORY_SEPARATOR.$className.'.php';
$file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', '', $className).'.php';

if (!file_exists($file) && $container->getParameter('kernel.debug')) {
$originalClassName = substr($className, 0, -5);
$registry = $container->get('doctrine');
if (1 === Version::compare('2.2.0')) {
$originalClassName = substr($className, 0, -5);
} else {
$originalClassName = ClassUtils::getRealClass($className);
$originalClassName = str_replace('\\', '', $originalClassName);
}

// Tries to auto-generate the proxy file
foreach ($registry->getEntityManagers() as $em) {
Expand Down

3 comments on commit 50cb486

@robocoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Spea Can you make a PR on github.com/doctrine/DoctrineBundle as well? This would address doctrine/DoctrineBundle#47

@alebo
Copy link
Contributor

@alebo alebo commented on 50cb486 May 17, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work for me with Symfony 2.0.13 and Doctrine 2.2.2

This code

$className = substr($class, strlen($namespace) +1);

leaves a class name starting with "CG..." while

ClassUtils::getRealClass($className);

expects it to to be "_CG_..." to work correctly

@robocoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alebo try updating your deps to 2.3.0-dev. ClassUtils was introduced in 2.2.0.

Please sign in to comment.