blob: ab56eff00c80ed537b3275f5db7be0c7340f725e [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;
32}
Mark Slee6e536442006-06-30 18:28:50 +000033
Mark Sleedac78562007-02-21 07:35:03 +000034class TException extends Exception {
35 function __construct($message=null, $code=0) {
36 parent::__construct($message, $code);
37 }
38}
39
40class TApplicationException extends TException {
41
42 const UNKNOWN = 0;
43 const UNKNOWN_METHOD = 1;
44 const INVALID_MESSAGE_TYPE = 2;
45 const WRONG_METHOD_NAME = 3;
46 const BAD_SEQUENCE_ID = 4;
47 const MISSING_RESULT = 5;
48
49 function __construct($message=null, $code=0) {
50 parent::__construct($message, $code);
51 }
52
53 public function read($input) {
54 $xfer = 0;
55 $fname = null;
56 $ftype = 0;
57 $fid = 0;
58 $xfer += $input->readStructBegin($fname);
59 while (true)
60 {
61 $xfer += $input->readFieldBegin($fname, $ftype, $fid);
62 if ($ftype == TType::STOP) {
63 break;
64 }
65 switch ($fid)
66 {
67 case 1:
68 if ($ftype == TType::STRING) {
69 $xfer += $input->readString($this->message);
70 } else {
71 $xfer += $input->skip($ftype);
72 }
73 break;
74 case 2:
75 if ($ftype == TType::I32) {
76 $xfer += $input->readI32($this->code);
77 } else {
78 $xfer += $input->skip($ftype);
79 }
80 break;
81 default:
82 $xfer += $input->skip($ftype);
83 break;
84 }
85 $xfer += $input->readFieldEnd();
86 }
87 $xfer += $input->readStructEnd();
88 return $xfer;
89 }
90
91 public function write($output) {
92 $xfer = 0;
93 $xfer += $output->writeStructBegin('TApplicationException');
94 if ($this->getMessage()) {
95 $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
96 $xfer += $output->writeString($this->getMessage());
97 $xfer += $output->writeFieldEnd();
98 }
99 if ($this->type !== null) {
100 $xfer += $output->writeFieldBegin('type', TType::I32, 2);
101 $xfer += $output->writeI32($this->getCode());
102 $xfer += $output->writeFieldEnd();
103 }
104 $xfer += $output->writeFieldStop();
105 $xfer += $output->writeStructEnd();
106 return $xfer;
107 }
108}
109
Mark Slee1ecb1b02007-02-22 01:01:10 +0000110/**
111 * Set global THRIFT ROOT automatically via inclusion here
112 */
113if (!isset($GLOBALS['THRIFT_ROOT'])) {
114 $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__);
115}
116include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php';
117include_once $GLOBALS['THRIFT_ROOT'].'/transport/TTransport.php';
Mark Sleedac78562007-02-21 07:35:03 +0000118
Mark Slee6e536442006-06-30 18:28:50 +0000119?>