Skip to content

Commit

Permalink
[DoctrineBundle] refactored Doctrine proxy cache warmer
Browse files Browse the repository at this point in the history
* removed the dependency on the Container
* the proxy cache is now get from each entity manager configuration
  • Loading branch information
fabpot committed Jun 7, 2011
1 parent 1c3fa20 commit 22428b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 118 deletions.
41 changes: 20 additions & 21 deletions src/Symfony/Bundle/DoctrineBundle/CacheWarmer/ProxyCacheWarmer.php
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Bundle\DoctrineBundle\CacheWarmer;

use Symfony\Component\DependencyInjection\Container;
use Symfony\Bundle\DoctrineBundle\Registry;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;

/**
Expand All @@ -24,17 +24,16 @@
*/
class ProxyCacheWarmer implements CacheWarmerInterface
{
/**
* @var Container
*/
private $container;
private $registry;

/**
* @param Container $container
* Constructor.
*
* @param Registry $registry The Doctrine registry
*/
public function __construct(Container $container)
public function __construct(Registry $registry)
{
$this->container = $container;
$this->registry = $registry;
}

/**
Expand All @@ -49,23 +48,23 @@ public function isOptional()

public function warmUp($cacheDir)
{
// we need the directory no matter the proxy cache generation strategy.
$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)));
foreach ($this->registry->getEntityManagers() as $em) {
// we need the directory no matter the proxy cache generation strategy
if (!file_exists($proxyCacheDir = $em->getConfiguration()->getProxyDir())) {
if (false === @mkdir($proxyCacheDir, 0777, true)) {
throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".', dirname($proxyCacheDir)));
}
} elseif (!is_writable($proxyCacheDir)) {
throw new \RuntimeException(sprintf('The Doctrine Proxy directory "%s" is not writeable for the current system user.', $proxyCacheDir));
}
} else if (!is_writable($proxyCacheDir)) {
throw new \RuntimeException(sprintf('Doctrine Proxy directory (%s) is not writeable for the current system user.', $proxyCacheDir));
}

// if proxies are autogenerated we don't need to generate them in the cache warmer.
if ($this->container->getParameter('doctrine.orm.auto_generate_proxy_classes') === true) {
return;
}
// if proxies are autogenerated we don't need to generate them in the cache warmer
if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
continue;
}

foreach ($this->container->get('doctrine')->getEntityManagers() as $em) {
$classes = $em->getMetadataFactory()->getAllMetadata();

$em->getProxyFactory()->generateProxyClasses($classes);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml
Expand Up @@ -44,7 +44,7 @@

<service id="doctrine.orm.proxy_cache_warmer" class="%doctrine.orm.proxy_cache_warmer.class%" public="false">
<tag name="kernel.cache_warmer" />
<argument type="service" id="service_container" />
<argument type="service" id="doctrine" />
</service>

<service id="form.type_guesser.doctrine" class="%form.type_guesser.doctrine.class%">
Expand Down

This file was deleted.

0 comments on commit 22428b8

Please sign in to comment.