暂无描述

AnnotationReaderProvider.php 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace MailPoet\Doctrine\Annotations;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoetVendor\Doctrine\Common\Annotations\AnnotationReader;
  5. use MailPoetVendor\Doctrine\Common\Annotations\AnnotationRegistry;
  6. use MailPoetVendor\Doctrine\Common\Annotations\CachedReader;
  7. use MailPoetVendor\Doctrine\Common\Cache\ArrayCache;
  8. class AnnotationReaderProvider {
  9. /** @var CachedReader */
  10. private $annotationReader;
  11. public function __construct() {
  12. // register annotation reader if doctrine/annotations package is installed
  13. // (i.e. in dev environment, on production metadata is dumped in the build)
  14. $readAnnotations = class_exists(CachedReader::class) && class_exists(AnnotationReader::class);
  15. if ($readAnnotations) {
  16. // autoload all annotation classes using registered loaders (Composer)
  17. // (needed for Symfony\Validator constraint annotations to be loaded)
  18. AnnotationRegistry::registerLoader('class_exists');
  19. $this->annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
  20. }
  21. }
  22. /** @return CachedReader|null */
  23. public function getAnnotationReader() {
  24. return $this->annotationReader;
  25. }
  26. }