Protobuf\Field::getPhpType PHP Method

getPhpType() public static method

public static getPhpType ( integer $type ) : string
$type integer
return string
    public static function getPhpType($type)
    {
        switch ($type) {
            case self::TYPE_DOUBLE:
            case self::TYPE_FLOAT:
                return 'float';
            case self::TYPE_INT64:
            case self::TYPE_UINT64:
            case self::TYPE_INT32:
            case self::TYPE_FIXED64:
            case self::TYPE_FIXED32:
            case self::TYPE_UINT32:
            case self::TYPE_SFIXED32:
            case self::TYPE_SFIXED64:
            case self::TYPE_SINT32:
            case self::TYPE_SINT64:
                return 'int';
            case self::TYPE_BOOL:
                return 'bool';
            case self::TYPE_STRING:
                return 'string';
            case self::TYPE_BYTES:
                return '\\Protobuf\\Stream';
            default:
                return null;
        }
    }

Usage Example

 /**
  * @param \google\protobuf\FieldDescriptorProto $field
  *
  * @return string
  */
 protected function getDoctype(FieldDescriptorProto $field)
 {
     $fieldType = $field->getType()->value();
     $phpType = Field::getPhpType($fieldType);
     $refTypes = [Type::TYPE_ENUM_VALUE => true, Type::TYPE_MESSAGE_VALUE => true];
     if (isset($refTypes[$fieldType])) {
         $typeName = $field->getTypeName();
         $refEntity = $this->getEntity($typeName);
         return $refEntity->getNamespacedName();
     }
     return $phpType ?: 'mixed';
 }
All Usage Examples Of Protobuf\Field::getPhpType