public function build()
 {
     $this->setObjectManager($this->createEntityManager());
     $this->serializerBuilder = BreezeSerializerBuilder::create($this->getObjectManager());
     $this->validatorBuilder = new ValidatorBuilder();
     if ($this->annotationsEnabled) {
         $this->validatorBuilder->enableAnnotationMapping();
     }
     foreach ($this->mappings as $mapping) {
         if (isset($mapping['serializer'])) {
             $this->serializerBuilder->addMetadataDir($mapping['serializer']);
         }
         if (isset($mapping['validation'])) {
             if ($mapping['type'] == 'xml') {
                 $this->validatorBuilder->addXmlMapping($mapping['validation']);
             } else {
                 if ($mapping['type'] == 'yaml') {
                     $this->validatorBuilder->addYamlMapping($mapping['validation']);
                 }
             }
             //                else if ($mapping['type'] == 'annotation') {
             //                    $this->validatorBuilder->enableAnnotationMapping();
             //                }
         }
     }
     $serializer = $this->serializerBuilder->build();
     $this->setSerializer($serializer);
     $validator = $this->validatorBuilder->getValidator();
     $this->setValidator($validator);
 }
Пример #2
1
 public function testWarmUp()
 {
     $validatorBuilder = new ValidatorBuilder();
     $validatorBuilder->addXmlMapping(__DIR__ . '/../Fixtures/Validation/Resources/person.xml');
     $validatorBuilder->addYamlMapping(__DIR__ . '/../Fixtures/Validation/Resources/author.yml');
     $validatorBuilder->addMethodMapping('loadValidatorMetadata');
     $validatorBuilder->enableAnnotationMapping();
     $file = sys_get_temp_dir() . '/cache-validator.php';
     @unlink($file);
     $fallbackPool = new ArrayAdapter();
     $warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
     $warmer->warmUp(dirname($file));
     $this->assertFileExists($file);
     $values = (require $file);
     $this->assertInternalType('array', $values);
     $this->assertCount(2, $values);
     $this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person', $values);
     $this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author', $values);
     $values = $fallbackPool->getValues();
     $this->assertInternalType('array', $values);
     $this->assertCount(2, $values);
     $this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person', $values);
     $this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author', $values);
 }