2017 © Pedro Peláez
 

library php-thrift-mapper

Convert a PHP array into an Apache Thrift struct type.

image

edvakf/php-thrift-mapper

Convert a PHP array into an Apache Thrift struct type.

  • Thursday, September 10, 2015
  • by edvakf
  • Repository
  • 1 Watchers
  • 2 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP-Thrift-Mapper

Convert a PHP array into an Apache Thrift struct type., (*1)

Build Status Coverage Status, (*2)

What is this?

A Thrift struct;, (*3)

struct Bonk
{
  1: string message,
  2: i32 type
}

generates a PHP source like the following., (*4)

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., (*5)

Here comes the ThriftMapper

It populates the Thrift object with the PHP array., (*6)

$ary = [
  "message" => "Hello!",
  "type" => 123,
];

$bonk = ThriftMapper::map(new Bonk(), $ary);

var_dump($bonk);

This code outputs;, (*7)

object(ThriftTest\Bonk)#19 (2) {
  ["message"]=>
  string(6) "Hello!"
  ["type"]=>
  int(123)
}

The Versions

10/09 2015

dev-master

9999999-dev

Convert a PHP array into an Apache Thrift struct type.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Atsushi Takayama