edvakf/php-thrift-mapper
Composer 安装命令:
composer require edvakf/php-thrift-mapper
包简介
Convert a PHP array into an Apache Thrift struct type.
README 文档
README
Convert a PHP array into an Apache Thrift struct type.
What is this?
A Thrift struct;
struct Bonk
{
1: string message,
2: i32 type
}
generates a PHP source like the following.
class Bonk { static $_TSPEC; /** * @var string */ public $message = null; /** * @var int */ public $type = null; public function __construct($vals=null) { if (!isset(self::$_TSPEC)) { self::$_TSPEC = array( 1 => array( 'var' => 'message', 'type' => TType::STRING, ), 2 => array( 'var' => 'type', 'type' => TType::I32, ), ); } if (is_array($vals)) { if (isset($vals['message'])) { $this->message = $vals['message']; } if (isset($vals['type'])) { $this->type = $vals['type']; } } } public function getName() { return 'Bonk'; }
Now, if I want to convert my PHP array to this class, there is no easy way.
Here comes the ThriftMapper
It populates the Thrift object with the PHP array.
$ary = [ "message" => "Hello!", "type" => 123, ]; $bonk = ThriftMapper::map(new Bonk(), $ary); var_dump($bonk);
This code outputs;
object(ThriftTest\Bonk)#19 (2) {
["message"]=>
string(6) "Hello!"
["type"]=>
int(123)
}
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-11