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

This commit is contained in:
Benjamin Eberlei 2011-01-26 00:27:58 +01:00 committed by Fabien Potencier
parent 8cfa246887
commit 18c611a29e
3 changed files with 17 additions and 31 deletions

View File

@ -49,6 +49,15 @@ class ProxyCacheWarmer implements CacheWarmerInterface
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');
foreach ($entityManagers AS $entityManagerName) {
$em = $this->container->get(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName));

View File

@ -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));
}
}
}

View File

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