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


PHP ClassType::getAnnotations方法代码示例

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


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

示例1: __construct

 /**
  * Parses class annotation and build metadata object
  * 
  * @param Nette\Reflection\ClassType $reflection 
  * @throws vBuilder\InvalidAnnotationException if any annotation is missing or bad formed
  */
 public function __construct(Nette\Reflection\ClassType $reflection)
 {
     // Nazev tabulky
     $annotations = $reflection->getAnnotations();
     if (isset($annotations['Table']) && isset($annotations['Table'][0]['name'])) {
         $this->tableName = $annotations['Table'][0]['name'];
     }
     // Entitni chovani
     if (isset($annotations['Behavior'])) {
         foreach ($annotations['Behavior'] as $curr) {
             if (!is_array($curr) && !$curr instanceof \Traversable) {
                 $this->behaviors[$curr] = array();
                 continue;
             }
             $curr = (array) $curr;
             $this->behaviors[array_shift($curr)] = $curr;
         }
     }
     // Sloupecky
     if (isset($annotations['Column'])) {
         foreach ($annotations['Column'] as $curr) {
             // Prazdne definice
             if ($curr === true) {
                 continue;
             }
             if (!is_array($curr) && !$curr instanceof \Traversable) {
                 $this->fields[$curr] = array();
                 continue;
             }
             $curr = (array) $curr;
             $name = array_shift($curr);
             $this->fields[$name] = array();
             foreach ($curr as $k => $v) {
                 if (is_numeric($k)) {
                     $this->fields[$name][$v] = true;
                 } else {
                     $this->fields[$name][$k] = $v;
                 }
             }
             if (isset($this->fields[$name]['id']) || isset($this->fields[$name]['pk'])) {
                 $this->idFields[] = $name;
             }
         }
     }
 }
开发者ID:vbuilder,项目名称:framework,代码行数:51,代码来源:AnnotationMetadata.php

示例2: getRepositoryList

 protected function getRepositoryList($modelClass)
 {
     $modelReflection = new ClassType($modelClass);
     $builder = $this->getContainerBuilder();
     $builder->addDependency($modelReflection->getFileName());
     $repositories = [];
     foreach ($modelReflection->getAnnotations() as $key => $annotations) {
         if ($key !== 'property-read') {
             continue;
         }
         foreach ($annotations as $annotation) {
             list($class, $name) = preg_split('#\\s+#', $annotation);
             $class = AnnotationsParser::expandClassName($class, $modelReflection);
             if (!class_exists($class)) {
                 throw new RuntimeException("Repository '{$class}' does not exist.");
             }
             $repositories[ltrim($name, '$')] = $class;
         }
     }
     return $repositories;
 }
开发者ID:Vyki,项目名称:orm,代码行数:21,代码来源:OrmExtension.php

示例3: getRepositoryList

 protected function getRepositoryList($modelClass)
 {
     $modelReflection = new ClassType($modelClass);
     $builder = $this->getContainerBuilder();
     $builder->addDependency($modelReflection->getFileName());
     $repositories = [];
     foreach ($modelReflection->getAnnotations() as $key => $annotations) {
         if ($key !== 'property-read') {
             continue;
         }
         foreach ($annotations as $annotation) {
             list($class, $name) = preg_split('#\\s+#', $annotation);
             $class = AnnotationsParser::expandClassName($class, $modelReflection);
             if (!class_exists($class)) {
                 throw new RuntimeException("Class repository '{$class}' does not exist.");
             }
             $repositories[] = ['name' => ltrim($name, '$'), 'serviceName' => $this->prefix('repositories.' . ltrim($name, '$')), 'class' => $class, 'entities' => call_user_func([$class, 'getEntityClassNames'])];
         }
     }
     return $repositories;
 }
开发者ID:Zarganwar,项目名称:orm,代码行数:21,代码来源:OrmExtension.php

