当前位置: 首页>>代码示例>>PHP>>正文


PHP Mapping\ClassMetadata类代码示例

本文整理汇总了PHP中Symfony\Component\Validator\Mapping\ClassMetadata的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata类的具体用法?PHP ClassMetadata怎么用?PHP ClassMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClassMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('title', new NotBlank());
     $metadata->addPropertyConstraint('coment', new NotBlank());
     $metadata->addPropertyConstraint('author', new NotBlank());
     $metadata->addPropertyConstraint('photo', new NotBlank());
 }
开发者ID:skalli350z,项目名称:project-master,代码行数:7,代码来源:AdvertType.php

示例2: loadClassMetadata

 /**
  * {@inheritDoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $annotClass = 'Symfony\\Component\\Validator\\Constraints\\Validation';
     $reflClass = $metadata->getReflectionClass();
     $loaded = false;
     if ($annot = $this->reader->getClassAnnotation($reflClass, $annotClass)) {
         foreach ($annot->constraints as $constraint) {
             $metadata->addConstraint($constraint);
         }
         $loaded = true;
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($annot = $this->reader->getPropertyAnnotation($property, $annotClass)) {
             foreach ($annot->constraints as $constraint) {
                 $metadata->addPropertyConstraint($property->getName(), $constraint);
             }
             $loaded = true;
         }
     }
     foreach ($reflClass->getMethods() as $method) {
         if ($annot = $this->reader->getMethodAnnotation($method, $annotClass)) {
             foreach ($annot->constraints as $constraint) {
                 // TODO: clean this up
                 $name = lcfirst(substr($method->getName(), 0, 3) == 'get' ? substr($method->getName(), 3) : substr($method->getName(), 2));
                 $metadata->addGetterConstraint($name, $constraint);
             }
             $loaded = true;
         }
     }
     return $loaded;
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:34,代码来源:AnnotationLoader.php

示例3: testValidateUniqueness

 /**
  * This is a functinoal test as there is a large integration necessary to get the validator working.
  */
 public function testValidateUniqueness()
 {
     $entityManagerName = "foo";
     $em = $this->createTestEntityManager();
     $schemaTool = new SchemaTool($em);
     $schemaTool->createSchema(array($em->getClassMetadata('Symfony\\Tests\\Bridge\\Doctrine\\Form\\Fixtures\\SingleIdentEntity')));
     $entity1 = new SingleIdentEntity(1, 'Foo');
     $registry = $this->createRegistryMock($entityManagerName, $em);
     $uniqueValidator = new UniqueEntityValidator($registry);
     $metadata = new ClassMetadata('Symfony\\Tests\\Bridge\\Doctrine\\Form\\Fixtures\\SingleIdentEntity');
     $metadata->addConstraint(new UniqueEntity(array('fields' => array('name'), 'em' => $entityManagerName)));
     $metadataFactory = $this->createMetadataFactoryMock($metadata);
     $validatorFactory = $this->createValidatorFactory($uniqueValidator);
     $validator = new Validator($metadataFactory, $validatorFactory);
     $violationsList = $validator->validate($entity1);
     $this->assertEquals(0, $violationsList->count(), "No violations found on entity before it is saved to the database.");
     $em->persist($entity1);
     $em->flush();
     $violationsList = $validator->validate($entity1);
     $this->assertEquals(0, $violationsList->count(), "No violations found on entity after it was saved to the database.");
     $entity2 = new SingleIdentEntity(2, 'Foo');
     $violationsList = $validator->validate($entity2);
     $this->assertEquals(1, $violationsList->count(), "No violations found on entity after it was saved to the database.");
     $violation = $violationsList[0];
     $this->assertEquals('This value is already used.', $violation->getMessage());
     $this->assertEquals('name', $violation->getPropertyPath());
     $this->assertEquals('Foo', $violation->getInvalidValue());
 }
开发者ID:RogerWebb,项目名称:symfony,代码行数:31,代码来源:UniqueValidatorTest.php

