-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PhpArrayAdapter to cache metadata
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 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,39 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\DoctrineBundle\CacheWarmer; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Mapping\ClassMetadataFactory; | ||
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AbstractPhpFileCacheWarmer; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
use Symfony\Component\Cache\DoctrineProvider; | ||
|
||
class DoctrineMetadataCacheWarmer extends AbstractPhpFileCacheWarmer | ||
{ | ||
/** | ||
* @var EntityManagerInterface | ||
*/ | ||
private $entityManager; | ||
|
||
public function __construct(EntityManagerInterface $entityManager, string $phpArrayFile) | ||
{ | ||
$this->entityManager = $entityManager; | ||
|
||
parent::__construct($phpArrayFile); | ||
} | ||
|
||
/** | ||
* @param string $cacheDir | ||
* | ||
* @return bool false if there is nothing to warm-up | ||
*/ | ||
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter) | ||
{ | ||
$metadataFactory = new ClassMetadataFactory(); | ||
$metadataFactory->setEntityManager($this->entityManager); | ||
$metadataFactory->setCacheDriver(new DoctrineProvider($arrayAdapter)); | ||
$metadataFactory->getAllMetadata(); | ||
|
||
return true; | ||
} | ||
} |
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