Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public static function loadValidatorMetadata(ClassMetadata $classMetadata)
 {
     $classMetadata->addPropertyConstraint('title', Assert::stringType()->notBlank());
     $classMetadata->addPropertyConstraint('content', Assert::stringType());
     $classMetadata->addPropertyConstraint('title', Assert::intType()->notBlank(), 'foo');
     $classMetadata->addPropertyConstraint('content', Assert::intType()->notBlank(), 'foo');
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public static function loadValidatorMetadata(ClassMetadata $classMetadata)
 {
     $classMetadata->addPropertyConstraint('email', Assert::email());
     $classMetadata->addPropertyConstraint('password', Assert::stringType()->notBlank());
 }
Exemplo n.º 3
0
 /**
  * @param object $object
  */
 protected function addObjectConstraints($object)
 {
     $metadata = $this->metadataFactory->getMetadataForClass(get_class($object));
     if ($metadata !== null) {
         /** @var ClassMetadata $classMetadata */
         $classMetadata = $metadata->getRootClassMetadata();
         foreach ($classMetadata->getPropertiesMetadata() as $propertyMetadata) {
             foreach ($propertyMetadata->getConstraints() as $group => $constraints) {
                 $allOf = Assert::create();
                 foreach ($constraints as $constraint) {
                     $allOf->addRules($constraint->getRules());
                 }
                 $this->addConstraint(Assert::create()->attribute($propertyMetadata->getPropertyName(), $allOf), get_class($object), $group);
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Test validate method.
  */
 public function testValidateExplicitConstraints()
 {
     $this->given($validator = $this->createValidator())->then()->boolean($validator->validate('ivannis', Assert::alnum()->noWhitespace()->length(1, 15)))->isTrue()->boolean($validator->validate('ivannis', Assert::alnum()->noWhitespace()->length(1, 15), 'foo'))->isTrue()->boolean($validator->validate('some tests', Assert::alnum()->noWhitespace()->length(1, 15)))->isFalse()->exception(function () use($validator) {
         $validator->validate('value');
     })->isInstanceOf(\RuntimeException::class);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public static function loadValidatorMetadata(ClassMetadata $classMetadata)
 {
     $classMetadata->addPropertyConstraint('email', Assert::email());
 }
Exemplo n.º 6
0
 /**
  * Test create method.
  */
 public function testCreate()
 {
     $this->given($validator = Assert::create())->then()->object($validator)->isInstanceOf(Assert::class);
 }