示例4: loadValidatorMetadata

 /**
  * Load validator metadata
  * 
  * @param Symfony\Component\Validator\Mapping\ClassMetadata $metadata
  */
 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('created', new Assert\NotBlank());
     $metadata->addPropertyConstraint('title', new Assert\NotBlank());
     $metadata->addPropertyConstraint('title', new Assert\Length(array('min' => 5)));
     $metadata->addPropertyConstraint('body', new Assert\NotBlank());
 }
开发者ID:bsa-git,项目名称:silex-mvc,代码行数:12,代码来源:Post.php

示例5: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('teamA', new Assert\Valid());
     $metadata->addPropertyConstraint('teamB', new Assert\Valid());
     $metadata->addPropertyConstraint('setScores', new Assert\Valid());
     $metadata->addPropertyConstraint('gameTimeLengthInSeconds', new Assert\Range(['min' => 0, 'max' => 65535]));
 }
开发者ID:pdt256,项目名称:vbscraper,代码行数:7,代码来源:Match.php

示例6: loadValidatorMetadata

 /**
  * @param ClassMetadata $metadata
  */
 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('title', new NotBlank(array('message' => 'You must enter a title')));
     $metadata->addPropertyConstraint('blog', new NotBlank(array('message' => 'You must enter little bit blog?')));
     $metadata->addPropertyConstraint('author', new NotBlank(array('message' => 'You must enter your name!')));
     $metadata->addPropertyConstraint('tags', new NotBlank(array('message' => 'You must enter minimal one tag')));
 }
开发者ID:hrobben,项目名称:sf2_blog,代码行数:10,代码来源:Blog.php

示例7: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('name', new NotBlank());
     $metadata->addPropertyConstraint('email', new Email());
     $metadata->addPropertyConstraint('short_name', new NotBlank());
     $metadata->addPropertyConstraint('address', new NotBlank());
 }
开发者ID:aestene,项目名称:webpage,代码行数:7,代码来源:Department.php

示例8: testLoadClassMetadataAndMerge

 /**
  * Test MetaData merge with parent annotation.
  */
 public function testLoadClassMetadataAndMerge()
 {
     $loader = new AnnotationLoader();
     // Load Parent MetaData
     $parent_metadata = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\EntityParent');
     $loader->loadClassMetadata($parent_metadata);
     $metadata = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\Entity');
     // Merge parent metaData.
     $metadata->mergeConstraints($parent_metadata);
     $loader->loadClassMetadata($metadata);
     $expected_parent = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\EntityParent');
     $expected_parent->addPropertyConstraint('other', new NotNull());
     $expected_parent->getReflectionClass();
     $expected = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\Entity');
     $expected->mergeConstraints($expected_parent);
     $expected->setGroupSequence(array('Foo', 'Entity'));
     $expected->addConstraint(new NotNull());
     $expected->addConstraint(new ConstraintA());
     $expected->addConstraint(new Min(3));
     $expected->addConstraint(new Choice(array('A', 'B')));
     $expected->addConstraint(new All(array(new NotNull(), new Min(3))));
     $expected->addConstraint(new All(array('constraints' => array(new NotNull(), new Min(3)))));
     $expected->addConstraint(new Collection(array('fields' => array('foo' => array(new NotNull(), new Min(3)), 'bar' => new Min(5)))));
     $expected->addPropertyConstraint('firstName', new Choice(array('message' => 'Must be one of %choices%', 'choices' => array('A', 'B'))));
     $expected->addGetterConstraint('lastName', new NotNull());
     // load reflection class so that the comparison passes
     $expected->getReflectionClass();
     $this->assertEquals($expected, $metadata);
 }
开发者ID:notbrain,项目名称:symfony,代码行数:32,代码来源:AnnotationLoaderTest.php

示例9: loadValidatorMetadata

 /**
  * Valorizes model validation metadata
  *
  * @return void
  */
 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addGetterConstraint('title', new Assert\NotBlank());
     $metadata->addGetterConstraint('content', new Assert\NotBlank());
     $metadata->addGetterConstraint('image', new Assert\NotBlank());
     $metadata->addGetterConstraint('image', new Assert\Image(['maxWidth' => 400]));
 }
