blob: 21a175c015ac7f2f2df854db203f9023453d9ddb [file] [log] [blame]
Mark Slee6e536442006-06-30 18:28:50 +00001<?php
2
Mark Slee99e2b262006-10-10 01:42:29 +00003/**
Mark Slee4902c052007-03-01 00:31:30 +00004 * Copyright (c) 2006- Facebook
5 * Distributed under the Thrift Software License
6 *
7 * See accompanying file LICENSE or visit the Thrift site at:
8 * http://developers.facebook.com/thrift/
9 *
10 * @package thrift
11 * @author Mark Slee <mcslee@facebook.com>
12 */
13
14/**
Mark Slee1ecb1b02007-02-22 01:01:10 +000015 * Data types that can be sent via Thrift
Mark Slee99e2b262006-10-10 01:42:29 +000016 */
Mark Slee1ecb1b02007-02-22 01:01:10 +000017class TType {
18 const STOP = 0;
19 const VOID = 1;
20 const BOOL = 2;
21 const BYTE = 3;
22 const I08 = 3;
23 const DOUBLE = 4;
24 const I16 = 6;
25 const I32 = 8;
26 const I64 = 10;
27 const STRING = 11;
28 const UTF7 = 11;
29 const STRUCT = 12;
30 const MAP = 13;
31 const SET = 14;
32 const LST = 15; // N.B. cannot use LIST keyword in PHP!
33 const UTF8 = 16;
34 const UTF16 = 17;
Mark Sleecfc01932006-09-01 22:18:16 +000035}
Mark Slee1ecb1b02007-02-22 01:01:10 +000036
37/**
38 * Message types for RPC
39 */
40class TMessageType {
41 const CALL = 1;
42 const REPLY = 2;
Mark Sleed395d572007-02-27 01:16:55 +000043 const EXCEPTION = 3;
Mark Slee1ecb1b02007-02-22 01:01:10 +000044}
Mark Slee6e536442006-06-30 18:28:50 +000045
Mark Sleedac78562007-02-21 07:35:03 +000046class TException extends Exception {
47 function __construct($message=null, $code=0) {
48 parent::__construct($message, $code);
49 }
50}
51
52class TApplicationException extends TException {
53
54 const UNKNOWN = 0;
55 const UNKNOWN_METHOD = 1;
56 const INVALID_MESSAGE_TYPE = 2;
57 const WRONG_METHOD_NAME = 3;
58 const BAD_SEQUENCE_ID = 4;
59 const MISSING_RESULT = 5;
60
61 function __construct($message=null, $code=0) {
62 parent::__construct($message, $code);
63 }
64
65 public function read($input) {
66 $xfer = 0;
67 $fname = null;
68 $ftype = 0;
69 $fid = 0;
70 $xfer += $input->readStructBegin($fname);
71 while (true)
72 {
73 $xfer += $input->readFieldBegin($fname, $ftype, $fid);
74 if ($ftype == TType::STOP) {
75 break;
76 }
77 switch ($fid)
78 {
79 case 1:
80 if ($ftype == TType::STRING) {
81 $xfer += $input->readString($this->message);
82 } else {
83 $xfer += $input->skip($ftype);
84 }
85 break;
86 case 2:
87 if ($ftype == TType::I32) {
88 $xfer += $input->readI32($this->code);
89 } else {
90 $xfer += $input->skip($ftype);
91 }
92 break;
93 default:
94 $xfer += $input->skip($ftype);
95 break;
96 }
97 $xfer += $input->readFieldEnd();
98 }
99 $xfer += $input->readStructEnd();
100 return $xfer;
101 }
102
103 public function write($output) {
104 $xfer = 0;
105 $xfer += $output->writeStructBegin('TApplicationException');
106 if ($this->getMessage()) {
107 $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
108 $xfer += $output->writeString($this->getMessage());
109 $xfer += $output->writeFieldEnd();
110 }
Mark Slee0af62d12007-02-27 22:11:09 +0000111 if ($this->getCode()) {
Mark Sleedac78562007-02-21 07:35:03 +0000112 $xfer += $output->writeFieldBegin('type', TType::I32, 2);
113 $xfer += $output->writeI32($this->getCode());
114 $xfer += $output->writeFieldEnd();
115 }
116 $xfer += $output->writeFieldStop();
117 $xfer += $output->writeStructEnd();
118 return $xfer;
119 }
120}
121
Mark Slee1ecb1b02007-02-22 01:01:10 +0000122/**
123 * Set global THRIFT ROOT automatically via inclusion here
124 */
125if (!isset($GLOBALS['THRIFT_ROOT'])) {
126 $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__);
127}
128include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php';
129include_once $GLOBALS['THRIFT_ROOT'].'/transport/TTransport.php';
Mark Sleedac78562007-02-21 07:35:03 +0000130
Mark Slee6e536442006-06-30 18:28:50 +0000131?>