Permalink
Browse files

[DoctrineBundle] Fixed performances issues on "On-demand" proxy file

generation
  • Loading branch information...
Grégoire Passault
Grégoire Passault committed Aug 16, 2011
1 parent 2a35a80 commit 7b4919c5bd049b9214980521f646e2e016b8798d
Showing with 15 additions and 15 deletions.
  1. +15 −15 DoctrineBundle.php
View
@@ -42,36 +42,36 @@ class_exists('Doctrine\ORM\Mapping\Driver\AnnotationDriver');
if ($this->container->hasParameter('doctrine.orm.proxy_namespace')) {
$namespace = $this->container->getParameter('doctrine.orm.proxy_namespace');
$dir = $this->container->getParameter('doctrine.orm.proxy_dir');
- $doctrine = $this->container->get('doctrine');
+ $container = $this->container;
- spl_autoload_register(function($class) use ($namespace, $dir, $doctrine) {
+ 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 (!file_exists($file)) {
- // Tries to auto-generate the proxy file
- if (preg_match('/^(.+)\\\\([a-z0-9_]+)Proxy$/i', $class, $matches)) {
- $className = $matches[2];
+ $originalClassName = substr($className, 0, -5);
+ $registry = $container->get('doctrine');
- foreach ($doctrine->getEntityManagers() as $em) {
- $em = $doctrine->getEntityManager();
+ // Tries to auto-generate the proxy file
+ foreach ($registry->getEntityManagers() as $em) {
- if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
+ if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
- $classes = $em->getMetadataFactory()->getAllMetadata();
- foreach ($classes as $class)
- {
- $name = str_replace('\\', '', $class->name);
+ $classes = $em->getMetadataFactory()->getAllMetadata();
+ foreach ($classes as $class)
+ {
+ $name = str_replace('\\', '', $class->name);
- if ($name == $className) {
- $em->getProxyFactory()->generateProxyClasses(array($class));
- }
+ if ($name == $originalClassName) {
+ $em->getProxyFactory()->generateProxyClasses(array($class));
}
}
}
}
}
+
+ clearstatcache($file);
if (!file_exists($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));

0 comments on commit 7b4919c

Please sign in to comment.