Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $GLOBALS['THRIFT_ROOT'] = '/usr/lib/php';
- require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
- require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TJSONProtocol.php';
- require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
- #require_once $GLOBALS['THRIFT_ROOT'].'/transport/THttpClient.php';
- require_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php';
- require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
- require_once '/var/www/html/tjs/web/gen-php/ThriftTest/ThriftTest.php';
- /****
- * stuff for binary tests
- ***/
- require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
- require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
- class ThriftTestHandler
- {
- function testVoid() {
- }
- function testString($s) {
- return $s;
- }
- function testDouble($d) {
- return $d;
- }
- function testByte($b) {
- return $b;
- }
- function testI32($i) {
- return $i;
- }
- function testI64($i) {
- return $i;
- }
- function testStruct($s) {
- return $s;
- }
- function testNest($s) {
- return $s;
- }
- function testMap($m) {
- return $m;
- }
- function testStringMap($m) {
- return $m;
- }
- function testSet($s) {
- return $s;
- }
- function testList($l) {
- return $l;
- }
- function testEnum($e) {
- return $e;
- }
- function testTypeDef($t) {
- return $t;
- }
- function testMapMap($m) {
- # map<i32,map<i32,i32>>
- $expectedResult = array(
- "4" => array(
- "1" => 1,
- "2" => 2,
- "3" => 3,
- "4" => 4
- ),
- "-4" => array(
- "-4" => -4,
- "-3" => -3,
- "-2" => -2,
- "-1" => -1
- )
- );
- return $expectedResult;
- }
- function testException($m) {
- switch ($m) {
- case 'Xception':
- case 'ApplicationException':
- throw new ThriftTest_Xception(
- array(
- 'errorCode' => 1001,
- 'message' => "$m"
- )
- );
- break;
- default:
- break;
- }
- }
- function testInsanity() {
- $xtruct1 = new ThriftTest_Xtruct(
- array(
- 'string_thing' => 'Goodbye4',
- 'byte_thing' => 4,
- 'i32_thing' => 4,
- 'i64_thing' => 4
- )
- );
- $xtruct2 = new ThriftTest_Xtruct(
- array(
- 'string_thing' => 'Hello2',
- 'byte_thing' =>2,
- 'i32_thing' => 2,
- 'i64_thing' => 2
- )
- );
- $userMap = array(
- Numberz::FIVE => 5,
- Numberz::EIGHT => 8
- );
- $insanity2 = new ThriftTest_Insanity(
- array(
- 'userMap' => $userMap,
- 'xtructs' => array($xtruct1,$xtruct2)
- )
- );
- $insanity3 = $insanity2;
- $insanity6 = new ThriftTest_Insanity(
- array(
- 'userMap' => null,
- 'xtructs' => null
- )
- );
- return array(
- "1" => array(
- Numberz::TWO => $insanity2,
- Numberz::THREE => $insanity3
- ),
- "2" => array(
- Numberz::SIX => $insanity6
- )
- );
- }
- }
- $handler = new ThriftTestHandler();
- $processor = new ThriftTestProcessor($handler);
- $tinput = new TPhpStream(TPhpStream::MODE_R);
- $toutput = new TPhpStream(TPhpStream::MODE_W);
- $tinput->open();
- $toutput->open();
- $pinput = new TJSONProtocol($tinput);
- $poutput = new TJSONProtocol($toutput);
- /***
- * for binary tests
- */
- //$pinput = new TBinaryProtocol($tinput);
- //$poutput = new TBinaryProtocol($toutput);
- $processor->process($pinput,$poutput);
Advertisement
Add Comment
Please, Sign In to add comment