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);
 }
Ejemplo n.º 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);
 }
 public function setUp()
 {
     $validatorBuilder = new ValidatorBuilder();
     $validatorBuilder->enableAnnotationMapping();
     $this->testSubject = new ValidatorInterceptor($validatorBuilder->getValidator());
     $this->mockInterceptorChain = $this->getMock(InterceptorChainInterface::class);
     $this->uow = $this->getMock(UnitOfWorkInterface::class);
 }
Ejemplo n.º 4
0
 /**
  * @test
  */
 public function simpleForm()
 {
     Helper::addServiceClass(SimpleForm::class);
     $form = Helper::getService(SimpleForm::class);
     $builder = new ValidatorBuilder();
     $builder->enableAnnotationMapping();
     $validator = $builder->getValidator();
     $response = $validator->validate($form);
     $this->assertEquals(5, count($response));
 }
 /**
  * @return ValidatorInterface
  */
 private function getValidatorWithAnnotationReader()
 {
     $validator = new ValidatorBuilder();
     $validator->enableAnnotationMapping($this->getAnnotationReader());
     return $validator->getValidator();
 }
Ejemplo n.º 6
0
 private function bindingResultBuild()
 {
     $bind = new BindingResult();
     $builder = new ValidatorBuilder();
     $builder->enableAnnotationMapping();
     foreach ($this->modelAttributes as $param) {
         if (in_array($param, $this->invokeParams)) {
             foreach ($builder->getValidator()->validate($param) as $offset => $violation) {
                 $bind->offsetSet($offset, $violation);
             }
         }
     }
     $bindRef = new \ReflectionObject($bind);
     $propRef = $bindRef->getProperty('map');
     $propRef->setAccessible(true);
     $map = array();
     foreach ($this->reflMethod->getParameters() as $param) {
         if (!$param instanceof BindingResult && $param->getClass()) {
             $map[$param->getClass()->getName()] = $param->getName();
         }
     }
     $propRef->setValue($bind, $map);
     return $bind;
 }