Przeglądaj źródła

[DoctrineBundle] Remove the CreateProxyDirectoryPass and let the cache directory generation be done by the cache warmer.

Benjamin Eberlei 14 lat temu
rodzic
commit
18c611a29e

+ 9 - 0
src/Symfony/Bundle/DoctrineBundle/CacheWarmer/ProxyCacheWarmer.php

@@ -49,6 +49,15 @@ class ProxyCacheWarmer implements CacheWarmerInterface
 
 
     public function warmUp($cacheDir)
     public function warmUp($cacheDir)
     {
     {
+        $proxyCacheDir = $this->container->getParameter('doctrine.orm.proxy_dir');
+        if (!file_exists($proxyCacheDir)) {
+            if (false === @mkdir($proxyCacheDir, 0777, true)) {
+                throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir)));
+            }
+        } else if (!is_writable($proxyCacheDir)) {
+            throw new \RuntimeException(sprintf('Doctrine Proxy directory (%s) is not writeable for the current system user.', $proxyCacheDir));
+        }
+
         $entityManagers = $this->container->getParameter('doctrine.orm.entity_managers');
         $entityManagers = $this->container->getParameter('doctrine.orm.entity_managers');
         foreach ($entityManagers AS $entityManagerName) {
         foreach ($entityManagers AS $entityManagerName) {
             $em = $this->container->get(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName));
             $em = $this->container->get(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName));

+ 0 - 29
src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Compiler/CreateProxyDirectoryPass.php

@@ -1,29 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\DoctrineBundle\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-
-class CreateProxyDirectoryPass implements CompilerPassInterface
-{
-    public function process(ContainerBuilder $container)
-    {
-        if (!$container->hasParameter('doctrine.orm.proxy_dir')) {
-            return;
-        }
-        // Don't do anything if auto_generate_proxy_classes is false
-        if (!$container->getParameter('doctrine.orm.auto_generate_proxy_classes')) {
-            return;
-        }
-        $proxyCacheDir = $container->getParameter('doctrine.orm.proxy_dir');
-        // Create entity proxy directory
-        if (!is_dir($proxyCacheDir)) {
-            if (false === @mkdir($proxyCacheDir, 0777, true)) {
-                throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir)));
-            }
-        } elseif (!is_writable($proxyCacheDir) && $container->getParameter('doctrine.orm.auto_generate_proxy_classes') == true) {
-            throw new \RuntimeException(sprintf('Unable to write in the Doctrine Proxy directory (%s)', $proxyCacheDir));
-        }
-    }
-}

+ 8 - 2
src/Symfony/Bundle/DoctrineBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php

@@ -20,6 +20,8 @@ class ProxyCacheWarmerTest extends \Symfony\Bundle\DoctrineBundle\Tests\TestCase
      * because there are none in the AnnotationsBundle. However that is
      * because there are none in the AnnotationsBundle. However that is
      * rather a task of doctrine to test. We touch the lines here and
      * rather a task of doctrine to test. We touch the lines here and
      * verify that the container is called correctly for the relevant information.
      * verify that the container is called correctly for the relevant information.
+     *
+     * @group DoctrineORMProxy
      */
      */
     public function testWarmCache()
     public function testWarmCache()
     {
     {
@@ -28,14 +30,18 @@ class ProxyCacheWarmerTest extends \Symfony\Bundle\DoctrineBundle\Tests\TestCase
         );
         );
         $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
         $container = $this->getMock('Symfony\Component\DependencyInjection\Container');
         $container->expects($this->at(0))
         $container->expects($this->at(0))
+                  ->method('getParameter')
+                  ->with($this->equalTo('doctrine.orm.proxy_dir'))
+                  ->will($this->returnValue(sys_get_temp_dir()));
+        $container->expects($this->at(1))
                   ->method('getParameter')
                   ->method('getParameter')
                   ->with($this->equalTo('doctrine.orm.entity_managers'))
                   ->with($this->equalTo('doctrine.orm.entity_managers'))
                   ->will($this->returnValue(array('default', 'foo')));
                   ->will($this->returnValue(array('default', 'foo')));
-        $container->expects($this->at(1))
+        $container->expects($this->at(2))
                   ->method('get')
                   ->method('get')
                   ->with($this->equalTo('doctrine.orm.default_entity_manager'))
                   ->with($this->equalTo('doctrine.orm.default_entity_manager'))
                   ->will($this->returnValue($testManager));
                   ->will($this->returnValue($testManager));
-        $container->expects($this->at(2))
+        $container->expects($this->at(3))
                   ->method('get')
                   ->method('get')
                   ->with($this->equalTo('doctrine.orm.foo_entity_manager'))
                   ->with($this->equalTo('doctrine.orm.foo_entity_manager'))
                   ->will($this->returnValue($testManager));
                   ->will($this->returnValue($testManager));