blob: 5fa57f03e276ba8fed5f2a07b58604ea6694b542 [file] [log] [blame]
Mark Slee6e536442006-06-30 18:28:50 +00001<?php
2
Mark Slee99e2b262006-10-10 01:42:29 +00003/**
Mark Slee1ecb1b02007-02-22 01:01:10 +00004 * Data types that can be sent via Thrift
Mark Slee99e2b262006-10-10 01:42:29 +00005 */
Mark Slee1ecb1b02007-02-22 01:01:10 +00006class TType {
7 const STOP = 0;
8 const VOID = 1;
9 const BOOL = 2;
10 const BYTE = 3;
11 const I08 = 3;
12 const DOUBLE = 4;
13 const I16 = 6;
14 const I32 = 8;
15 const I64 = 10;
16 const STRING = 11;
17 const UTF7 = 11;
18 const STRUCT = 12;
19 const MAP = 13;
20 const SET = 14;
21 const LST = 15; // N.B. cannot use LIST keyword in PHP!
22 const UTF8 = 16;
23 const UTF16 = 17;
Mark Sleecfc01932006-09-01 22:18:16 +000024}
Mark Slee1ecb1b02007-02-22 01:01:10 +000025
26/**
27 * Message types for RPC
28 */
29class TMessageType {
30 const CALL = 1;
31 const REPLY = 2;
Mark Sleed395d572007-02-27 01:16:55 +000032 const EXCEPTION = 3;
Mark Slee1ecb1b02007-02-22 01:01:10 +000033}
Mark Slee6e536442006-06-30 18:28:50 +000034
Mark Sleedac78562007-02-21 07:35:03 +000035class TException extends Exception {
36 function __construct($message=null, $code=0) {
37 parent::__construct($message, $code);
38 }
39}
40
41class TApplicationException extends TException {
42
43 const UNKNOWN = 0;
44 const UNKNOWN_METHOD = 1;
45 const INVALID_MESSAGE_TYPE = 2;
46 const WRONG_METHOD_NAME = 3;
47 const BAD_SEQUENCE_ID = 4;
48 const MISSING_RESULT = 5;
49
50 function __construct($message=null, $code=0) {
51 parent::__construct($message, $code);
52 }
53
54 public function read($input) {
55 $xfer = 0;
56 $fname = null;
57 $ftype = 0;
58 $fid = 0;
59 $xfer += $input->readStructBegin($fname);
60 while (true)
61 {
62 $xfer += $input->readFieldBegin($fname, $ftype, $fid);
63 if ($ftype == TType::STOP) {
64 break;
65 }
66 switch ($fid)
67 {
68 case 1:
69 if ($ftype == TType::STRING) {
70 $xfer += $input->readString($this->message);
71 } else {
72 $xfer += $input->skip($ftype);
73 }
74 break;
75 case 2:
76 if ($ftype == TType::I32) {
77 $xfer += $input->readI32($this->code);
78 } else {
79 $xfer += $input->skip($ftype);
80 }
81 break;
82 default:
83 $xfer += $input->skip($ftype);
84 break;
85 }
86 $xfer += $input->readFieldEnd();
87 }
88 $xfer += $input->readStructEnd();
89 return $xfer;
90 }
91
92 public function write($output) {
93 $xfer = 0;
94 $xfer += $output->writeStructBegin('TApplicationException');
95 if ($this->getMessage()) {
96 $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
97 $xfer += $output->writeString($this->getMessage());
98 $xfer += $output->writeFieldEnd();
99 }
Mark Slee0af62d12007-02-27 22:11:09 +0000100 if ($this->getCode()) {
Mark Sleedac78562007-02-21 07:35:03 +0000101 $xfer += $output->writeFieldBegin('type', TType::I32, 2);
102 $xfer += $output->writeI32($this->getCode());
103 $xfer += $output->writeFieldEnd();
104 }
105 $xfer += $output->writeFieldStop();
106 $xfer += $output->writeStructEnd();
107 return $xfer;
108 }
109}
110
Mark Slee1ecb1b02007-02-22 01:01:10 +0000111/**
112 * Set global THRIFT ROOT automatically via inclusion here
113 */
114if (!isset($GLOBALS['THRIFT_ROOT'])) {
115 $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__);
116}
117include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php';
118include_once $GLOBALS['THRIFT_ROOT'].'/transport/TTransport.php';
Mark Sleedac78562007-02-21 07:35:03 +0000119
Mark Slee6e536442006-06-30 18:28:50 +0000120?>