[DoctrineBundle] Fixed performances issues on "On-demand" proxy file
generation
This commit is contained in:
parent
e866a678d2
commit
0c4b79396b
@ -42,36 +42,36 @@ class DoctrineBundle extends Bundle
|
||||
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)) {
|
||||
$originalClassName = substr($className, 0, -5);
|
||||
$registry = $container->get('doctrine');
|
||||
|
||||
// Tries to auto-generate the proxy file
|
||||
if (preg_match('/^(.+)\\\\([a-z0-9_]+)Proxy$/i', $class, $matches)) {
|
||||
$className = $matches[2];
|
||||
foreach ($registry->getEntityManagers() as $em) {
|
||||
|
||||
foreach ($doctrine->getEntityManagers() as $em) {
|
||||
$em = $doctrine->getEntityManager();
|
||||
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));
|
||||
|
Reference in New Issue
Block a user