This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
/
ProxyCacheWarmer.php
55 lines (46 loc) · 1.83 KB
/
ProxyCacheWarmer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Doctrine\Bundle\CouchDBBundle\CacheWarmer;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ProxyCacheWarmer implements CacheWarmerInterface
{
private $container;
/**
* Constructor.
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $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)
{
foreach ($this->container->getParameter('doctrine_couchdb.document_managers') as $dmName) {
$dm = $this->container->get($dmName);
// we need the directory no matter the proxy cache generation strategy
if (!file_exists($proxyCacheDir = $dm->getConfiguration()->getProxyDir())) {
if (false === @mkdir($proxyCacheDir, 0777, true)) {
throw new \RuntimeException(sprintf('Unable to create the Doctrine CouchDB Proxy directory "%s".', dirname($proxyCacheDir)));
}
} elseif (!is_writable($proxyCacheDir)) {
throw new \RuntimeException(sprintf('The Doctrine CouchDB 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 ($dm->getConfiguration()->getAutoGenerateProxyClasses()) {
continue;
}
$classes = $dm->getMetadataFactory()->getAllMetadata();
$dm->getProxyFactory()->generateProxyClasses($classes);*/
}
}
}