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


PHP ClassMetadata::getReflectionClass方法代码示例

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


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

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

示例6: loadClassMetadata

 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $class_name = $metadata->getReflectionClass()->getName();
     if ($this->loader->hasAdminClass($class_name)) {
         $admin = $this->loader->getAdminByClass($class_name);
         $admin->loadValidatorMetadata($metadata);
         return true;
     }
 }
开发者ID:symforce,项目名称:symforce-admin,代码行数:9,代码来源:ValidatorLoader.php

示例7: loadClassMetadata

 /**
  * {@inheritDoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     if ($reflClass->hasMethod($this->methodName)) {
         $reflMethod = $reflClass->getMethod($this->methodName);
         if (!$reflMethod->isStatic()) {
             throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->getName(), $this->methodName));
         }
         $reflMethod->invoke(null, $metadata);
         return true;
     }
     return false;
 }
开发者ID:janmarek,项目名称:Neuron,代码行数:16,代码来源:StaticMethodLoader.php

示例8: loadClassMetadata

 /**
  * {@inheritDoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     $className = $reflClass->getName();
     $loaded = false;
     foreach ($this->reader->getClassAnnotations($reflClass) as $constraint) {
         if ($constraint instanceof Set) {
             foreach ($constraint->constraints as $constraint) {
                 $metadata->addConstraint($constraint);
             }
         } elseif ($constraint instanceof GroupSequence) {
             $metadata->setGroupSequence($constraint->groups);
         } elseif ($constraint instanceof Constraint) {
             $metadata->addConstraint($constraint);
         }
         $loaded = true;
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($property->getDeclaringClass()->getName() == $className) {
             foreach ($this->reader->getPropertyAnnotations($property) as $constraint) {
                 if ($constraint instanceof Set) {
                     foreach ($constraint->constraints as $constraint) {
                         $metadata->addPropertyConstraint($property->getName(), $constraint);
                     }
                 } elseif ($constraint instanceof Constraint) {
                     $metadata->addPropertyConstraint($property->getName(), $constraint);
                 }
                 $loaded = true;
             }
         }
     }
     foreach ($reflClass->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() == $className) {
             foreach ($this->reader->getMethodAnnotations($method) as $constraint) {
                 // TODO: clean this up
                 $name = lcfirst(substr($method->getName(), 0, 3) == 'get' ? substr($method->getName(), 3) : substr($method->getName(), 2));
                 if ($constraint instanceof Set) {
                     foreach ($constraint->constraints as $constraint) {
                         $metadata->addGetterConstraint($name, $constraint);
                     }
                 } elseif ($constraint instanceof Constraint) {
                     $metadata->addGetterConstraint($name, $constraint);
                 }
                 $loaded = true;
             }
         }
     }
     return $loaded;
 }
开发者ID:notbrain,项目名称:symfony,代码行数:52,代码来源:AnnotationLoader.php

示例9: loadClassMetadata

 /**
  * {@inheritDoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     /** @var \ReflectionClass $reflClass */
     $reflClass = $metadata->getReflectionClass();
     if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
         $reflMethod = $reflClass->getMethod($this->methodName);
         if (!$reflMethod->isStatic()) {
             throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->name, $this->methodName));
         }
         if ($reflMethod->getDeclaringClass()->name != $reflClass->name) {
             return false;
         }
         $reflMethod->invoke(null, $metadata);
         return true;
     }
     return false;
 }
开发者ID:artz20,项目名称:Tv-shows-zone,代码行数:20,代码来源:StaticMethodLoader.php

示例10: loadClassMetadata

 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     $className = $reflClass->name;
     $success = false;
     foreach ($this->reader->getClassAnnotations($reflClass) as $constraint) {
         if ($constraint instanceof GroupSequence) {
             $metadata->setGroupSequence($constraint->groups);
         } elseif ($constraint instanceof GroupSequenceProvider) {
             $metadata->setGroupSequenceProvider(true);
         } elseif ($constraint instanceof Constraint) {
             $metadata->addConstraint($constraint);
         }
         $success = true;
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($property->getDeclaringClass()->name == $className) {
             foreach ($this->reader->getPropertyAnnotations($property) as $constraint) {
                 if ($constraint instanceof Constraint) {
                     $metadata->addPropertyConstraint($property->name, $constraint);
                 }
                 $success = true;
             }
         }
     }
     foreach ($reflClass->getMethods() as $method) {
         if ($method->getDeclaringClass()->name == $className) {
             foreach ($this->reader->getMethodAnnotations($method) as $constraint) {
                 if ($constraint instanceof Callback) {
                     $constraint->callback = $method->getName();
                     $constraint->methods = null;
                     $metadata->addConstraint($constraint);
                 } elseif ($constraint instanceof Constraint) {
                     if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) {
                         $metadata->addGetterConstraint(lcfirst($matches[2]), $constraint);
                     } else {
                         throw new MappingException(sprintf('The constraint on "%s::%s" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name));
                     }
                 }
                 $success = true;
             }
         }
     }
     return $success;
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:48,代码来源:AnnotationLoader.php

示例11: testLoadClassMetadata

 public function testLoadClassMetadata()
 {
     $loader = new AnnotationLoader();
     $metadata = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\Entity');
     $loader->loadClassMetadata($metadata);
     $expected = new ClassMetadata('Symfony\\Tests\\Component\\Validator\\Fixtures\\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:netixpro,项目名称:symfony,代码行数:19,代码来源:AnnotationLoaderTest.php

示例12: testLoadGroupSequenceProviderAnnotation

 public function testLoadGroupSequenceProviderAnnotation()
 {
     $loader = new AnnotationLoader(new AnnotationReader());
     $metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\GroupSequenceProviderEntity');
     $loader->loadClassMetadata($metadata);
     $expected = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\GroupSequenceProviderEntity');
     $expected->setGroupSequenceProvider(true);
     $expected->getReflectionClass();
     $this->assertEquals($expected, $metadata);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:10,代码来源:AnnotationLoaderTest.php


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