开发者ID:neemzy,项目名称:patchwork,代码行数:12,代码来源:Pizza.php

示例10: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('name', new NotBlank());
     $metadata->addPropertyConstraint('name', new Length(['min' => 5, 'max' => 10, 'minMessage' => 'Your name must be at least {{ limit }} characters long', 'maxMessage' => 'Your name cannot be longer than {{ limit }} characters']));
     $metadata->addPropertyConstraint('password', new NotBlank());
     $metadata->addPropertyConstraint('password', new Length(['min' => 5, 'max' => 10, 'minMessage' => 'Your password must be at least {{ limit }} characters long', 'maxMessage' => 'Your password cannot be longer than {{ limit }} characters']));
 }
开发者ID:romanveliev,项目名称:forms,代码行数:7,代码来源:Users.php

示例11: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('name', new NotBlank());
     $metadata->addPropertyConstraint('email', new NotBlank());
     $metadata->addPropertyConstraint('email', new Email(array('message' => 'Please provide a valid email address.')));
     $metadata->addPropertyConstraint('subject', new NotBlank());
 }
开发者ID:nickdunn2,项目名称:nickblog,代码行数:7,代码来源:Enquiry.php

示例12: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('name', new Constraints\NotBlank());
     $metadata->addPropertyConstraint('name', new Constraints\MinLength(2));
     $metadata->addPropertyConstraint('username', new Constraints\NotBlank());
     $metadata->addPropertyConstraint('username', new Constraints\MinLength(2));
 }
开发者ID:robzienert,项目名称:symfony2bundles,代码行数:7,代码来源:Repo.php

示例13: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('login', new NotBlank());
     $metadata->addPropertyConstraint('login', new Length(array('min' => 6, 'max' => 40)));
     $metadata->addPropertyConstraint('email', new Length(array('min' => 2, 'max' => 100)));
     $metadata->addPropertyConstraint('email', new Email());
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:7,代码来源:PasswordRecoveryRequestIntent.php

示例14: loadValidatorMetadata

 public static function loadValidatorMetadata(ClassMetadata $metadata)
 {
     $metadata->addPropertyConstraint('title', new NotBlank(array('message' => 'You must enter a title')));
     $metadata->addPropertyConstraint('author', new NotBlank(array('message' => 'You must enter a author')));
     $metadata->addPropertyConstraint('blog', new NotBlank(array('message' => 'You must enter the text')));
     $metadata->addPropertyConstraint('blog', new Length(array('min' => 50)));
 }
开发者ID:xooi,项目名称:blogTutorial,代码行数:7,代码来源:Blog.php

示例15: loadClassMetadata

 public function loadClassMetadata(ClassMetadata $metadata)
 {
     /** @var \ReflectionClass $refClass */
     $refClass = $metadata->getReflectionClass();
     $baseClass = $this->classNameProvider->getBaseClass($refClass->name);
     if (!$baseClass) {
         return false;
     }
     if (!array_key_exists($baseClass, $this->config->models)) {
         return false;
     }
     foreach ($this->config->models[$baseClass]->properties as $propName => $property) {
         if ($property->validation) {
             if (!is_array($property->validation)) {
                 throw new \LogicException("Configuration error: {$baseClass}:{$propName}:validation must be array");
             }
             foreach ($property->validation as $index => $rule) {
                 if (!is_array($rule) or count($rule) != 1) {
                     throw new \LogicException("Configuration error: {$baseClass}:{$propName}:validation: rule #{$index} must be array of 1 element which contains array");
                 }
                 $constraintClass = array_keys($rule)[0];
                 $constraintOptions = $rule[$constraintClass];
                 $fullClass = $this->getFullConstraintClass($constraintClass);
                 $metadata->addGetterConstraint($propName, new $fullClass($constraintOptions));
             }
         }
     }
     return true;
 }
开发者ID:miknatr,项目名称:grace,代码行数:29,代码来源:GraceModelValidationLoader.php


注:本文中的Symfony\Component\Validator\Mapping\ClassMetadata类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。