當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。