예제 #1
0
파일: Post.php 프로젝트: cubiche/cubiche
 /**
  * {@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');
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public static function loadValidatorMetadata(ClassMetadata $classMetadata)
 {
     $classMetadata->addPropertyConstraint('email', Assert::email());
     $classMetadata->addPropertyConstraint('password', Assert::stringType()->notBlank());
 }
예제 #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);
             }
         }
     }
 }
예제 #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);
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public static function loadValidatorMetadata(ClassMetadata $classMetadata)
 {
     $classMetadata->addPropertyConstraint('email', Assert::email());
 }
예제 #6
0
 /**
  * Test create method.
  */
 public function testCreate()
 {
     $this->given($validator = Assert::create())->then()->object($validator)->isInstanceOf(Assert::class);
 }