Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e76190
commit 6f543a7
Showing
2 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
|
||
namespace Doctrine\Bundle\OXMBundle\CacheWarmer; | ||
|
||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; | ||
|
||
/** | ||
* The proxy generator cache warmer generates all document proxies. | ||
* | ||
* In the process of generating proxies the cache for all the metadata is primed also, | ||
* since this information is necessary to build the proxies in the first place. | ||
* | ||
* @author Igor Golovanov <igor.golovanov@gmail.com> | ||
*/ | ||
class ProxyCacheWarmer implements CacheWarmerInterface | ||
{ | ||
/** | ||
* @var Container | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @param Container $container | ||
*/ | ||
public function __construct(Container $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* This cache warmer is not optional, without proxies fatal error occurs! | ||
* | ||
* @return false | ||
*/ | ||
public function isOptional() | ||
{ | ||
return false; | ||
} | ||
|
||
public function warmUp($cacheDir) | ||
{ | ||
// we need the directory no matter the proxy cache generation strategy. | ||
$proxyCacheDir = $this->container->getParameter('doctrine.oxm.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)); | ||
} | ||
|
||
// if proxies are autogenerated we don't need to generate them in the cache warmer. | ||
if ($this->container->getParameter('doctrine.oxm.auto_generate_proxy_classes') === true) { | ||
return; | ||
} | ||
|
||
$xmlEntityManagers = $this->container->getParameter('doctrine.oxm.xml_entity_managers'); | ||
foreach ($xmlEntityManagers as $xmlEntityManagerName) { | ||
$xem = $this->container->get(sprintf('doctrine.oxm.%s_xml_entity_manager', $xmlEntityManagerName)); | ||
$classes = $xem->getMetadataFactory()->getAllMetadata(); | ||
$xem->getProxyFactory()->generateProxyClasses($classes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters