From: Mark Slee Date: Wed, 21 Feb 2007 07:35:03 +0000 (+0000) Subject: Proper exception types in PHP thrift X-Git-Tag: 0.2.0~1454 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=dac7856db7c26bf2ea7405a736dba94c93652e7a;p=common%2Fthrift.git Proper exception types in PHP thrift Reviewed By: tbr-aditya git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665018 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/php/src/Thrift.php b/lib/php/src/Thrift.php index fc4034bc..87bcc2bc 100644 --- a/lib/php/src/Thrift.php +++ b/lib/php/src/Thrift.php @@ -8,4 +8,81 @@ if (!isset($GLOBALS['THRIFT_ROOT'])) { } include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php'; +class TException extends Exception { + function __construct($message=null, $code=0) { + parent::__construct($message, $code); + } +} + +class TApplicationException extends TException { + + const UNKNOWN = 0; + const UNKNOWN_METHOD = 1; + const INVALID_MESSAGE_TYPE = 2; + const WRONG_METHOD_NAME = 3; + const BAD_SEQUENCE_ID = 4; + const MISSING_RESULT = 5; + + function __construct($message=null, $code=0) { + parent::__construct($message, $code); + } + + public function read($input) { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) + { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + switch ($fid) + { + case 1: + if ($ftype == TType::STRING) { + $xfer += $input->readString($this->message); + } else { + $xfer += $input->skip($ftype); + } + break; + case 2: + if ($ftype == TType::I32) { + $xfer += $input->readI32($this->code); + } else { + $xfer += $input->skip($ftype); + } + break; + default: + $xfer += $input->skip($ftype); + break; + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('TApplicationException'); + if ($this->getMessage()) { + $xfer += $output->writeFieldBegin('message', TType::STRING, 1); + $xfer += $output->writeString($this->getMessage()); + $xfer += $output->writeFieldEnd(); + } + if ($this->type !== null) { + $xfer += $output->writeFieldBegin('type', TType::I32, 2); + $xfer += $output->writeI32($this->getCode()); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} + + ?> diff --git a/lib/php/src/protocol/TProtocol.php b/lib/php/src/protocol/TProtocol.php index 95196041..d95c26c3 100644 --- a/lib/php/src/protocol/TProtocol.php +++ b/lib/php/src/protocol/TProtocol.php @@ -9,6 +9,8 @@ * @author Aditya Agarwal */ +include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php'; + /** * Data types that can be sent via Thrift */ @@ -40,6 +42,20 @@ class TMessageType { const REPLY = 2; } +/** + * Protocol exceptions + */ +class TProtocolException extends TException { + const UNKNOWN = 0; + const INVALID_DATA = 1; + const NEGATIVE_SIZE = 2; + const SIZE_LIMIT = 3; + + function __construct($message=null, $code=0) { + parent::__construct($message, $code); + } +} + /** * Protocol base class module. */ diff --git a/lib/php/src/transport/TTransport.php b/lib/php/src/transport/TTransport.php index 8d57d2ae..2a8d217b 100644 --- a/lib/php/src/transport/TTransport.php +++ b/lib/php/src/transport/TTransport.php @@ -1,5 +1,21 @@