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


PHP ClassMetadata::mergeConstraints方法代码示例

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


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

示例1: getClassMetadata

 public function getClassMetadata($class)
 {
     $class = ltrim($class, '\\');
     if (!isset($this->loadedClasses[$class])) {
         if ($this->cache !== null && $this->cache->has($class)) {
             $this->loadedClasses[$class] = $this->cache->read($class);
         } else {
             $metadata = new ClassMetadata($class);
             // Include constraints from the parent class
             if ($parent = $metadata->getReflectionClass()->getParentClass()) {
                 $metadata->mergeConstraints($this->getClassMetadata($parent->getName()));
             }
             // Include constraints from all implemented interfaces
             foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
                 $metadata->mergeConstraints($this->getClassMetadata($interface->getName()));
             }
             $this->loader->loadClassMetadata($metadata);
             $this->loadedClasses[$class] = $metadata;
             if ($this->cache !== null) {
                 $this->cache->write($metadata);
             }
         }
     }
     return $this->loadedClasses[$class];
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:25,代码来源:ClassMetadataFactory.php

示例2: getMetadataFor

 /**
  * {@inheritdoc}
  */
 public function getMetadataFor($value)
 {
     if (!is_object($value) && !is_string($value)) {
         throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
     }
     $class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
     if (isset($this->loadedClasses[$class])) {
         return $this->loadedClasses[$class];
     }
     if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) {
         return $this->loadedClasses[$class];
     }
     if (!class_exists($class) && !interface_exists($class)) {
         throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
     }
     $metadata = new ClassMetadata($class);
     // Include constraints from the parent class
     if ($parent = $metadata->getReflectionClass()->getParentClass()) {
         $metadata->mergeConstraints($this->getMetadataFor($parent->name));
     }
     // Include constraints from all implemented interfaces
     foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
         if ('Symfony\\Component\\Validator\\GroupSequenceProviderInterface' === $interface->name) {
             continue;
         }
         $metadata->mergeConstraints($this->getMetadataFor($interface->name));
     }
     if (null !== $this->loader) {
         $this->loader->loadClassMetadata($metadata);
     }
     if (null !== $this->cache) {
         $this->cache->write($metadata);
     }
     return $this->loadedClasses[$class] = $metadata;
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:38,代码来源:ClassMetadataFactory.php

示例3: getClassMetadata

 public function getClassMetadata($class)
 {
     $class = ltrim($class, '\\');
     if (isset($this->loadedClasses[$class])) {
         return $this->loadedClasses[$class];
     }
     if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) {
         return $this->loadedClasses[$class];
     }
     $metadata = new ClassMetadata($class);
     // Include constraints from the parent class
     if ($parent = $metadata->getReflectionClass()->getParentClass()) {
         $metadata->mergeConstraints($this->getClassMetadata($parent->name));
     }
     // Include constraints from all implemented interfaces
     foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
         if ('Symfony\\Component\\Validator\\GroupSequenceProviderInterface' === $interface->name) {
             continue;
         }
         $metadata->mergeConstraints($this->getClassMetadata($interface->name));
     }
     if (null !== $this->loader) {
         $this->loader->loadClassMetadata($metadata);
     }
     if (null !== $this->cache) {
         $this->cache->write($metadata);
     }
     return $this->loadedClasses[$class] = $metadata;
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:29,代码来源:ClassMetadataFactory.php

示例4: 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


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