示例4: parseAnnotations

 protected function parseAnnotations(ClassType $reflection)
 {
     foreach ($reflection->getAnnotations() as $annotation => $values) {
         if ($annotation === 'property') {
             $access = PropertyMetadata::READWRITE;
         } elseif ($annotation === 'property-read') {
             $access = PropertyMetadata::READ;
         } else {
             continue;
         }
         foreach ($values as $value) {
             $splitted = preg_split('#\\s+#', $value, 3);
             if (count($splitted) < 2 || $splitted[1][0] !== '$') {
                 throw new InvalidArgumentException("Annotation syntax error '{$value}'.");
             }
             $name = substr($splitted[1], 1);
             $types = $this->parseAnnotationTypes($splitted[0], $reflection);
             if ($access === PropertyMetadata::READWRITE) {
                 $this->storageProperties[$name] = TRUE;
             }
             $this->parseAnnotationValue($name, $types, $access, isset($splitted[2]) ? $splitted[2] : NULL);
         }
     }
 }
开发者ID:Zarganwar,项目名称:orm,代码行数:24,代码来源:AnnotationParser.php

示例5: parseAnnotations

 protected function parseAnnotations(ClassType $reflection)
 {
     foreach ($reflection->getAnnotations() as $annotation => $values) {
         if ($annotation === 'property') {
             $isReadonly = false;
         } elseif ($annotation === 'property-read') {
             $isReadonly = true;
         } else {
             continue;
         }
         foreach ($values as $value) {
             $splitted = preg_split('#\\s+#', $value, 3);
             if (count($splitted) < 2 || $splitted[1][0] !== '$') {
                 throw new InvalidArgumentException("Annotation syntax error '{$value}'.");
             }
             $property = new PropertyMetadata();
             $property->name = substr($splitted[1], 1);
             $property->isReadonly = $isReadonly;
             $this->metadata->setProperty($property->name, $property);
             $this->parseAnnotationTypes($property, $splitted[0]);
             $this->parseAnnotationValue($property, isset($splitted[2]) ? $splitted[2] : null);
         }
     }
 }
开发者ID:nextras,项目名称:orm,代码行数:24,代码来源:MetadataParser.php

示例6: getAnnotations

 /**
  * @return array|\Nette\Reflection\IAnnotation[]
  */
 public function getAnnotations()
 {
     if ($this->annotations == NULL) {
         $reflection = new ClassType(get_called_class());
         $annotations = $reflection->getAnnotations();
         $this->annotations = $annotations;
     }
     return $this->annotations;
 }
开发者ID:peterzadori,项目名称:movi,代码行数:12,代码来源:Repository.php

示例7: getAnnotatedProperties

 /**
  * Parse class and returns names and target classes of annotated properties
  * @param $className
  * @return mixed
  * @throws RestException
  */
 public function getAnnotatedProperties($className)
 {
     if (!isset($this->classProperties[$className])) {
         $this->classProperties[$className] = array();
         $ref = new ClassType($className);
         if ($ref->isAbstract() or $ref->isInterface()) {
             throw new RestException("Class can not be either abstract nor interface");
         }
         $ann = $ref->getAnnotations();
         $parents = class_parents($className);
         $parents[$className] = $className;
         if ($className != DataHash::class and (!$parents or !in_array(DataHash::class, $parents))) {
             throw RestException::notInheritedForm($className, DataHash::class);
         }
         $this->parseProperties($ref, $ann, 'property');
         $this->parseProperties($ref, $ann, 'property-read');
     }
     return $this->classProperties[$className];
 }
开发者ID:pipaslot,项目名称:rest,代码行数:25,代码来源:ResultMapper.php

示例8: getMetadata

 /**
  * @return mixed[][]
  */
 private static function getMetadata()
 {
     $className = get_called_class();
     if (!isset(self::$metadata[$className])) {
         self::$metadata[$className] = array();
         $classReflection = new ClassType($className);
         $annotations = $classReflection->getAnnotations();
         self::$metadata[$className] += self::parseMetadataFromAnnotation($annotations, 'property', true, true);
         self::$metadata[$className] += self::parseMetadataFromAnnotation($annotations, 'property-read', true, false);
         self::$metadata[$className] += self::parseMetadataFromAnnotation($annotations, 'property-write', false, true);
     }
     return self::$metadata[$className];
 }
开发者ID:venne,项目名称:data-transfer,代码行数:16,代码来源:DataTransferObject.php


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