annotation_reader_provider = $annotation_reader_provider; } function createValidator() { $builder = Validation::createValidatorBuilder(); // annotation reader exists only in dev environment, on production cache is pre-generated $annotation_reader = $this->annotation_reader_provider->getAnnotationReader(); if ($annotation_reader) { $builder->enableAnnotationMapping($annotation_reader); } // metadata cache (for production cache is pre-generated at build time) $is_read_only = !$annotation_reader; $metadata_cache = new MetadataCache(self::METADATA_DIR, $is_read_only); $builder->setMetadataCache(new DoctrineCache($metadata_cache)); return $builder->getValidator(); } }