コード例 #1
0
 protected function createProperty(Tag $tag)
 {
     $name = trim($tag->getVariableName(), '$');
     $prop = new ClassProperty();
     $prop->name = $name;
     $prop->setType($this->getFQCN($tag->getType()));
     return $prop;
 }
コード例 #2
0
 /**
  * Adds type information to the structure.
  *
  * @param string[] $types Array with types in any format; will be transformed
  *  to FQCN.
  *
  * @todo Move this method to a better spot with namespace and alias access
  *  (together with namespace and alias stuff).
  *
  * @return void
  */
 public function setTypes($types)
 {
     foreach ($types as $type) {
         if ($type == '') {
             continue;
         }
         $type = trim($this->expandType($type));
         // strip ampersands
         $name = str_replace('&', '', $type);
         $type_object = $this->xml->addChild('type', $name);
         // register whether this variable is by reference by checking
         // the first and last character
         $type_object['by_reference'] = substr($type, 0, 1) === '&' || substr($type, -1) === '&' ? 'true' : 'false';
     }
     $this->xml['type'] = $this->expandType($this->tag->getType());
 }
コード例 #3
0
ファイル: TypeFinder.php プロジェクト: noikiy/php-to-zephir
 /**
  * @param string $actualNamespace
  * @param Tag    $tag
  *
  * @return string
  */
 private function findType(Tag $tag, $actualNamespace, array $use, array $classes)
 {
     $rawType = $tag->getType();
     if ($rawType === 'integer') {
         $rawType = 'int';
     }
     $primitiveTypes = array('string', 'int', 'integer', 'float', 'double', 'bool', 'boolean', 'array', 'null', 'callable', 'scalar', 'void', 'object');
     $excludedType = array('mixed', 'callable', 'callable[]', 'scalar', 'scalar[]', 'void', 'object', 'self', 'resource', 'true');
     if (in_array($rawType, $excludedType) === true || count(explode('|', $rawType)) !== 1) {
         return array('value' => '', 'isClass' => false);
     }
     $arrayOfPrimitiveTypes = array_map(function ($val) {
         return $val . '[]';
     }, $primitiveTypes);
     if (preg_match("/^[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*\$/", $rawType) === 0) {
         // this is a typo
         $this->logger->log(sprintf('Type "%s" does not exist in docblock', $rawType));
         $type = array('value' => '', 'isClass' => false);
     } elseif (in_array(strtolower($rawType), $primitiveTypes)) {
         $type = array('value' => strtolower($rawType), 'isClass' => false);
     } elseif (in_array(strtolower($rawType), $arrayOfPrimitiveTypes)) {
         $type = array('value' => strtolower($rawType), 'isClass' => false);
     } else {
         // considered as class
         $type = array('value' => $rawType, 'isClass' => true);
     }
     return $type;
 }
コード例 #4
0
 /**
  * Gets the type of the parameter or null if it is not defined.
  *
  * @param Tag $tag
  *
  * @return array
  */
 private function getType(Tag $tag) : array
 {
     $type = $tag->getType();
     if ($type instanceof Compound) {
         if ($type->has(2)) {
             // Several types, cannot guess
             return [];
         }
         $type0 = $type->get(0);
         $type1 = $type->get(1);
         if ($type0 instanceof Null_ && $type1 instanceof Null_) {
             // No type hint
             return [];
         }
         if (!$type0 instanceof Null_ && $type1 instanceof Null_) {
             return [$type0->__toString(), true];
         }
         if (!$type1 instanceof Null_ && $type0 instanceof Null_) {
             return [$type1->__toString(), true];
         }
         // Mixed types, cannot guess
         return [];
     }
     return [$type->__toString(), false];
 }
コード例 #5
0
 /**
  * Gets the type of the parameter or an empty array if it is not defined.
  *
  * @param Tag $tag
  *
  * @return array
  */
 private function getTypeFromTag(Tag $tag) : array
 {
     $type = $tag->getType();
     if (null === $type) {
         // No type specified
         return [];
     }
     if ($type instanceof Compound) {
         if ($type->has(2)) {
             // Several types, cannot guess
             return [];
         }
         $type0 = $type->get(0);
         $type1 = $type->get(1);
         if ($type0 instanceof Null_ && $type1 instanceof Null_) {
             // No type hint
             return [];
         }
         if (!$type0 instanceof Null_ && $type1 instanceof Null_) {
             return [$type0->__toString(), true];
         }
         if (!$type1 instanceof Null_ && $type0 instanceof Null_) {
             return [$type1->__toString(), true];
         }
         // Mixed types, cannot guess
         return [];
     }
     if ($type instanceof Array_) {
         // May contain more specific type declarations, but we only
         // convert to pure arrays
         return ['array', false];
     }
     return [$type->__toString(), false];
 }