blob: 87bcc2bc27e68c00c0e1c2346622ed76dcd64c1a [file] [log] [blame]
Mark Slee6e536442006-06-30 18:28:50 +00001<?php
2
Mark Slee99e2b262006-10-10 01:42:29 +00003/**
4 * Set global THRIFT ROOT automatically via inclusion here
5 */
Mark Sleecfc01932006-09-01 22:18:16 +00006if (!isset($GLOBALS['THRIFT_ROOT'])) {
7 $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__);
8}
9include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php';
Mark Slee6e536442006-06-30 18:28:50 +000010
Mark Sleedac78562007-02-21 07:35:03 +000011class TException extends Exception {
12 function __construct($message=null, $code=0) {
13 parent::__construct($message, $code);
14 }
15}
16
17class TApplicationException extends TException {
18
19 const UNKNOWN = 0;
20 const UNKNOWN_METHOD = 1;
21 const INVALID_MESSAGE_TYPE = 2;
22 const WRONG_METHOD_NAME = 3;
23 const BAD_SEQUENCE_ID = 4;
24 const MISSING_RESULT = 5;
25
26 function __construct($message=null, $code=0) {
27 parent::__construct($message, $code);
28 }
29
30 public function read($input) {
31 $xfer = 0;
32 $fname = null;
33 $ftype = 0;
34 $fid = 0;
35 $xfer += $input->readStructBegin($fname);
36 while (true)
37 {
38 $xfer += $input->readFieldBegin($fname, $ftype, $fid);
39 if ($ftype == TType::STOP) {
40 break;
41 }
42 switch ($fid)
43 {
44 case 1:
45 if ($ftype == TType::STRING) {
46 $xfer += $input->readString($this->message);
47 } else {
48 $xfer += $input->skip($ftype);
49 }
50 break;
51 case 2:
52 if ($ftype == TType::I32) {
53 $xfer += $input->readI32($this->code);
54 } else {
55 $xfer += $input->skip($ftype);
56 }
57 break;
58 default:
59 $xfer += $input->skip($ftype);
60 break;
61 }
62 $xfer += $input->readFieldEnd();
63 }
64 $xfer += $input->readStructEnd();
65 return $xfer;
66 }
67
68 public function write($output) {
69 $xfer = 0;
70 $xfer += $output->writeStructBegin('TApplicationException');
71 if ($this->getMessage()) {
72 $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
73 $xfer += $output->writeString($this->getMessage());
74 $xfer += $output->writeFieldEnd();
75 }
76 if ($this->type !== null) {
77 $xfer += $output->writeFieldBegin('type', TType::I32, 2);
78 $xfer += $output->writeI32($this->getCode());
79 $xfer += $output->writeFieldEnd();
80 }
81 $xfer += $output->writeFieldStop();
82 $xfer += $output->writeStructEnd();
83 return $xfer;
84 }
85}
86
87
Mark Slee6e536442006-06-30 18:28:50 +000088?>