THRIFT-2807 PHP CS Fix
This closes #252
Patch: Roger Thomas
diff --git a/lib/php/lib/Thrift/Base/TBase.php b/lib/php/lib/Thrift/Base/TBase.php
index 3d5b526..4195f75 100644
--- a/lib/php/lib/Thrift/Base/TBase.php
+++ b/lib/php/lib/Thrift/Base/TBase.php
@@ -31,8 +31,8 @@
* of PHP. Note that code is intentionally duplicated in here to avoid making
* function calls for every field or member of a container..
*/
-abstract class TBase {
-
+abstract class TBase
+{
static $tmethod = array(TType::BOOL => 'Bool',
TType::BYTE => 'Byte',
TType::I16 => 'I16',
@@ -41,11 +41,12 @@
TType::DOUBLE => 'Double',
TType::STRING => 'String');
- abstract function read($input);
+ abstract public function read($input);
- abstract function write($output);
+ abstract public function write($output);
- public function __construct($spec=null, $vals=null) {
+ public function __construct($spec=null, $vals=null)
+ {
if (is_array($spec) && is_array($vals)) {
foreach ($spec as $fid => $fspec) {
$var = $fspec['var'];
@@ -61,7 +62,8 @@
$this->__construct(get_object_vars($this));
}
- private function _readMap(&$var, $spec, $input) {
+ private function _readMap(&$var, $spec, $input)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -124,10 +126,12 @@
$var[$key] = $val;
}
$xfer += $input->readMapEnd();
+
return $xfer;
}
- private function _readList(&$var, $spec, $input, $set=false) {
+ private function _readList(&$var, $spec, $input, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$eread = $vread = null;
@@ -177,10 +181,12 @@
} else {
$xfer += $input->readListEnd();
}
+
return $xfer;
}
- protected function _read($class, $spec, $input) {
+ protected function _read($class, $spec, $input)
+ {
$xfer = 0;
$fname = null;
$ftype = 0;
@@ -226,10 +232,12 @@
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
+
return $xfer;
}
- private function _writeMap($var, $spec, $output) {
+ private function _writeMap($var, $spec, $output)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -284,10 +292,12 @@
}
}
$xfer += $output->writeMapEnd();
+
return $xfer;
}
- private function _writeList($var, $spec, $output, $set=false) {
+ private function _writeList($var, $spec, $output, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$ewrite = null;
@@ -327,10 +337,12 @@
} else {
$xfer += $output->writeListEnd();
}
+
return $xfer;
}
- protected function _write($class, $spec, $output) {
+ protected function _write($class, $spec, $output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin($class);
foreach ($spec as $fid => $fspec) {
@@ -362,6 +374,7 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
}
diff --git a/lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php b/lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php
index bce93f5..67575ce 100644
--- a/lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php
+++ b/lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php
@@ -18,7 +18,7 @@
* under the License.
*
* ClassLoader to load Thrift library and definitions
- * Inspired from UniversalClassLoader from Symfony 2
+ * Inspired from UniversalClassLoader from Symfony 2
*
* @package thrift.classloader
*/
@@ -54,7 +54,7 @@
/**
* Set autoloader to use APC cache
* @param boolean $apc
- * @param string $apc_prefix
+ * @param string $apc_prefix
*/
public function __construct($apc = false, $apc_prefix = null)
{
@@ -112,7 +112,7 @@
/**
* Loads the given class or interface in APC.
- * @param string $class The name of the class
+ * @param string $class The name of the class
* @return string
*/
protected function findFileInApc($class)
@@ -126,33 +126,28 @@
/**
* Find class in namespaces or definitions directories
- * @param string $class
+ * @param string $class
* @return string
*/
public function findFile($class)
{
// Remove first backslash
- if ('\\' == $class[0])
- {
+ if ('\\' == $class[0]) {
$class = substr($class, 1);
}
- if (false !== $pos = strrpos($class, '\\'))
- {
+ if (false !== $pos = strrpos($class, '\\')) {
// Namespaced class name
$namespace = substr($class, 0, $pos);
// Iterate in normal namespaces
- foreach ($this->namespaces as $ns => $dirs)
- {
+ foreach ($this->namespaces as $ns => $dirs) {
//Don't interfere with other autoloaders
- if (0 !== strpos($namespace, $ns))
- {
+ if (0 !== strpos($namespace, $ns)) {
continue;
}
- foreach ($dirs as $dir)
- {
+ foreach ($dirs as $dir) {
$className = substr($class, $pos + 1);
$file = $dir.DIRECTORY_SEPARATOR.
@@ -160,8 +155,7 @@
DIRECTORY_SEPARATOR.
$className.'.php';
- if (file_exists($file))
- {
+ if (file_exists($file)) {
return $file;
}
}
@@ -173,24 +167,20 @@
$m = explode('\\', $class);
// Ignore wrong call
- if(count($m) <= 1)
- {
+ if (count($m) <= 1) {
return;
}
$class = array_pop($m);
$namespace = implode('\\', $m);
- foreach ($this->definitions as $ns => $dirs)
- {
+ foreach ($this->definitions as $ns => $dirs) {
//Don't interfere with other autoloaders
- if (0 !== strpos($namespace, $ns))
- {
+ if (0 !== strpos($namespace, $ns)) {
continue;
}
- foreach ($dirs as $dir)
- {
+ foreach ($dirs as $dir) {
/**
* Available in service: Interface, Client, Processor, Rest
* And every service methods (_.+)
@@ -201,9 +191,7 @@
)
{
$className = 'Types';
- }
- else
- {
+ } else {
$className = $n[1];
}
@@ -212,8 +200,7 @@
DIRECTORY_SEPARATOR .
$className . '.php';
- if (file_exists($file))
- {
+ if (file_exists($file)) {
return $file;
}
}
diff --git a/lib/php/lib/Thrift/Exception/TApplicationException.php b/lib/php/lib/Thrift/Exception/TApplicationException.php
index 9081973..b1689fc 100644
--- a/lib/php/lib/Thrift/Exception/TApplicationException.php
+++ b/lib/php/lib/Thrift/Exception/TApplicationException.php
@@ -22,10 +22,10 @@
namespace Thrift\Exception;
-use Thrift\Exception\TException;
use Thrift\Type\TType;
-class TApplicationException extends TException {
+class TApplicationException extends TException
+{
static $_TSPEC =
array(1 => array('var' => 'message',
'type' => TType::STRING),
@@ -44,15 +44,18 @@
const INVALID_PROTOCOL = 9;
const UNSUPPORTED_CLIENT_TYPE = 10;
- function __construct($message=null, $code=0) {
+ public function __construct($message=null, $code=0)
+ {
parent::__construct($message, $code);
}
- public function read($output) {
+ public function read($output)
+ {
return $this->_read('TApplicationException', self::$_TSPEC, $output);
}
- public function write($output) {
+ public function write($output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin('TApplicationException');
if ($message = $this->getMessage()) {
@@ -67,6 +70,7 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
}
diff --git a/lib/php/lib/Thrift/Exception/TException.php b/lib/php/lib/Thrift/Exception/TException.php
index 8e8cd28..5c06843 100644
--- a/lib/php/lib/Thrift/Exception/TException.php
+++ b/lib/php/lib/Thrift/Exception/TException.php
@@ -38,8 +38,10 @@
* @param mixed $p1 Message (string) or type-spec (array)
* @param mixed $p2 Code (integer) or values (array)
*/
-class TException extends \Exception {
- function __construct($p1=null, $p2=0) {
+class TException extends \Exception
+{
+ public function __construct($p1=null, $p2=0)
+ {
if (is_array($p1) && is_array($p2)) {
$spec = $p1;
$vals = $p2;
@@ -62,7 +64,8 @@
TType::DOUBLE => 'Double',
TType::STRING => 'String');
- private function _readMap(&$var, $spec, $input) {
+ private function _readMap(&$var, $spec, $input)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -125,10 +128,12 @@
$var[$key] = $val;
}
$xfer += $input->readMapEnd();
+
return $xfer;
}
- private function _readList(&$var, $spec, $input, $set=false) {
+ private function _readList(&$var, $spec, $input, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$eread = $vread = null;
@@ -178,10 +183,12 @@
} else {
$xfer += $input->readListEnd();
}
+
return $xfer;
}
- protected function _read($class, $spec, $input) {
+ protected function _read($class, $spec, $input)
+ {
$xfer = 0;
$fname = null;
$ftype = 0;
@@ -227,10 +234,12 @@
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
+
return $xfer;
}
- private function _writeMap($var, $spec, $output) {
+ private function _writeMap($var, $spec, $output)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -285,10 +294,12 @@
}
}
$xfer += $output->writeMapEnd();
+
return $xfer;
}
- private function _writeList($var, $spec, $output, $set=false) {
+ private function _writeList($var, $spec, $output, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$ewrite = null;
@@ -328,10 +339,12 @@
} else {
$xfer += $output->writeListEnd();
}
+
return $xfer;
}
- protected function _write($class, $spec, $output) {
+ protected function _write($class, $spec, $output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin($class);
foreach ($spec as $fid => $fspec) {
@@ -363,6 +376,7 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
diff --git a/lib/php/lib/Thrift/Exception/TProtocolException.php b/lib/php/lib/Thrift/Exception/TProtocolException.php
index f2529f5..ba7135c 100644
--- a/lib/php/lib/Thrift/Exception/TProtocolException.php
+++ b/lib/php/lib/Thrift/Exception/TProtocolException.php
@@ -23,8 +23,6 @@
namespace Thrift\Exception;
-use Thrift\Exception\TException;
-
/**
* Protocol module. Contains all the types and definitions needed to implement
* a protocol encoder/decoder.
@@ -35,7 +33,8 @@
/**
* Protocol exceptions
*/
-class TProtocolException extends TException {
+class TProtocolException extends TException
+{
const UNKNOWN = 0;
const INVALID_DATA = 1;
const NEGATIVE_SIZE = 2;
@@ -44,7 +43,8 @@
const NOT_IMPLEMENTED = 5;
const DEPTH_LIMIT = 6;
- function __construct($message=null, $code=0) {
+ public function __construct($message=null, $code=0)
+ {
parent::__construct($message, $code);
}
}
diff --git a/lib/php/lib/Thrift/Exception/TTransportException.php b/lib/php/lib/Thrift/Exception/TTransportException.php
index f467eb9..0074467 100644
--- a/lib/php/lib/Thrift/Exception/TTransportException.php
+++ b/lib/php/lib/Thrift/Exception/TTransportException.php
@@ -22,20 +22,19 @@
namespace Thrift\Exception;
-use Thrift\Exception\TException;
-
/**
* Transport exceptions
*/
-class TTransportException extends TException {
-
+class TTransportException extends TException
+{
const UNKNOWN = 0;
const NOT_OPEN = 1;
const ALREADY_OPEN = 2;
const TIMED_OUT = 3;
const END_OF_FILE = 4;
- function __construct($message=null, $code=0) {
+ public function __construct($message=null, $code=0)
+ {
parent::__construct($message, $code);
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Factory/TBinaryProtocolFactory.php b/lib/php/lib/Thrift/Factory/TBinaryProtocolFactory.php
index 85da567..0c1c4a7 100644
--- a/lib/php/lib/Thrift/Factory/TBinaryProtocolFactory.php
+++ b/lib/php/lib/Thrift/Factory/TBinaryProtocolFactory.php
@@ -22,22 +22,24 @@
namespace Thrift\Factory;
-use Thrift\Factory\TProtocolFactory;
use Thrift\Protocol\TBinaryProtocol;
/**
* Binary Protocol Factory
*/
-class TBinaryProtocolFactory implements TProtocolFactory {
+class TBinaryProtocolFactory implements TProtocolFactory
+{
private $strictRead_ = false;
private $strictWrite_ = false;
- public function __construct($strictRead=false, $strictWrite=false) {
+ public function __construct($strictRead=false, $strictWrite=false)
+ {
$this->strictRead_ = $strictRead;
$this->strictWrite_ = $strictWrite;
}
- public function getProtocol($trans) {
+ public function getProtocol($trans)
+ {
return new TBinaryProtocol($trans, $this->strictRead_, $this->strictWrite_);
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Factory/TCompactProtocolFactory.php b/lib/php/lib/Thrift/Factory/TCompactProtocolFactory.php
index 9f972aa..f4b4fe3 100644
--- a/lib/php/lib/Thrift/Factory/TCompactProtocolFactory.php
+++ b/lib/php/lib/Thrift/Factory/TCompactProtocolFactory.php
@@ -22,18 +22,19 @@
namespace Thrift\Factory;
-use Thrift\Factory\TProtocolFactory;
use Thrift\Protocol\TCompactProtocol;
/**
* Compact Protocol Factory
*/
-class TCompactProtocolFactory implements TProtocolFactory {
-
- public function __construct() {
+class TCompactProtocolFactory implements TProtocolFactory
+{
+ public function __construct()
+ {
}
- public function getProtocol($trans) {
+ public function getProtocol($trans)
+ {
return new TCompactProtocol($trans);
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Factory/TJSONProtocolFactory.php b/lib/php/lib/Thrift/Factory/TJSONProtocolFactory.php
index 27e4391..fbfb1d7 100644
--- a/lib/php/lib/Thrift/Factory/TJSONProtocolFactory.php
+++ b/lib/php/lib/Thrift/Factory/TJSONProtocolFactory.php
@@ -22,7 +22,6 @@
namespace Thrift\Factory;
-use Thrift\Factory\TProtocolFactory;
use Thrift\Protocol\TJSONProtocol;
/**
diff --git a/lib/php/lib/Thrift/Factory/TProtocolFactory.php b/lib/php/lib/Thrift/Factory/TProtocolFactory.php
index 6b322eb..4c9562d 100644
--- a/lib/php/lib/Thrift/Factory/TProtocolFactory.php
+++ b/lib/php/lib/Thrift/Factory/TProtocolFactory.php
@@ -25,7 +25,8 @@
/**
* Protocol factory creates protocol objects from transports
*/
-interface TProtocolFactory {
+interface TProtocolFactory
+{
/**
* Build a protocol from the base transport
*
diff --git a/lib/php/lib/Thrift/Factory/TStringFuncFactory.php b/lib/php/lib/Thrift/Factory/TStringFuncFactory.php
index edc3649..6ad6839 100644
--- a/lib/php/lib/Thrift/Factory/TStringFuncFactory.php
+++ b/lib/php/lib/Thrift/Factory/TStringFuncFactory.php
@@ -24,7 +24,8 @@
use Thrift\StringFunc\Mbstring;
use Thrift\StringFunc\Core;
-class TStringFuncFactory {
+class TStringFuncFactory
+{
private static $_instance;
/**
@@ -33,22 +34,24 @@
*
* @return TStringFunc
*/
- public static function create() {
- if(!self::$_instance) {
+ public static function create()
+ {
+ if (!self::$_instance) {
self::_setInstance();
}
return self::$_instance;
}
- private static function _setInstance() {
+ private static function _setInstance()
+ {
/**
* Cannot use str* functions for byte counting because multibyte
* characters will be read a single bytes.
*
* See: http://us.php.net/manual/en/mbstring.overload.php
*/
- if(ini_get('mbstring.func_overload') & 2) {
+ if (ini_get('mbstring.func_overload') & 2) {
self::$_instance = new Mbstring();
}
/**
@@ -60,4 +63,4 @@
self::$_instance = new Core();
}
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Factory/TTransportFactory.php b/lib/php/lib/Thrift/Factory/TTransportFactory.php
index f3ae123..b32b5f4 100644
--- a/lib/php/lib/Thrift/Factory/TTransportFactory.php
+++ b/lib/php/lib/Thrift/Factory/TTransportFactory.php
@@ -4,13 +4,15 @@
use Thrift\Transport\TTransport;
-class TTransportFactory {
+class TTransportFactory
+{
/**
* @static
* @param TTransport $transport
* @return TTransport
*/
- public static function getTransport(TTransport $transport) {
+ public static function getTransport(TTransport $transport)
+ {
return $transport;
}
}
diff --git a/lib/php/lib/Thrift/Protocol/JSON/BaseContext.php b/lib/php/lib/Thrift/Protocol/JSON/BaseContext.php
index e96e504..31bcb48 100644
--- a/lib/php/lib/Thrift/Protocol/JSON/BaseContext.php
+++ b/lib/php/lib/Thrift/Protocol/JSON/BaseContext.php
@@ -24,16 +24,16 @@
class BaseContext
{
- function escapeNum()
+ public function escapeNum()
{
return false;
}
- function write()
+ public function write()
{
}
- function read()
+ public function read()
{
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Protocol/JSON/ListContext.php b/lib/php/lib/Thrift/Protocol/JSON/ListContext.php
index a2b75b1..eef6594 100644
--- a/lib/php/lib/Thrift/Protocol/JSON/ListContext.php
+++ b/lib/php/lib/Thrift/Protocol/JSON/ListContext.php
@@ -22,7 +22,6 @@
namespace Thrift\Protocol\JSON;
-use Thrift\Protocol\JSON\BaseContext;
use Thrift\Protocol\TJSONProtocol;
class ListContext extends BaseContext
@@ -30,11 +29,13 @@
private $first_ = true;
private $p_;
- public function __construct($p) {
+ public function __construct($p)
+ {
$this->p_ = $p;
}
- public function write() {
+ public function write()
+ {
if ($this->first_) {
$this->first_ = false;
} else {
@@ -42,11 +43,12 @@
}
}
- public function read() {
+ public function read()
+ {
if ($this->first_) {
$this->first_ = false;
} else {
$this->p_->readJSONSyntaxChar(TJSONProtocol::COMMA);
}
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Protocol/JSON/LookaheadReader.php b/lib/php/lib/Thrift/Protocol/JSON/LookaheadReader.php
index 128b5fc..0b18c40 100644
--- a/lib/php/lib/Thrift/Protocol/JSON/LookaheadReader.php
+++ b/lib/php/lib/Thrift/Protocol/JSON/LookaheadReader.php
@@ -33,7 +33,8 @@
$this->p_ = $p;
}
- public function read() {
+ public function read()
+ {
if ($this->hasData_) {
$this->hasData_ = false;
} else {
@@ -43,12 +44,14 @@
return substr($this->data_, 0, 1);
}
- public function peek() {
+ public function peek()
+ {
if (!$this->hasData_) {
$this->data_ = $this->p_->getTransport()->readAll(1);
}
$this->hasData_ = true;
+
return substr($this->data_, 0, 1);
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Protocol/JSON/PairContext.php b/lib/php/lib/Thrift/Protocol/JSON/PairContext.php
index 1c87dd3..7b353c4 100644
--- a/lib/php/lib/Thrift/Protocol/JSON/PairContext.php
+++ b/lib/php/lib/Thrift/Protocol/JSON/PairContext.php
@@ -22,19 +22,21 @@
namespace Thrift\Protocol\JSON;
-use Thrift\Protocol\JSON\BaseContext;
use Thrift\Protocol\TJSONProtocol;
-class PairContext extends BaseContext {
+class PairContext extends BaseContext
+{
private $first_ = true;
private $colon_ = true;
private $p_ = null;
- public function __construct($p) {
+ public function __construct($p)
+ {
$this->p_ = $p;
}
- public function write() {
+ public function write()
+ {
if ($this->first_) {
$this->first_ = false;
$this->colon_ = true;
@@ -44,7 +46,8 @@
}
}
- public function read() {
+ public function read()
+ {
if ($this->first_) {
$this->first_ = false;
$this->colon_ = true;
@@ -54,7 +57,8 @@
}
}
- public function escapeNum() {
+ public function escapeNum()
+ {
return $this->colon_;
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Protocol/TBinaryProtocol.php b/lib/php/lib/Thrift/Protocol/TBinaryProtocol.php
index b1fddac..fe6a103 100644
--- a/lib/php/lib/Thrift/Protocol/TBinaryProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TBinaryProtocol.php
@@ -22,7 +22,6 @@
namespace Thrift\Protocol;
-use Thrift\Protocol\TProtocol;
use Thrift\Type\TType;
use Thrift\Exception\TProtocolException;
use Thrift\Factory\TStringFuncFactory;
@@ -31,23 +30,26 @@
* Binary implementation of the Thrift protocol.
*
*/
-class TBinaryProtocol extends TProtocol {
-
+class TBinaryProtocol extends TProtocol
+{
const VERSION_MASK = 0xffff0000;
const VERSION_1 = 0x80010000;
protected $strictRead_ = false;
protected $strictWrite_ = true;
- public function __construct($trans, $strictRead=false, $strictWrite=true) {
+ public function __construct($trans, $strictRead=false, $strictWrite=true)
+ {
parent::__construct($trans);
$this->strictRead_ = $strictRead;
$this->strictWrite_ = $strictWrite;
}
- public function writeMessageBegin($name, $type, $seqid) {
+ public function writeMessageBegin($name, $type, $seqid)
+ {
if ($this->strictWrite_) {
$version = self::VERSION_1 | $type;
+
return
$this->writeI32($version) +
$this->writeString($name) +
@@ -60,89 +62,110 @@
}
}
- public function writeMessageEnd() {
+ public function writeMessageEnd()
+ {
return 0;
}
- public function writeStructBegin($name) {
+ public function writeStructBegin($name)
+ {
return 0;
}
- public function writeStructEnd() {
+ public function writeStructEnd()
+ {
return 0;
}
- public function writeFieldBegin($fieldName, $fieldType, $fieldId) {
+ public function writeFieldBegin($fieldName, $fieldType, $fieldId)
+ {
return
$this->writeByte($fieldType) +
$this->writeI16($fieldId);
}
- public function writeFieldEnd() {
+ public function writeFieldEnd()
+ {
return 0;
}
- public function writeFieldStop() {
+ public function writeFieldStop()
+ {
return
$this->writeByte(TType::STOP);
}
- public function writeMapBegin($keyType, $valType, $size) {
+ public function writeMapBegin($keyType, $valType, $size)
+ {
return
$this->writeByte($keyType) +
$this->writeByte($valType) +
$this->writeI32($size);
}
- public function writeMapEnd() {
+ public function writeMapEnd()
+ {
return 0;
}
- public function writeListBegin($elemType, $size) {
+ public function writeListBegin($elemType, $size)
+ {
return
$this->writeByte($elemType) +
$this->writeI32($size);
}
- public function writeListEnd() {
+ public function writeListEnd()
+ {
return 0;
}
- public function writeSetBegin($elemType, $size) {
+ public function writeSetBegin($elemType, $size)
+ {
return
$this->writeByte($elemType) +
$this->writeI32($size);
}
- public function writeSetEnd() {
+ public function writeSetEnd()
+ {
return 0;
}
- public function writeBool($value) {
+ public function writeBool($value)
+ {
$data = pack('c', $value ? 1 : 0);
$this->trans_->write($data, 1);
+
return 1;
}
- public function writeByte($value) {
+ public function writeByte($value)
+ {
$data = pack('c', $value);
$this->trans_->write($data, 1);
+
return 1;
}
- public function writeI16($value) {
+ public function writeI16($value)
+ {
$data = pack('n', $value);
$this->trans_->write($data, 2);
+
return 2;
}
- public function writeI32($value) {
+ public function writeI32($value)
+ {
$data = pack('N', $value);
$this->trans_->write($data, 4);
+
return 4;
}
- public function writeI64($value) {
+ public function writeI64($value)
+ {
// If we are on a 32bit architecture we have to explicitly deal with
// 64-bit twos-complement arithmetic since PHP wants to treat all ints
// as signed and any int over 2^31 - 1 as a float
@@ -153,13 +176,13 @@
$value *= -1;
}
- $hi = (int)($value / 4294967296);
- $lo = (int)$value;
+ $hi = (int) ($value / 4294967296);
+ $lo = (int) $value;
if ($neg) {
$hi = ~$hi;
$lo = ~$lo;
- if (($lo & (int)0xffffffff) == (int)0xffffffff) {
+ if (($lo & (int) 0xffffffff) == (int) 0xffffffff) {
$lo = 0;
$hi++;
} else {
@@ -175,25 +198,31 @@
}
$this->trans_->write($data, 8);
+
return 8;
}
- public function writeDouble($value) {
+ public function writeDouble($value)
+ {
$data = pack('d', $value);
$this->trans_->write(strrev($data), 8);
+
return 8;
}
- public function writeString($value) {
+ public function writeString($value)
+ {
$len = TStringFuncFactory::create()->strlen($value);
$result = $this->writeI32($len);
if ($len) {
$this->trans_->write($value, $len);
}
+
return $result + $len;
}
- public function readMessageBegin(&$name, &$type, &$seqid) {
+ public function readMessageBegin(&$name, &$type, &$seqid)
+ {
$result = $this->readI32($sz);
if ($sz < 0) {
$version = (int) ($sz & self::VERSION_MASK);
@@ -216,102 +245,126 @@
$this->readI32($seqid);
}
}
+
return $result;
}
- public function readMessageEnd() {
+ public function readMessageEnd()
+ {
return 0;
}
- public function readStructBegin(&$name) {
+ public function readStructBegin(&$name)
+ {
$name = '';
+
return 0;
}
- public function readStructEnd() {
+ public function readStructEnd()
+ {
return 0;
}
- public function readFieldBegin(&$name, &$fieldType, &$fieldId) {
+ public function readFieldBegin(&$name, &$fieldType, &$fieldId)
+ {
$result = $this->readByte($fieldType);
if ($fieldType == TType::STOP) {
$fieldId = 0;
+
return $result;
}
$result += $this->readI16($fieldId);
+
return $result;
}
- public function readFieldEnd() {
+ public function readFieldEnd()
+ {
return 0;
}
- public function readMapBegin(&$keyType, &$valType, &$size) {
+ public function readMapBegin(&$keyType, &$valType, &$size)
+ {
return
$this->readByte($keyType) +
$this->readByte($valType) +
$this->readI32($size);
}
- public function readMapEnd() {
+ public function readMapEnd()
+ {
return 0;
}
- public function readListBegin(&$elemType, &$size) {
+ public function readListBegin(&$elemType, &$size)
+ {
return
$this->readByte($elemType) +
$this->readI32($size);
}
- public function readListEnd() {
+ public function readListEnd()
+ {
return 0;
}
- public function readSetBegin(&$elemType, &$size) {
+ public function readSetBegin(&$elemType, &$size)
+ {
return
$this->readByte($elemType) +
$this->readI32($size);
}
- public function readSetEnd() {
+ public function readSetEnd()
+ {
return 0;
}
- public function readBool(&$value) {
+ public function readBool(&$value)
+ {
$data = $this->trans_->readAll(1);
$arr = unpack('c', $data);
$value = $arr[1] == 1;
+
return 1;
}
- public function readByte(&$value) {
+ public function readByte(&$value)
+ {
$data = $this->trans_->readAll(1);
$arr = unpack('c', $data);
$value = $arr[1];
+
return 1;
}
- public function readI16(&$value) {
+ public function readI16(&$value)
+ {
$data = $this->trans_->readAll(2);
$arr = unpack('n', $data);
$value = $arr[1];
if ($value > 0x7fff) {
$value = 0 - (($value - 1) ^ 0xffff);
}
+
return 2;
}
- public function readI32(&$value) {
+ public function readI32(&$value)
+ {
$data = $this->trans_->readAll(4);
$arr = unpack('N', $data);
$value = $arr[1];
if ($value > 0x7fffffff) {
$value = 0 - (($value - 1) ^ 0xffffffff);
}
+
return 4;
}
- public function readI64(&$value) {
+ public function readI64(&$value)
+ {
$data = $this->trans_->readAll(8);
$arr = unpack('N2', $data);
@@ -327,10 +380,10 @@
// Check for a negative
if ($isNeg) {
- $hi = ~$hi & (int)0xffffffff;
- $lo = ~$lo & (int)0xffffffff;
+ $hi = ~$hi & (int) 0xffffffff;
+ $lo = ~$lo & (int) 0xffffffff;
- if ($lo == (int)0xffffffff) {
+ if ($lo == (int) 0xffffffff) {
$hi++;
$lo = 0;
} else {
@@ -341,13 +394,13 @@
// Force 32bit words in excess of 2G to pe positive - we deal wigh sign
// explicitly below
- if ($hi & (int)0x80000000) {
- $hi &= (int)0x7fffffff;
+ if ($hi & (int) 0x80000000) {
+ $hi &= (int) 0x7fffffff;
$hi += 0x80000000;
}
- if ($lo & (int)0x80000000) {
- $lo &= (int)0x7fffffff;
+ if ($lo & (int) 0x80000000) {
+ $lo &= (int) 0x7fffffff;
$lo += 0x80000000;
}
@@ -377,20 +430,24 @@
return 8;
}
- public function readDouble(&$value) {
+ public function readDouble(&$value)
+ {
$data = strrev($this->trans_->readAll(8));
$arr = unpack('d', $data);
$value = $arr[1];
+
return 8;
}
- public function readString(&$value) {
+ public function readString(&$value)
+ {
$result = $this->readI32($len);
if ($len) {
$value = $this->trans_->readAll($len);
} else {
$value = '';
}
+
return $result + $len;
}
}
diff --git a/lib/php/lib/Thrift/Protocol/TBinaryProtocolAccelerated.php b/lib/php/lib/Thrift/Protocol/TBinaryProtocolAccelerated.php
index 7a40ce9..f0e0bb9 100644
--- a/lib/php/lib/Thrift/Protocol/TBinaryProtocolAccelerated.php
+++ b/lib/php/lib/Thrift/Protocol/TBinaryProtocolAccelerated.php
@@ -22,18 +22,19 @@
namespace Thrift\Protocol;
-use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TBufferedTransport;
/**
* Accelerated binary protocol: used in conjunction with the thrift_protocol
* extension for faster deserialization
*/
-class TBinaryProtocolAccelerated extends TBinaryProtocol {
- public function __construct($trans, $strictRead=false, $strictWrite=true) {
+class TBinaryProtocolAccelerated extends TBinaryProtocol
+{
+ public function __construct($trans, $strictRead=false, $strictWrite=true)
+ {
// If the transport doesn't implement putBack, wrap it in a
// TBufferedTransport (which does)
-
+
// NOTE (t.heintz): This is very evil to do, because the TBufferedTransport may swallow bytes, which
// are then never written to the underlying transport. This happens precisely when a number of bytes
// less than the max buffer size (512 by default) is written to the transport and then flush() is NOT
@@ -47,16 +48,18 @@
// I am leaving this code in nonetheless, because there may be applications depending on this behavior.
//
// @see THRIFT-1579
-
+
if (!method_exists($trans, 'putBack')) {
$trans = new TBufferedTransport($trans);
}
parent::__construct($trans, $strictRead, $strictWrite);
}
- public function isStrictRead() {
+ public function isStrictRead()
+ {
return $this->strictRead_;
}
- public function isStrictWrite() {
+ public function isStrictWrite()
+ {
return $this->strictWrite_;
}
}
diff --git a/lib/php/lib/Thrift/Protocol/TCompactProtocol.php b/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
index b8a71d6..2870351 100644
--- a/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TCompactProtocol.php
@@ -22,7 +22,6 @@
namespace Thrift\Protocol;
-use Thrift\Protocol\TProtocol;
use Thrift\Type\TType;
use Thrift\Exception\TProtocolException;
use Thrift\Factory\TStringFuncFactory;
@@ -31,8 +30,8 @@
* Compact implementation of the Thrift protocol.
*
*/
-class TCompactProtocol extends TProtocol {
-
+class TCompactProtocol extends TProtocol
+{
const COMPACT_STOP = 0x00;
const COMPACT_TRUE = 0x01;
const COMPACT_FALSE = 0x02;
@@ -103,15 +102,18 @@
protected $containers = array();
// Some varint / zigzag helper methods
- public function toZigZag($n, $bits) {
+ public function toZigZag($n, $bits)
+ {
return ($n << 1) ^ ($n >> ($bits - 1));
}
- public function fromZigZag($n) {
+ public function fromZigZag($n)
+ {
return ($n >> 1) ^ -($n & 1);
}
- public function getVarint($data) {
+ public function getVarint($data)
+ {
$out = "";
while (true) {
if (($data & ~0x7f) === 0) {
@@ -122,17 +124,21 @@
$data = $data >> 7;
}
}
+
return $out;
}
- public function writeVarint($data) {
+ public function writeVarint($data)
+ {
$out = $this->getVarint($data);
$result = TStringFuncFactory::create()->strlen($out);
$this->trans_->write($out, $result);
+
return $result;
}
- public function readVarint(&$result) {
+ public function readVarint(&$result)
+ {
$idx = 0;
$shift = 0;
$result = 0;
@@ -151,11 +157,13 @@
return $idx;
}
- public function __construct($trans) {
+ public function __construct($trans)
+ {
parent::__construct($trans);
}
- public function writeMessageBegin($name, $type, $seqid) {
+ public function writeMessageBegin($name, $type, $seqid)
+ {
$written =
$this->writeUByte(TCompactProtocol::PROTOCOL_ID) +
$this->writeUByte(TCompactProtocol::VERSION |
@@ -163,33 +171,42 @@
$this->writeVarint($seqid) +
$this->writeString($name);
$this->state = TCompactProtocol::STATE_VALUE_WRITE;
+
return $written;
}
- public function writeMessageEnd() {
+ public function writeMessageEnd()
+ {
$this->state = TCompactProtocol::STATE_CLEAR;
+
return 0;
}
- public function writeStructBegin($name) {
+ public function writeStructBegin($name)
+ {
$this->structs[] = array($this->state, $this->lastFid);
$this->state = TCompactProtocol::STATE_FIELD_WRITE;
$this->lastFid = 0;
+
return 0;
}
- public function writeStructEnd() {
+ public function writeStructEnd()
+ {
$old_values = array_pop($this->structs);
$this->state = $old_values[0];
$this->lastFid = $old_values[1];
+
return 0;
}
- public function writeFieldStop() {
+ public function writeFieldStop()
+ {
return $this->writeByte(0);
}
- public function writeFieldHeader($type, $fid) {
+ public function writeFieldHeader($type, $fid)
+ {
$written = 0;
$delta = $fid - $this->lastFid;
if (0 < $delta && $delta <= 15) {
@@ -199,26 +216,33 @@
$this->writeI16($fid);
}
$this->lastFid = $fid;
+
return $written;
}
- public function writeFieldBegin($field_name, $field_type, $field_id) {
+ public function writeFieldBegin($field_name, $field_type, $field_id)
+ {
if ($field_type == TTYPE::BOOL) {
$this->state = TCompactProtocol::STATE_BOOL_WRITE;
$this->boolFid = $field_id;
+
return 0;
} else {
$this->state = TCompactProtocol::STATE_VALUE_WRITE;
+
return $this->writeFieldHeader(self::$ctypes[$field_type], $field_id);
}
}
- public function writeFieldEnd() {
+ public function writeFieldEnd()
+ {
$this->state = TCompactProtocol::STATE_FIELD_WRITE;
+
return 0;
}
- public function writeCollectionBegin($etype, $size) {
+ public function writeCollectionBegin($etype, $size)
+ {
$written = 0;
if ($size <= 14) {
$written = $this->writeUByte($size << 4 |
@@ -234,7 +258,8 @@
return $written;
}
- public function writeMapBegin($key_type, $val_type, $size) {
+ public function writeMapBegin($key_type, $val_type, $size)
+ {
$written = 0;
if ($size == 0) {
$written = $this->writeByte(0);
@@ -244,89 +269,113 @@
self::$ctypes[$val_type]);
}
$this->containers[] = $this->state;
+
return $written;
}
- public function writeCollectionEnd() {
+ public function writeCollectionEnd()
+ {
$this->state = array_pop($this->containers);
+
return 0;
}
- public function writeMapEnd() {
+ public function writeMapEnd()
+ {
return $this->writeCollectionEnd();
}
- public function writeListBegin($elem_type, $size) {
+ public function writeListBegin($elem_type, $size)
+ {
return $this->writeCollectionBegin($elem_type, $size);
}
- public function writeListEnd() {
+ public function writeListEnd()
+ {
return $this->writeCollectionEnd();
}
- public function writeSetBegin($elem_type, $size) {
+ public function writeSetBegin($elem_type, $size)
+ {
return $this->writeCollectionBegin($elem_type, $size);
}
- public function writeSetEnd() {
+ public function writeSetEnd()
+ {
return $this->writeCollectionEnd();
}
- public function writeBool($value) {
+ public function writeBool($value)
+ {
if ($this->state == TCompactProtocol::STATE_BOOL_WRITE) {
$ctype = TCompactProtocol::COMPACT_FALSE;
if ($value) {
$ctype = TCompactProtocol::COMPACT_TRUE;
}
+
return $this->writeFieldHeader($ctype, $this->boolFid);
- } else if ($this->state == TCompactProtocol::STATE_CONTAINER_WRITE) {
+ } elseif ($this->state == TCompactProtocol::STATE_CONTAINER_WRITE) {
return $this->writeByte($value ? 1 : 0);
} else {
throw new TProtocolException('Invalid state in compact protocol');
}
}
- public function writeByte($value) {
+ public function writeByte($value)
+ {
$data = pack('c', $value);
$this->trans_->write($data, 1);
+
return 1;
}
- public function writeUByte($byte) {
+ public function writeUByte($byte)
+ {
$this->trans_->write(pack('C', $byte), 1);
+
return 1;
}
- public function writeI16($value) {
+ public function writeI16($value)
+ {
$thing = $this->toZigZag($value, 16);
+
return $this->writeVarint($thing);
}
- public function writeI32($value) {
+ public function writeI32($value)
+ {
$thing = $this->toZigZag($value, 32);
+
return $this->writeVarint($thing);
}
- public function writeDouble($value) {
+ public function writeDouble($value)
+ {
$data = pack('d', $value);
$this->trans_->write($data, 8);
+
return 8;
}
- public function writeString($value) {
+ public function writeString($value)
+ {
$len = TStringFuncFactory::create()->strlen($value);
$result = $this->writeVarint($len);
if ($len) {
$this->trans_->write($value, $len);
}
+
return $result + $len;
}
- public function readFieldBegin(&$name, &$field_type, &$field_id) {
+ public function readFieldBegin(&$name, &$field_type, &$field_id)
+ {
$result = $this->readUByte($field_type);
if (($field_type & 0x0f) == TType::STOP) {
$field_id = 0;
+
return $result;
}
$delta = $field_type >> 4;
@@ -340,41 +389,51 @@
if ($field_type == TCompactProtocol::COMPACT_TRUE) {
$this->state = TCompactProtocol::STATE_BOOL_READ;
$this->boolValue = true;
- } else if ($field_type == TCompactProtocol::COMPACT_FALSE) {
+ } elseif ($field_type == TCompactProtocol::COMPACT_FALSE) {
$this->state = TCompactProtocol::STATE_BOOL_READ;
$this->boolValue = false;
} else {
$this->state = TCompactProtocol::STATE_VALUE_READ;
}
+
return $result;
}
- public function readFieldEnd() {
+ public function readFieldEnd()
+ {
$this->state = TCompactProtocol::STATE_FIELD_READ;
+
return 0;
}
- public function readUByte(&$value) {
+ public function readUByte(&$value)
+ {
$data = $this->trans_->readAll(1);
$arr = unpack('C', $data);
$value = $arr[1];
+
return 1;
}
- public function readByte(&$value) {
+ public function readByte(&$value)
+ {
$data = $this->trans_->readAll(1);
$arr = unpack('c', $data);
$value = $arr[1];
+
return 1;
}
- public function readZigZag(&$value) {
+ public function readZigZag(&$value)
+ {
$result = $this->readVarint($value);
$value = $this->fromZigZag($value);
+
return $result;
}
- public function readMessageBegin(&$name, &$type, &$seqid) {
+ public function readMessageBegin(&$name, &$type, &$seqid)
+ {
$protoId = 0;
$result = $this->readUByte($protoId);
if ($protoId != TCompactProtocol::PROTOCOL_ID) {
@@ -393,26 +452,32 @@
return $result;
}
- public function readMessageEnd() {
+ public function readMessageEnd()
+ {
return 0;
}
- public function readStructBegin(&$name) {
+ public function readStructBegin(&$name)
+ {
$name = ''; // unused
$this->structs[] = array($this->state, $this->lastFid);
$this->state = TCompactProtocol::STATE_FIELD_READ;
$this->lastFid = 0;
+
return 0;
}
- public function readStructEnd() {
+ public function readStructEnd()
+ {
$last = array_pop($this->structs);
$this->state = $last[0];
$this->lastFid = $last[1];
+
return 0;
}
- public function readCollectionBegin(&$type, &$size) {
+ public function readCollectionBegin(&$type, &$size)
+ {
$sizeType = 0;
$result = $this->readUByte($sizeType);
$size = $sizeType >> 4;
@@ -426,7 +491,8 @@
return $result;
}
- public function readMapBegin(&$key_type, &$val_type, &$size) {
+ public function readMapBegin(&$key_type, &$val_type, &$size)
+ {
$result = $this->readVarint($size);
$types = 0;
if ($size > 0) {
@@ -440,68 +506,84 @@
return $result;
}
- public function readCollectionEnd() {
+ public function readCollectionEnd()
+ {
$this->state = array_pop($this->containers);
+
return 0;
}
- public function readMapEnd() {
+ public function readMapEnd()
+ {
return $this->readCollectionEnd();
}
- public function readListBegin(&$elem_type, &$size) {
+ public function readListBegin(&$elem_type, &$size)
+ {
return $this->readCollectionBegin($elem_type, $size);
}
- public function readListEnd() {
+ public function readListEnd()
+ {
return $this->readCollectionEnd();
}
- public function readSetBegin(&$elem_type, &$size) {
+ public function readSetBegin(&$elem_type, &$size)
+ {
return $this->readCollectionBegin($elem_type, $size);
}
- public function readSetEnd() {
+ public function readSetEnd()
+ {
return $this->readCollectionEnd();
}
- public function readBool(&$value) {
+ public function readBool(&$value)
+ {
if ($this->state == TCompactProtocol::STATE_BOOL_READ) {
$value = $this->boolValue;
+
return 0;
- } else if ($this->state == TCompactProtocol::STATE_CONTAINER_READ) {
+ } elseif ($this->state == TCompactProtocol::STATE_CONTAINER_READ) {
return $this->readByte($value);
} else {
throw new TProtocolException('Invalid state in compact protocol');
}
}
- public function readI16(&$value) {
+ public function readI16(&$value)
+ {
return $this->readZigZag($value);
}
- public function readI32(&$value) {
+ public function readI32(&$value)
+ {
return $this->readZigZag($value);
}
- public function readDouble(&$value) {
+ public function readDouble(&$value)
+ {
$data = $this->trans_->readAll(8);
$arr = unpack('d', $data);
$value = $arr[1];
+
return 8;
}
- public function readString(&$value) {
+ public function readString(&$value)
+ {
$result = $this->readVarint($len);
if ($len) {
$value = $this->trans_->readAll($len);
} else {
$value = '';
}
+
return $result + $len;
}
- public function getTType($byte) {
+ public function getTType($byte)
+ {
return self::$ttypes[$byte & 0x0f];
}
@@ -511,7 +593,8 @@
// Read and write I64 as two 32 bit numbers $hi and $lo
- public function readI64(&$value) {
+ public function readI64(&$value)
+ {
// Read varint from wire
$hi = 0;
$lo = 0;
@@ -531,7 +614,7 @@
// Shift hi and lo together.
if ($shift >= 32) {
$hi |= (($byte & 0x7f) << ($shift - 32));
- } else if ($shift > 25) {
+ } elseif ($shift > 25) {
$hi |= (($byte & 0x7f) >> ($shift - 25));
}
if (($byte >> 7) === 0) {
@@ -556,10 +639,10 @@
// Check for a negative
if ($isNeg) {
- $hi = ~$hi & (int)0xffffffff;
- $lo = ~$lo & (int)0xffffffff;
+ $hi = ~$hi & (int) 0xffffffff;
+ $lo = ~$lo & (int) 0xffffffff;
- if ($lo == (int)0xffffffff) {
+ if ($lo == (int) 0xffffffff) {
$hi++;
$lo = 0;
} else {
@@ -570,13 +653,13 @@
// Force 32bit words in excess of 2G to be positive - we deal with sign
// explicitly below
- if ($hi & (int)0x80000000) {
- $hi &= (int)0x7fffffff;
+ if ($hi & (int) 0x80000000) {
+ $hi &= (int) 0x7fffffff;
$hi += 0x80000000;
}
- if ($lo & (int)0x80000000) {
- $lo &= (int)0x7fffffff;
+ if ($lo & (int) 0x80000000) {
+ $lo &= (int) 0x7fffffff;
$lo += 0x80000000;
}
@@ -606,7 +689,8 @@
return $idx;
}
- public function writeI64($value) {
+ public function writeI64($value)
+ {
// If we are in an I32 range, use the easy method below.
if (($value > 4294967296) || ($value < -4294967296)) {
// Convert $value to $hi and $lo
@@ -616,13 +700,13 @@
$value *= -1;
}
- $hi = (int)$value >> 32;
- $lo = (int)$value & 0xffffffff;
+ $hi = (int) $value >> 32;
+ $lo = (int) $value & 0xffffffff;
if ($neg) {
$hi = ~$hi;
$lo = ~$lo;
- if (($lo & (int)0xffffffff) == (int)0xffffffff) {
+ if (($lo & (int) 0xffffffff) == (int) 0xffffffff) {
$lo = 0;
$hi++;
} else {
diff --git a/lib/php/lib/Thrift/Protocol/TJSONProtocol.php b/lib/php/lib/Thrift/Protocol/TJSONProtocol.php
index 402401a..6c93b09 100644
--- a/lib/php/lib/Thrift/Protocol/TJSONProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TJSONProtocol.php
@@ -23,7 +23,6 @@
namespace Thrift\Protocol;
-use Thrift\Protocol\TProtocol;
use Thrift\Type\TType;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\JSON\BaseContext;
@@ -142,8 +141,7 @@
case 's':
if (substr($name, 1, 1) == 't') {
$result = TType::STRING;
- }
- else if (substr($name, 1, 1) == 'e') {
+ } elseif (substr($name, 1, 1) == 'e') {
$result = TType::SET;
}
break;
@@ -155,6 +153,7 @@
if ($result == TType::STOP) {
throw new TProtocolException("Unrecognized type", TProtocolException::INVALID_DATA);
}
+
return $result;
}
@@ -162,22 +161,26 @@
public $context_;
public $reader_;
- private function pushContext($c) {
+ private function pushContext($c)
+ {
array_push($this->contextStack_, $this->context_);
$this->context_ = $c;
}
- private function popContext() {
+ private function popContext()
+ {
$this->context_ = array_pop($this->contextStack_);
}
- public function __construct($trans) {
+ public function __construct($trans)
+ {
parent::__construct($trans);
$this->context_ = new BaseContext();
$this->reader_ = new LookaheadReader($this);
}
- public function reset() {
+ public function reset()
+ {
$this->contextStack_ = array();
$this->context_ = new BaseContext();
$this->reader_ = new LookaheadReader($this);
@@ -185,7 +188,8 @@
private $tmpbuf_ = array(4);
- public function readJSONSyntaxChar($b) {
+ public function readJSONSyntaxChar($b)
+ {
$ch = $this->reader_->read();
if (substr($ch, 0, 1) != $b) {
@@ -193,7 +197,8 @@
}
}
- private function hexVal($s) {
+ private function hexVal($s)
+ {
for ($i = 0; $i < strlen($s); $i++) {
$ch = substr($s, $i, 1);
@@ -205,11 +210,13 @@
return hexdec($s);
}
- private function hexChar($val) {
+ private function hexChar($val)
+ {
return dechex($val);
}
- private function writeJSONString($b) {
+ private function writeJSONString($b)
+ {
$this->context_->write();
if (is_numeric($b) && $this->context_->escapeNum()) {
@@ -223,7 +230,8 @@
}
}
- private function writeJSONInteger($num) {
+ private function writeJSONInteger($num)
+ {
$this->context_->write();
if ($this->context_->escapeNum()) {
@@ -237,7 +245,8 @@
}
}
- private function writeJSONDouble($num) {
+ private function writeJSONDouble($num)
+ {
$this->context_->write();
if ($this->context_->escapeNum()) {
@@ -251,42 +260,48 @@
}
}
- private function writeJSONBase64($data) {
+ private function writeJSONBase64($data)
+ {
$this->context_->write();
$this->trans_->write(self::QUOTE);
$this->trans_->write(json_encode(base64_encode($data)));
$this->trans_->write(self::QUOTE);
}
- private function writeJSONObjectStart() {
+ private function writeJSONObjectStart()
+ {
$this->context_->write();
$this->trans_->write(self::LBRACE);
$this->pushContext(new PairContext($this));
}
- private function writeJSONObjectEnd() {
+ private function writeJSONObjectEnd()
+ {
$this->popContext();
$this->trans_->write(self::RBRACE);
}
- private function writeJSONArrayStart() {
+ private function writeJSONArrayStart()
+ {
$this->context_->write();
$this->trans_->write(self::LBRACKET);
$this->pushContext(new ListContext($this));
}
- private function writeJSONArrayEnd() {
+ private function writeJSONArrayEnd()
+ {
$this->popContext();
$this->trans_->write(self::RBRACKET);
}
- private function readJSONString($skipContext) {
+ private function readJSONString($skipContext)
+ {
if (!$skipContext) {
$this->context_->read();
}
$jsonString = '';
- $lastChar = NULL;
+ $lastChar = null;
while (true) {
$ch = $this->reader_->read();
$jsonString .= $ch;
@@ -301,10 +316,12 @@
$lastChar = $ch;
}
}
+
return json_decode($jsonString);
}
- private function isJSONNumeric($b) {
+ private function isJSONNumeric($b)
+ {
switch ($b) {
case '+':
case '-':
@@ -323,10 +340,12 @@
case 'e':
return true;
}
+
return false;
}
- private function readJSONNumericChars() {
+ private function readJSONNumericChars()
+ {
$strbld = array();
while (true) {
@@ -342,7 +361,8 @@
return implode("", $strbld);
}
- private function readJSONInteger() {
+ private function readJSONInteger()
+ {
$this->context_->read();
if ($this->context_->escapeNum()) {
@@ -368,7 +388,8 @@
* separate function? So we don't have to force the rest of the
* use cases through the extra conditional.
*/
- private function readJSONIntegerAsString() {
+ private function readJSONIntegerAsString()
+ {
$this->context_->read();
if ($this->context_->escapeNum()) {
@@ -388,7 +409,8 @@
return $str;
}
- private function readJSONDouble() {
+ private function readJSONDouble()
+ {
$this->context_->read();
if (substr($this->reader_->peek(), 0, 1) == self::QUOTE) {
@@ -396,9 +418,9 @@
if ($arr == "NaN") {
return NAN;
- } else if ($arr == "Infinity") {
+ } elseif ($arr == "Infinity") {
return INF;
- } else if (!$this->context_->escapeNum()) {
+ } elseif (!$this->context_->escapeNum()) {
throw new TProtocolException("Numeric data unexpectedly quoted " . $arr,
TProtocolException::INVALID_DATA);
}
@@ -413,7 +435,8 @@
}
}
- private function readJSONBase64() {
+ private function readJSONBase64()
+ {
$arr = $this->readJSONString(false);
$data = base64_decode($arr, true);
@@ -424,13 +447,15 @@
return $data;
}
- private function readJSONObjectStart() {
+ private function readJSONObjectStart()
+ {
$this->context_->read();
$this->readJSONSyntaxChar(self::LBRACE);
$this->pushContext(new PairContext($this));
}
- private function readJSONObjectEnd() {
+ private function readJSONObjectEnd()
+ {
$this->readJSONSyntaxChar(self::RBRACE);
$this->popContext();
}
@@ -442,7 +467,8 @@
$this->pushContext(new ListContext($this));
}
- private function readJSONArrayEnd() {
+ private function readJSONArrayEnd()
+ {
$this->readJSONSyntaxChar(self::RBRACKET);
$this->popContext();
}
@@ -450,11 +476,12 @@
/**
* Writes the message header
*
- * @param string $name Function name
- * @param int $type message type TMessageType::CALL or TMessageType::REPLY
- * @param int $seqid The sequence id of this message
+ * @param string $name Function name
+ * @param int $type message type TMessageType::CALL or TMessageType::REPLY
+ * @param int $seqid The sequence id of this message
*/
- public function writeMessageBegin($name, $type, $seqid) {
+ public function writeMessageBegin($name, $type, $seqid)
+ {
$this->writeJSONArrayStart();
$this->writeJSONInteger(self::VERSION);
$this->writeJSONString($name);
@@ -465,18 +492,20 @@
/**
* Close the message
*/
- public function writeMessageEnd() {
+ public function writeMessageEnd()
+ {
$this->writeJSONArrayEnd();
}
/**
* Writes a struct header.
*
- * @param string $name Struct name
+ * @param string $name Struct name
* @throws TException on write error
- * @return int How many bytes written
+ * @return int How many bytes written
*/
- public function writeStructBegin($name) {
+ public function writeStructBegin($name)
+ {
$this->writeJSONObjectStart();
}
@@ -484,26 +513,31 @@
* Close a struct.
*
* @throws TException on write error
- * @return int How many bytes written
+ * @return int How many bytes written
*/
- public function writeStructEnd() {
+ public function writeStructEnd()
+ {
$this->writeJSONObjectEnd();
}
- public function writeFieldBegin($fieldName, $fieldType, $fieldId) {
+ public function writeFieldBegin($fieldName, $fieldType, $fieldId)
+ {
$this->writeJSONInteger($fieldId);
$this->writeJSONObjectStart();
$this->writeJSONString($this->getTypeNameForTypeID($fieldType));
}
- public function writeFieldEnd() {
+ public function writeFieldEnd()
+ {
$this->writeJsonObjectEnd();
}
- public function writeFieldStop() {
+ public function writeFieldStop()
+ {
}
- public function writeMapBegin($keyType, $valType, $size) {
+ public function writeMapBegin($keyType, $valType, $size)
+ {
$this->writeJSONArrayStart();
$this->writeJSONString($this->getTypeNameForTypeID($keyType));
$this->writeJSONString($this->getTypeNameForTypeID($valType));
@@ -511,56 +545,68 @@
$this->writeJSONObjectStart();
}
- public function writeMapEnd() {
+ public function writeMapEnd()
+ {
$this->writeJSONObjectEnd();
$this->writeJSONArrayEnd();
}
- public function writeListBegin($elemType, $size) {
+ public function writeListBegin($elemType, $size)
+ {
$this->writeJSONArrayStart();
$this->writeJSONString($this->getTypeNameForTypeID($elemType));
$this->writeJSONInteger($size);
}
- public function writeListEnd() {
+ public function writeListEnd()
+ {
$this->writeJSONArrayEnd();
}
- public function writeSetBegin($elemType, $size) {
+ public function writeSetBegin($elemType, $size)
+ {
$this->writeJSONArrayStart();
$this->writeJSONString($this->getTypeNameForTypeID($elemType));
$this->writeJSONInteger($size);
}
- public function writeSetEnd() {
+ public function writeSetEnd()
+ {
$this->writeJSONArrayEnd();
}
- public function writeBool($bool) {
+ public function writeBool($bool)
+ {
$this->writeJSONInteger($bool ? 1 : 0);
}
- public function writeByte($byte) {
+ public function writeByte($byte)
+ {
$this->writeJSONInteger($byte);
}
- public function writeI16($i16) {
+ public function writeI16($i16)
+ {
$this->writeJSONInteger($i16);
}
- public function writeI32($i32) {
+ public function writeI32($i32)
+ {
$this->writeJSONInteger($i32);
}
- public function writeI64($i64) {
+ public function writeI64($i64)
+ {
$this->writeJSONInteger($i64);
}
- public function writeDouble($dub) {
+ public function writeDouble($dub)
+ {
$this->writeJSONDouble($dub);
}
- public function writeString($str) {
+ public function writeString($str)
+ {
$this->writeJSONString($str);
}
@@ -568,10 +614,11 @@
* Reads the message header
*
* @param string $name Function name
- * @param int $type message type TMessageType::CALL or TMessageType::REPLY
+ * @param int $type message type TMessageType::CALL or TMessageType::REPLY
* @parem int $seqid The sequence id of this message
*/
- public function readMessageBegin(&$name, &$type, &$seqid) {
+ public function readMessageBegin(&$name, &$type, &$seqid)
+ {
$this->readJSONArrayStart();
if ($this->readJSONInteger() != self::VERSION) {
@@ -588,20 +635,25 @@
/**
* Read the close of message
*/
- public function readMessageEnd() {
+ public function readMessageEnd()
+ {
$this->readJSONArrayEnd();
}
- public function readStructBegin(&$name) {
+ public function readStructBegin(&$name)
+ {
$this->readJSONObjectStart();
+
return 0;
}
- public function readStructEnd() {
+ public function readStructEnd()
+ {
$this->readJSONObjectEnd();
}
- public function readFieldBegin(&$name, &$fieldType, &$fieldId) {
+ public function readFieldBegin(&$name, &$fieldType, &$fieldId)
+ {
$ch = $this->reader_->peek();
$name = "";
@@ -614,11 +666,13 @@
}
}
- public function readFieldEnd() {
+ public function readFieldEnd()
+ {
$this->readJSONObjectEnd();
}
- public function readMapBegin(&$keyType, &$valType, &$size) {
+ public function readMapBegin(&$keyType, &$valType, &$size)
+ {
$this->readJSONArrayStart();
$keyType = $this->getTypeIDForTypeName($this->readJSONString(false));
$valType = $this->getTypeIDForTypeName($this->readJSONString(false));
@@ -626,69 +680,90 @@
$this->readJSONObjectStart();
}
- public function readMapEnd() {
+ public function readMapEnd()
+ {
$this->readJSONObjectEnd();
$this->readJSONArrayEnd();
}
- public function readListBegin(&$elemType, &$size) {
+ public function readListBegin(&$elemType, &$size)
+ {
$this->readJSONArrayStart();
$elemType = $this->getTypeIDForTypeName($this->readJSONString(false));
$size = $this->readJSONInteger();
+
return true;
}
- public function readListEnd() {
+ public function readListEnd()
+ {
$this->readJSONArrayEnd();
}
- public function readSetBegin(&$elemType, &$size) {
+ public function readSetBegin(&$elemType, &$size)
+ {
$this->readJSONArrayStart();
$elemType = $this->getTypeIDForTypeName($this->readJSONString(false));
$size = $this->readJSONInteger();
+
return true;
}
- public function readSetEnd() {
+ public function readSetEnd()
+ {
$this->readJSONArrayEnd();
}
- public function readBool(&$bool) {
+ public function readBool(&$bool)
+ {
$bool = $this->readJSONInteger() == 0 ? false : true;
+
return true;
}
- public function readByte(&$byte) {
+ public function readByte(&$byte)
+ {
$byte = $this->readJSONInteger();
+
return true;
}
- public function readI16(&$i16) {
+ public function readI16(&$i16)
+ {
$i16 = $this->readJSONInteger();
+
return true;
}
- public function readI32(&$i32) {
+ public function readI32(&$i32)
+ {
$i32 = $this->readJSONInteger();
+
return true;
}
- public function readI64(&$i64) {
- if ( PHP_INT_SIZE === 4 ) {
+ public function readI64(&$i64)
+ {
+ if (PHP_INT_SIZE === 4) {
$i64 = $this->readJSONIntegerAsString();
} else {
$i64 = $this->readJSONInteger();
}
+
return true;
}
- public function readDouble(&$dub) {
+ public function readDouble(&$dub)
+ {
$dub = $this->readJSONDouble();
+
return true;
}
- public function readString(&$str) {
+ public function readString(&$str)
+ {
$str = $this->readJSONString(false);
+
return true;
}
}
diff --git a/lib/php/lib/Thrift/Protocol/TMultiplexedProtocol.php b/lib/php/lib/Thrift/Protocol/TMultiplexedProtocol.php
index 50f869f..d579c09 100644
--- a/lib/php/lib/Thrift/Protocol/TMultiplexedProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TMultiplexedProtocol.php
@@ -83,4 +83,3 @@
}
}
}
-
\ No newline at end of file
diff --git a/lib/php/lib/Thrift/Protocol/TProtocol.php b/lib/php/lib/Thrift/Protocol/TProtocol.php
index 380ff10..0e3bc0d 100644
--- a/lib/php/lib/Thrift/Protocol/TProtocol.php
+++ b/lib/php/lib/Thrift/Protocol/TProtocol.php
@@ -28,8 +28,8 @@
/**
* Protocol base class module.
*/
-abstract class TProtocol {
-
+abstract class TProtocol
+{
/**
* Underlying transport
*
@@ -40,7 +40,8 @@
/**
* Constructor
*/
- protected function __construct($trans) {
+ protected function __construct($trans)
+ {
$this->trans_ = $trans;
}
@@ -49,7 +50,8 @@
*
* @return TTransport
*/
- public function getTransport() {
+ public function getTransport()
+ {
return $this->trans_;
}
@@ -60,12 +62,12 @@
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
* @param int $seqid The sequence id of this message
*/
- public abstract function writeMessageBegin($name, $type, $seqid);
+ abstract public function writeMessageBegin($name, $type, $seqid);
/**
* Close the message
*/
- public abstract function writeMessageEnd();
+ abstract public function writeMessageEnd();
/**
* Writes a struct header.
@@ -74,7 +76,7 @@
* @throws TException on write error
* @return int How many bytes written
*/
- public abstract function writeStructBegin($name);
+ abstract public function writeStructBegin($name);
/**
* Close a struct.
@@ -82,7 +84,7 @@
* @throws TException on write error
* @return int How many bytes written
*/
- public abstract function writeStructEnd();
+ abstract public function writeStructEnd();
/*
* Starts a field.
@@ -93,37 +95,37 @@
* @throws TException on write error
* @return int How many bytes written
*/
- public abstract function writeFieldBegin($fieldName, $fieldType, $fieldId);
+ abstract public function writeFieldBegin($fieldName, $fieldType, $fieldId);
- public abstract function writeFieldEnd();
+ abstract public function writeFieldEnd();
- public abstract function writeFieldStop();
+ abstract public function writeFieldStop();
- public abstract function writeMapBegin($keyType, $valType, $size);
+ abstract public function writeMapBegin($keyType, $valType, $size);
- public abstract function writeMapEnd();
+ abstract public function writeMapEnd();
- public abstract function writeListBegin($elemType, $size);
+ abstract public function writeListBegin($elemType, $size);
- public abstract function writeListEnd();
+ abstract public function writeListEnd();
- public abstract function writeSetBegin($elemType, $size);
+ abstract public function writeSetBegin($elemType, $size);
- public abstract function writeSetEnd();
+ abstract public function writeSetEnd();
- public abstract function writeBool($bool);
+ abstract public function writeBool($bool);
- public abstract function writeByte($byte);
+ abstract public function writeByte($byte);
- public abstract function writeI16($i16);
+ abstract public function writeI16($i16);
- public abstract function writeI32($i32);
+ abstract public function writeI32($i32);
- public abstract function writeI64($i64);
+ abstract public function writeI64($i64);
- public abstract function writeDouble($dub);
+ abstract public function writeDouble($dub);
- public abstract function writeString($str);
+ abstract public function writeString($str);
/**
* Reads the message header
@@ -132,46 +134,46 @@
* @param int $type message type TMessageType::CALL or TMessageType::REPLY
* @parem int $seqid The sequence id of this message
*/
- public abstract function readMessageBegin(&$name, &$type, &$seqid);
+ abstract public function readMessageBegin(&$name, &$type, &$seqid);
/**
* Read the close of message
*/
- public abstract function readMessageEnd();
+ abstract public function readMessageEnd();
- public abstract function readStructBegin(&$name);
+ abstract public function readStructBegin(&$name);
- public abstract function readStructEnd();
+ abstract public function readStructEnd();
- public abstract function readFieldBegin(&$name, &$fieldType, &$fieldId);
+ abstract public function readFieldBegin(&$name, &$fieldType, &$fieldId);
- public abstract function readFieldEnd();
+ abstract public function readFieldEnd();
- public abstract function readMapBegin(&$keyType, &$valType, &$size);
+ abstract public function readMapBegin(&$keyType, &$valType, &$size);
- public abstract function readMapEnd();
+ abstract public function readMapEnd();
- public abstract function readListBegin(&$elemType, &$size);
+ abstract public function readListBegin(&$elemType, &$size);
- public abstract function readListEnd();
+ abstract public function readListEnd();
- public abstract function readSetBegin(&$elemType, &$size);
+ abstract public function readSetBegin(&$elemType, &$size);
- public abstract function readSetEnd();
+ abstract public function readSetEnd();
- public abstract function readBool(&$bool);
+ abstract public function readBool(&$bool);
- public abstract function readByte(&$byte);
+ abstract public function readByte(&$byte);
- public abstract function readI16(&$i16);
+ abstract public function readI16(&$i16);
- public abstract function readI32(&$i32);
+ abstract public function readI32(&$i32);
- public abstract function readI64(&$i64);
+ abstract public function readI64(&$i64);
- public abstract function readDouble(&$dub);
+ abstract public function readDouble(&$dub);
- public abstract function readString(&$str);
+ abstract public function readString(&$str);
/**
* The skip function is a utility to parse over unrecognized date without
@@ -179,7 +181,8 @@
*
* @param TType $type What type is it
*/
- public function skip($type) {
+ public function skip($type)
+ {
switch ($type) {
case TType::BOOL:
return $this->readBool($bool);
@@ -207,6 +210,7 @@
$result += $this->readFieldEnd();
}
$result += $this->readStructEnd();
+
return $result;
}
case TType::MAP:
@@ -217,6 +221,7 @@
$result += $this->skip($valType);
}
$result += $this->readMapEnd();
+
return $result;
}
case TType::SET:
@@ -226,6 +231,7 @@
$result += $this->skip($elemType);
}
$result += $this->readSetEnd();
+
return $result;
}
case TType::LST:
@@ -235,6 +241,7 @@
$result += $this->skip($elemType);
}
$result += $this->readListEnd();
+
return $result;
}
default:
@@ -249,7 +256,8 @@
* @param TTransport $itrans TTransport object
* @param int $type Field type
*/
- public static function skipBinary($itrans, $type) {
+ public static function skipBinary($itrans, $type)
+ {
switch ($type) {
case TType::BOOL:
return $itrans->readAll(1);
@@ -269,6 +277,7 @@
if ($len > 0x7fffffff) {
$len = 0 - (($len - 1) ^ 0xffffffff);
}
+
return 4 + $itrans->readAll($len);
case TType::STRUCT:
{
@@ -286,6 +295,7 @@
$result += $itrans->readAll(2);
$result += self::skipBinary($itrans, $ftype);
}
+
return $result;
}
case TType::MAP:
@@ -310,6 +320,7 @@
$result += self::skipBinary($itrans, $ktype);
$result += self::skipBinary($itrans, $vtype);
}
+
return $result;
}
case TType::SET:
@@ -330,6 +341,7 @@
for ($i = 0; $i < $size; $i++) {
$result += self::skipBinary($itrans, $vtype);
}
+
return $result;
}
default:
diff --git a/lib/php/lib/Thrift/Protocol/TProtocolDecorator.php b/lib/php/lib/Thrift/Protocol/TProtocolDecorator.php
index 4f1746c..c08c4d5 100644
--- a/lib/php/lib/Thrift/Protocol/TProtocolDecorator.php
+++ b/lib/php/lib/Thrift/Protocol/TProtocolDecorator.php
@@ -79,7 +79,7 @@
* @param string $name Struct name
*
* @throws TException on write error
- * @return int How many bytes written
+ * @return int How many bytes written
*/
public function writeStructBegin($name)
{
@@ -90,7 +90,7 @@
* Close a struct.
*
* @throws TException on write error
- * @return int How many bytes written
+ * @return int How many bytes written
*/
public function writeStructEnd()
{
diff --git a/lib/php/lib/Thrift/Serializer/TBinarySerializer.php b/lib/php/lib/Thrift/Serializer/TBinarySerializer.php
index 4e0af87..7e0cf8b 100644
--- a/lib/php/lib/Thrift/Serializer/TBinarySerializer.php
+++ b/lib/php/lib/Thrift/Serializer/TBinarySerializer.php
@@ -31,14 +31,15 @@
* Utility class for serializing and deserializing
* a thrift object using TBinaryProtocolAccelerated.
*/
-class TBinarySerializer {
-
+class TBinarySerializer
+{
// NOTE(rmarin): Because thrift_protocol_write_binary
// adds a begin message prefix, you cannot specify
// a transport in which to serialize an object. It has to
// be a string. Otherwise we will break the compatibility with
// normal deserialization.
- public static function serialize($object) {
+ public static function serialize($object)
+ {
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocolAccelerated($transport);
if (function_exists('thrift_protocol_write_binary')) {
@@ -52,10 +53,12 @@
$object->write($protocol);
}
$protocol->getTransport()->flush();
+
return $transport->getBuffer();
}
- public static function deserialize($string_object, $class_name) {
+ public static function deserialize($string_object, $class_name)
+ {
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocolAccelerated($transport);
if (function_exists('thrift_protocol_read_binary')) {
@@ -67,12 +70,14 @@
$protocolTransport = $protocol->getTransport();
$protocolTransport->write($string_object);
$protocolTransport->flush();
+
return thrift_protocol_read_binary($protocol, $class_name,
$protocol->isStrictRead());
} else {
$transport->write($string_object);
$object = new $class_name();
$object->read($protocol);
+
return $object;
}
}
diff --git a/lib/php/lib/Thrift/Server/TForkingServer.php b/lib/php/lib/Thrift/Server/TForkingServer.php
index 6fca305..7f6e541 100644
--- a/lib/php/lib/Thrift/Server/TForkingServer.php
+++ b/lib/php/lib/Thrift/Server/TForkingServer.php
@@ -2,7 +2,6 @@
namespace Thrift\Server;
-use Thrift\Server\TServer;
use Thrift\Transport\TTransport;
use Thrift\Exception\TException;
use Thrift\Exception\TTransportException;
@@ -12,7 +11,8 @@
*
* @package thrift.server
*/
-class TForkingServer extends TServer {
+class TForkingServer extends TServer
+{
/**
* Flag for the main serving loop
*
@@ -34,7 +34,8 @@
*
* @return void
*/
- public function serve() {
+ public function serve()
+ {
$this->transport_->listen();
while (!$this->stop_) {
@@ -46,16 +47,13 @@
if ($pid > 0) {
$this->handleParent($transport, $pid);
- }
- else if ($pid === 0) {
+ } elseif ($pid === 0) {
$this->handleChild($transport);
- }
- else {
+ } else {
throw new TException('Failed to fork');
}
}
- }
- catch (TTransportException $e) { }
+ } catch (TTransportException $e) { }
$this->collectChildren();
}
@@ -68,7 +66,8 @@
* @param int $pid
* @return void
*/
- private function handleParent(TTransport $transport, $pid) {
+ private function handleParent(TTransport $transport, $pid)
+ {
$this->children_[$pid] = $transport;
}
@@ -78,7 +77,8 @@
* @param TTransport $transport
* @return void
*/
- private function handleChild(TTransport $transport) {
+ private function handleChild(TTransport $transport)
+ {
try {
$inputTransport = $this->inputTransportFactory_->getTransport($transport);
$outputTransport = $this->outputTransportFactory_->getTransport($transport);
@@ -86,8 +86,7 @@
$outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
@$transport->close();
- }
- catch (TTransportException $e) { }
+ } catch (TTransportException $e) { }
exit(0);
}
@@ -97,7 +96,8 @@
*
* @return void
*/
- private function collectChildren() {
+ private function collectChildren()
+ {
foreach ($this->children_ as $pid => $transport) {
if (pcntl_waitpid($pid, $status, WNOHANG) > 0) {
unset($this->children_[$pid]);
@@ -112,7 +112,8 @@
*
* @return void
*/
- public function stop() {
+ public function stop()
+ {
$this->transport_->close();
$this->stop_ = true;
}
diff --git a/lib/php/lib/Thrift/Server/TServer.php b/lib/php/lib/Thrift/Server/TServer.php
index 343bf4b..f4d76cc 100644
--- a/lib/php/lib/Thrift/Server/TServer.php
+++ b/lib/php/lib/Thrift/Server/TServer.php
@@ -2,7 +2,6 @@
namespace Thrift\Server;
-use Thrift\Server\TServerTransport;
use Thrift\Factory\TTransportFactory;
use Thrift\Factory\TProtocolFactory;
@@ -11,8 +10,8 @@
*
* @package thrift.server
*/
-abstract class TServer {
-
+abstract class TServer
+{
/**
* Processor to handle new clients
*
diff --git a/lib/php/lib/Thrift/Server/TServerSocket.php b/lib/php/lib/Thrift/Server/TServerSocket.php
index 00a6fb9..4eff29c 100644
--- a/lib/php/lib/Thrift/Server/TServerSocket.php
+++ b/lib/php/lib/Thrift/Server/TServerSocket.php
@@ -2,7 +2,6 @@
namespace Thrift\Server;
-use Thrift\Server\TServerTransport;
use Thrift\Transport\TSocket;
/**
@@ -10,8 +9,8 @@
*
* @package thrift.transport
*/
-class TServerSocket extends TServerTransport {
-
+class TServerSocket extends TServerTransport
+{
/**
* Handle for the listener socket
*
@@ -47,7 +46,8 @@
* @param int $port Port to listen on
* @return void
*/
- public function __construct($host = 'localhost', $port = 9090) {
+ public function __construct($host = 'localhost', $port = 9090)
+ {
$this->host_ = $host;
$this->port_ = $port;
}
@@ -58,7 +58,8 @@
* @param int $acceptTimeout
* @return void
*/
- public function setAcceptTimeout($acceptTimeout) {
+ public function setAcceptTimeout($acceptTimeout)
+ {
$this->acceptTimeout_ = $acceptTimeout;
}
@@ -67,7 +68,8 @@
*
* @return void
*/
- public function listen() {
+ public function listen()
+ {
$this->listener_ = stream_socket_server('tcp://' . $this->host_ . ':' . $this->port_);
}
@@ -76,7 +78,8 @@
*
* @return void
*/
- public function close() {
+ public function close()
+ {
@fclose($this->listener_);
$this->listener_ = null;
}
@@ -86,7 +89,8 @@
*
* @return TSocket
*/
- protected function acceptImpl() {
+ protected function acceptImpl()
+ {
$handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0);
if(!$handle) return null;
diff --git a/lib/php/lib/Thrift/Server/TServerTransport.php b/lib/php/lib/Thrift/Server/TServerTransport.php
index 5324712..f82d06d 100644
--- a/lib/php/lib/Thrift/Server/TServerTransport.php
+++ b/lib/php/lib/Thrift/Server/TServerTransport.php
@@ -9,7 +9,8 @@
*
* @package thrift.transport
*/
-abstract class TServerTransport {
+abstract class TServerTransport
+{
/**
* List for new clients
*
@@ -33,7 +34,7 @@
* @abstract
* @return TTransport
*/
- protected abstract function acceptImpl();
+ abstract protected function acceptImpl();
/**
* Uses the accept implemtation. If null is returned, an
@@ -42,7 +43,8 @@
* @throws TTransportException
* @return TTransport
*/
- public function accept() {
+ public function accept()
+ {
$transport = $this->acceptImpl();
if ($transport == null) {
diff --git a/lib/php/lib/Thrift/Server/TSimpleServer.php b/lib/php/lib/Thrift/Server/TSimpleServer.php
index 790e48f..e277700 100644
--- a/lib/php/lib/Thrift/Server/TSimpleServer.php
+++ b/lib/php/lib/Thrift/Server/TSimpleServer.php
@@ -2,7 +2,6 @@
namespace Thrift\Server;
-use Thrift\Server\TServer;
use Thrift\Exception\TTransportException;
/**
@@ -10,7 +9,8 @@
*
* @package thrift.server
*/
-class TSimpleServer extends TServer {
+class TSimpleServer extends TServer
+{
/**
* Flag for the main serving loop
*
@@ -25,7 +25,8 @@
*
* @return void
*/
- public function serve() {
+ public function serve()
+ {
$this->transport_->listen();
while (!$this->stop_) {
@@ -39,8 +40,7 @@
$outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport);
while ($this->processor_->process($inputProtocol, $outputProtocol)) { }
}
- }
- catch (TTransportException $e) { }
+ } catch (TTransportException $e) { }
}
}
@@ -50,7 +50,8 @@
*
* @return void
*/
- public function stop() {
+ public function stop()
+ {
$this->transport_->close();
$this->stop_ = true;
}
diff --git a/lib/php/lib/Thrift/StringFunc/Core.php b/lib/php/lib/Thrift/StringFunc/Core.php
index e38a5b2..39a75b3 100644
--- a/lib/php/lib/Thrift/StringFunc/Core.php
+++ b/lib/php/lib/Thrift/StringFunc/Core.php
@@ -21,18 +21,20 @@
namespace Thrift\StringFunc;
-use Thrift\StringFunc\TStringFunc;
-
-class Core implements TStringFunc {
- public function substr($str, $start, $length = null) {
+class Core implements TStringFunc
+{
+ public function substr($str, $start, $length = null)
+ {
// specifying a null $length would return an empty string
- if($length === null) {
+ if ($length === null) {
return substr($str, $start);
}
+
return substr($str, $start, $length);
}
- public function strlen($str) {
+ public function strlen($str)
+ {
return strlen($str);
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/StringFunc/Mbstring.php b/lib/php/lib/Thrift/StringFunc/Mbstring.php
index c1ace13..968ff18 100644
--- a/lib/php/lib/Thrift/StringFunc/Mbstring.php
+++ b/lib/php/lib/Thrift/StringFunc/Mbstring.php
@@ -21,10 +21,10 @@
namespace Thrift\StringFunc;
-use Thrift\StringFunc\TStringFunc;
-
-class Mbstring implements TStringFunc {
- public function substr($str, $start, $length = null) {
+class Mbstring implements TStringFunc
+{
+ public function substr($str, $start, $length = null)
+ {
/**
* We need to set the charset parameter, which is the second
* optional parameter and the first optional parameter can't
@@ -32,14 +32,15 @@
* cause an empty string to be returned, so we need to
* actually calculate the proper length value.
*/
- if($length === null) {
+ if ($length === null) {
$length = $this->strlen($str) - $start;
}
return mb_substr($str, $start, $length, '8bit');
}
- public function strlen($str) {
+ public function strlen($str)
+ {
return mb_strlen($str, '8bit');
}
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/StringFunc/TStringFunc.php b/lib/php/lib/Thrift/StringFunc/TStringFunc.php
index c5bb390..dea497f 100644
--- a/lib/php/lib/Thrift/StringFunc/TStringFunc.php
+++ b/lib/php/lib/Thrift/StringFunc/TStringFunc.php
@@ -21,7 +21,8 @@
namespace Thrift\StringFunc;
-interface TStringFunc {
+interface TStringFunc
+{
public function substr($str, $start, $length = null);
public function strlen($str);
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/TMultiplexedProcessor.php b/lib/php/lib/Thrift/TMultiplexedProcessor.php
index c62e325..02b8321 100644
--- a/lib/php/lib/Thrift/TMultiplexedProcessor.php
+++ b/lib/php/lib/Thrift/TMultiplexedProcessor.php
@@ -50,7 +50,8 @@
* </code></blockquote>
*/
-class TMultiplexedProcessor {
+class TMultiplexedProcessor
+{
private $serviceProcessorMap_;
/**
@@ -63,7 +64,8 @@
* @param processor Implementation of a service, ususally referred to
* as "handlers", e.g. WeatherReportHandler implementing WeatherReport.Iface.
*/
- public function registerProcessor($serviceName, $processor) {
+ public function registerProcessor($serviceName, $processor)
+ {
$this->serviceProcessorMap_[$serviceName] = $processor;
}
@@ -79,10 +81,11 @@
* </ol>
*
* @throws TException If the message type is not CALL or ONEWAY, if
- * the service name was not found in the message, or if the service
- * name was not found in the service map.
+ * the service name was not found in the message, or if the service
+ * name was not found in the service map.
*/
- public function process(TProtocol $input, TProtocol $output) {
+ public function process(TProtocol $input, TProtocol $output)
+ {
/*
Use the actual underlying protocol (e.g. TBinaryProtocol) to read the
message header. This pulls the message "off the wire", which we'll
@@ -107,6 +110,7 @@
// Dispatch processing to the stored processor
$processor = $this->serviceProcessorMap_[$serviceName];
+
return $processor->process(
new StoredMessageProtocol($input, $messageName, $mtype, $rseqid), $output
);
@@ -118,17 +122,20 @@
* to allow them to call readMessageBegin() and get the Message in exactly
* the standard format, without the service name prepended to the Message name.
*/
-class StoredMessageProtocol extends TProtocolDecorator {
+class StoredMessageProtocol extends TProtocolDecorator
+{
private $fname_, $mtype_, $rseqid_;
- public function __construct(TProtocol $protocol, $fname, $mtype, $rseqid) {
+ public function __construct(TProtocol $protocol, $fname, $mtype, $rseqid)
+ {
parent::__construct($protocol);
$this->fname_ = $fname;
$this->mtype_ = $mtype;
$this->rseqid_ = $rseqid;
}
- public function readMessageBegin(&$name, &$type, &$seqid) {
+ public function readMessageBegin(&$name, &$type, &$seqid)
+ {
$name = $this->fname_;
$type = $this->mtype_;
$seqid = $this->rseqid_;
diff --git a/lib/php/lib/Thrift/Transport/TBufferedTransport.php b/lib/php/lib/Thrift/Transport/TBufferedTransport.php
index 270c004..f654ad3 100644
--- a/lib/php/lib/Thrift/Transport/TBufferedTransport.php
+++ b/lib/php/lib/Thrift/Transport/TBufferedTransport.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Factory\TStringFuncFactory;
/**
@@ -32,12 +31,13 @@
*
* @package thrift.transport
*/
-class TBufferedTransport extends TTransport {
-
+class TBufferedTransport extends TTransport
+{
/**
* Constructor. Creates a buffered transport around an underlying transport
*/
- public function __construct($transport=null, $rBufSize=512, $wBufSize=512) {
+ public function __construct($transport=null, $rBufSize=512, $wBufSize=512)
+ {
$this->transport_ = $transport;
$this->rBufSize_ = $rBufSize;
$this->wBufSize_ = $wBufSize;
@@ -78,19 +78,23 @@
*/
protected $rBuf_ = '';
- public function isOpen() {
+ public function isOpen()
+ {
return $this->transport_->isOpen();
}
- public function open() {
+ public function open()
+ {
$this->transport_->open();
}
- public function close() {
+ public function close()
+ {
$this->transport_->close();
}
- public function putBack($data) {
+ public function putBack($data)
+ {
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
$this->rBuf_ = $data;
} else {
@@ -107,25 +111,28 @@
* Therefore, use the readAll method of the wrapped transport inside
* the buffered readAll.
*/
- public function readAll($len) {
+ public function readAll($len)
+ {
$have = TStringFuncFactory::create()->strlen($this->rBuf_);
if ($have == 0) {
$data = $this->transport_->readAll($len);
- } else if ($have < $len) {
+ } elseif ($have < $len) {
$data = $this->rBuf_;
$this->rBuf_ = '';
$data .= $this->transport_->readAll($len - $have);
- } else if ($have == $len) {
+ } elseif ($have == $len) {
$data = $this->rBuf_;
$this->rBuf_ = '';
- } else if ($have > $len) {
+ } elseif ($have > $len) {
$data = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
}
+
return $data;
}
- public function read($len) {
+ public function read($len)
+ {
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
$this->rBuf_ = $this->transport_->read($this->rBufSize_);
}
@@ -133,15 +140,18 @@
if (TStringFuncFactory::create()->strlen($this->rBuf_) <= $len) {
$ret = $this->rBuf_;
$this->rBuf_ = '';
+
return $ret;
}
$ret = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
+
return $ret;
}
- public function write($buf) {
+ public function write($buf)
+ {
$this->wBuf_ .= $buf;
if (TStringFuncFactory::create()->strlen($this->wBuf_) >= $this->wBufSize_) {
$out = $this->wBuf_;
@@ -154,7 +164,8 @@
}
}
- public function flush() {
+ public function flush()
+ {
if (TStringFuncFactory::create()->strlen($this->wBuf_) > 0) {
$out = $this->wBuf_;
diff --git a/lib/php/lib/Thrift/Transport/TCurlClient.php b/lib/php/lib/Thrift/Transport/TCurlClient.php
index 9eeefe1..4b3e694 100644
--- a/lib/php/lib/Thrift/Transport/TCurlClient.php
+++ b/lib/php/lib/Thrift/Transport/TCurlClient.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Exception\TTransportException;
use Thrift\Factory\TStringFuncFactory;
@@ -31,8 +30,8 @@
*
* @package thrift.transport
*/
-class TCurlClient extends TTransport {
-
+class TCurlClient extends TTransport
+{
private static $curlHandle;
/**
@@ -91,7 +90,8 @@
* @param int $port
* @param string $uri
*/
- public function __construct($host, $port=80, $uri='', $scheme = 'http') {
+ public function __construct($host, $port=80, $uri='', $scheme = 'http')
+ {
if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
$uri = '/'.$uri;
}
@@ -109,7 +109,8 @@
*
* @param float $timeout
*/
- public function setTimeoutSecs($timeout) {
+ public function setTimeoutSecs($timeout)
+ {
$this->timeout_ = $timeout;
}
@@ -118,7 +119,8 @@
*
* @return boolean true if open
*/
- public function isOpen() {
+ public function isOpen()
+ {
return true;
}
@@ -127,13 +129,15 @@
*
* @throws TTransportException if cannot open
*/
- public function open() {
+ public function open()
+ {
}
/**
* Close the transport.
*/
- public function close() {
+ public function close()
+ {
$this->request_ = '';
$this->response_ = null;
}
@@ -145,12 +149,14 @@
* @return string The data that has been read
* @throws TTransportException if cannot read any more data
*/
- public function read($len) {
+ public function read($len)
+ {
if ($len >= strlen($this->response_)) {
return $this->response_;
} else {
$ret = substr($this->response_, 0, $len);
$this->response_ = substr($this->response_, $len);
+
return $ret;
}
}
@@ -161,7 +167,8 @@
* @param string $buf The data to write
* @throws TTransportException if writing fails
*/
- public function write($buf) {
+ public function write($buf)
+ {
$this->request_ .= $buf;
}
@@ -170,7 +177,8 @@
*
* @throws TTransportException if a writing error occurs
*/
- public function flush() {
+ public function flush()
+ {
if (!self::$curlHandle) {
register_shutdown_function(array('Thrift\\Transport\\TCurlClient', 'closeCurlHandle'));
self::$curlHandle = curl_init();
@@ -208,7 +216,8 @@
}
}
- static function closeCurlHandle() {
+ public static function closeCurlHandle()
+ {
try {
if (self::$curlHandle) {
curl_close(self::$curlHandle);
diff --git a/lib/php/lib/Thrift/Transport/TFramedTransport.php b/lib/php/lib/Thrift/Transport/TFramedTransport.php
index d80d548..b8a64a9 100644
--- a/lib/php/lib/Thrift/Transport/TFramedTransport.php
+++ b/lib/php/lib/Thrift/Transport/TFramedTransport.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Factory\TStringFuncFactory;
/**
@@ -31,8 +30,8 @@
*
* @package thrift.transport
*/
-class TFramedTransport extends TTransport {
-
+class TFramedTransport extends TTransport
+{
/**
* Underlying transport object.
*
@@ -73,21 +72,25 @@
*
* @param TTransport $transport Underlying transport
*/
- public function __construct($transport=null, $read=true, $write=true) {
+ public function __construct($transport=null, $read=true, $write=true)
+ {
$this->transport_ = $transport;
$this->read_ = $read;
$this->write_ = $write;
}
- public function isOpen() {
+ public function isOpen()
+ {
return $this->transport_->isOpen();
}
- public function open() {
+ public function open()
+ {
$this->transport_->open();
}
- public function close() {
+ public function close()
+ {
$this->transport_->close();
}
@@ -97,7 +100,8 @@
*
* @param int $len How much data
*/
- public function read($len) {
+ public function read($len)
+ {
if (!$this->read_) {
return $this->transport_->read($len);
}
@@ -110,12 +114,14 @@
if ($len >= TStringFuncFactory::create()->strlen($this->rBuf_)) {
$out = $this->rBuf_;
$this->rBuf_ = null;
+
return $out;
}
// Return TStringFuncFactory::create()->substr
$out = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len);
$this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len);
+
return $out;
}
@@ -124,7 +130,8 @@
*
* @param string $data data to return
*/
- public function putBack($data) {
+ public function putBack($data)
+ {
if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) {
$this->rBuf_ = $data;
} else {
@@ -135,7 +142,8 @@
/**
* Reads a chunk of data into the internal read buffer.
*/
- private function readFrame() {
+ private function readFrame()
+ {
$buf = $this->transport_->readAll(4);
$val = unpack('N', $buf);
$sz = $val[1];
@@ -149,7 +157,8 @@
* @param string $buf The data
* @param int $len Limit of bytes to write
*/
- public function write($buf, $len=null) {
+ public function write($buf, $len=null)
+ {
if (!$this->write_) {
return $this->transport_->write($buf, $len);
}
@@ -164,7 +173,8 @@
* Writes the output buffer to the stream in the format of a 4-byte length
* followed by the actual data.
*/
- public function flush() {
+ public function flush()
+ {
if (!$this->write_ || TStringFuncFactory::create()->strlen($this->wBuf_) == 0) {
return $this->transport_->flush();
}
diff --git a/lib/php/lib/Thrift/Transport/THttpClient.php b/lib/php/lib/Thrift/Transport/THttpClient.php
index f46b18a..b372ab7 100644
--- a/lib/php/lib/Thrift/Transport/THttpClient.php
+++ b/lib/php/lib/Thrift/Transport/THttpClient.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Exception\TTransportException;
use Thrift\Factory\TStringFuncFactory;
@@ -31,8 +30,8 @@
*
* @package thrift.transport
*/
-class THttpClient extends TTransport {
-
+class THttpClient extends TTransport
+{
/**
* The host to connect to
*
@@ -96,7 +95,8 @@
* @param int $port
* @param string $uri
*/
- public function __construct($host, $port=80, $uri='', $scheme = 'http') {
+ public function __construct($host, $port=80, $uri='', $scheme = 'http')
+ {
if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) {
$uri = '/'.$uri;
}
@@ -115,7 +115,8 @@
*
* @param float $timeout
*/
- public function setTimeoutSecs($timeout) {
+ public function setTimeoutSecs($timeout)
+ {
$this->timeout_ = $timeout;
}
@@ -124,7 +125,8 @@
*
* @return boolean true if open
*/
- public function isOpen() {
+ public function isOpen()
+ {
return true;
}
@@ -138,7 +140,8 @@
/**
* Close the transport.
*/
- public function close() {
+ public function close()
+ {
if ($this->handle_) {
@fclose($this->handle_);
$this->handle_ = null;
@@ -152,7 +155,8 @@
* @return string The data that has been read
* @throws TTransportException if cannot read any more data
*/
- public function read($len) {
+ public function read($len)
+ {
$data = @fread($this->handle_, $len);
if ($data === FALSE || $data === '') {
$md = stream_get_meta_data($this->handle_);
@@ -162,6 +166,7 @@
throw new TTransportException('THttpClient: Could not read '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::UNKNOWN);
}
}
+
return $data;
}
@@ -171,7 +176,8 @@
* @param string $buf The data to write
* @throws TTransportException if writing fails
*/
- public function write($buf) {
+ public function write($buf)
+ {
$this->buf_ .= $buf;
}
@@ -180,7 +186,8 @@
*
* @throws TTransportException if a writing error occurs
*/
- public function flush() {
+ public function flush()
+ {
// God, PHP really has some esoteric ways of doing simple things.
$host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : '');
@@ -214,7 +221,8 @@
}
}
- public function addHeaders($headers) {
+ public function addHeaders($headers)
+ {
$this->headers_ = array_merge($this->headers_, $headers);
}
diff --git a/lib/php/lib/Thrift/Transport/TMemoryBuffer.php b/lib/php/lib/Thrift/Transport/TMemoryBuffer.php
index 911fab6..5fc26bf 100644
--- a/lib/php/lib/Thrift/Transport/TMemoryBuffer.php
+++ b/lib/php/lib/Thrift/Transport/TMemoryBuffer.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Exception\TTransportException;
use Thrift\Factory\TStringFuncFactory;
@@ -34,19 +33,21 @@
*
* @package thrift.transport
*/
-class TMemoryBuffer extends TTransport {
-
+class TMemoryBuffer extends TTransport
+{
/**
* Constructor. Optionally pass an initial value
* for the buffer.
*/
- public function __construct($buf = '') {
+ public function __construct($buf = '')
+ {
$this->buf_ = $buf;
}
protected $buf_ = '';
- public function isOpen() {
+ public function isOpen()
+ {
return true;
}
@@ -54,11 +55,13 @@
public function close() {}
- public function write($buf) {
+ public function write($buf)
+ {
$this->buf_ .= $buf;
}
- public function read($len) {
+ public function read($len)
+ {
$bufLength = TStringFuncFactory::create()->strlen($this->buf_);
if ($bufLength === 0) {
@@ -70,6 +73,7 @@
if ($bufLength <= $len) {
$ret = $this->buf_;
$this->buf_ = '';
+
return $ret;
}
@@ -79,11 +83,13 @@
return $ret;
}
- function getBuffer() {
+ public function getBuffer()
+ {
return $this->buf_;
}
- public function available() {
+ public function available()
+ {
return TStringFuncFactory::create()->strlen($this->buf_);
}
}
diff --git a/lib/php/lib/Thrift/Transport/TNullTransport.php b/lib/php/lib/Thrift/Transport/TNullTransport.php
index 4bf10ed..feeb7a4 100644
--- a/lib/php/lib/Thrift/Transport/TNullTransport.php
+++ b/lib/php/lib/Thrift/Transport/TNullTransport.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Exception\TTransportException;
/**
@@ -31,9 +30,10 @@
*
* @package thrift.transport
*/
-class TNullTransport extends TTransport {
-
- public function isOpen() {
+class TNullTransport extends TTransport
+{
+ public function isOpen()
+ {
return true;
}
@@ -41,7 +41,8 @@
public function close() {}
- public function read($len) {
+ public function read($len)
+ {
throw new TTransportException("Can't read from TNullTransport.");
}
diff --git a/lib/php/lib/Thrift/Transport/TPhpStream.php b/lib/php/lib/Thrift/Transport/TPhpStream.php
index 691d0cf..4c14cdf 100644
--- a/lib/php/lib/Thrift/Transport/TPhpStream.php
+++ b/lib/php/lib/Thrift/Transport/TPhpStream.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Exception\TException;
use Thrift\Factory\TStringFuncFactory;
@@ -32,8 +31,8 @@
*
* @package thrift.transport
*/
-class TPhpStream extends TTransport {
-
+class TPhpStream extends TTransport
+{
const MODE_R = 1;
const MODE_W = 2;
@@ -45,12 +44,14 @@
private $write_ = false;
- public function __construct($mode) {
+ public function __construct($mode)
+ {
$this->read_ = $mode & self::MODE_R;
$this->write_ = $mode & self::MODE_W;
}
- public function open() {
+ public function open()
+ {
if ($this->read_) {
$this->inStream_ = @fopen(self::inStreamName(), 'r');
if (!is_resource($this->inStream_)) {
@@ -65,7 +66,8 @@
}
}
- public function close() {
+ public function close()
+ {
if ($this->read_) {
@fclose($this->inStream_);
$this->inStream_ = null;
@@ -76,21 +78,25 @@
}
}
- public function isOpen() {
+ public function isOpen()
+ {
return
(!$this->read_ || is_resource($this->inStream_)) &&
(!$this->write_ || is_resource($this->outStream_));
}
- public function read($len) {
+ public function read($len)
+ {
$data = @fread($this->inStream_, $len);
if ($data === FALSE || $data === '') {
throw new TException('TPhpStream: Could not read '.$len.' bytes');
}
+
return $data;
}
- public function write($buf) {
+ public function write($buf)
+ {
while (TStringFuncFactory::create()->strlen($buf) > 0) {
$got = @fwrite($this->outStream_, $buf);
if ($got === 0 || $got === FALSE) {
@@ -100,14 +106,17 @@
}
}
- public function flush() {
+ public function flush()
+ {
@fflush($this->outStream_);
}
- private static function inStreamName() {
+ private static function inStreamName()
+ {
if (php_sapi_name() == 'cli') {
return 'php://stdin';
}
+
return 'php://input';
}
diff --git a/lib/php/lib/Thrift/Transport/TSocket.php b/lib/php/lib/Thrift/Transport/TSocket.php
index 3ad3bf7..96935d4 100644
--- a/lib/php/lib/Thrift/Transport/TSocket.php
+++ b/lib/php/lib/Thrift/Transport/TSocket.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TTransport;
use Thrift\Exception\TException;
use Thrift\Exception\TTransportException;
use Thrift\Factory\TStringFuncFactory;
@@ -32,8 +31,8 @@
*
* @package thrift.transport
*/
-class TSocket extends TTransport {
-
+class TSocket extends TTransport
+{
/**
* Handle to PHP socket
*
@@ -96,14 +95,14 @@
*
* @var bool
*/
- protected $persist_ = FALSE;
+ protected $persist_ = false;
/**
* Debugging on?
*
* @var bool
*/
- protected $debug_ = FALSE;
+ protected $debug_ = false;
/**
* Debug handler
@@ -122,7 +121,7 @@
*/
public function __construct($host='localhost',
$port=9090,
- $persist=FALSE,
+ $persist=false,
$debugHandler=null) {
$this->host_ = $host;
$this->port_ = $port;
@@ -134,7 +133,8 @@
* @param resource $handle
* @return void
*/
- public function setHandle($handle) {
+ public function setHandle($handle)
+ {
$this->handle_ = $handle;
}
@@ -143,7 +143,8 @@
*
* @param int $timeout Timeout in milliseconds.
*/
- public function setSendTimeout($timeout) {
+ public function setSendTimeout($timeout)
+ {
$this->sendTimeoutSec_ = floor($timeout / 1000);
$this->sendTimeoutUsec_ =
($timeout - ($this->sendTimeoutSec_ * 1000)) * 1000;
@@ -154,7 +155,8 @@
*
* @param int $timeout Timeout in milliseconds.
*/
- public function setRecvTimeout($timeout) {
+ public function setRecvTimeout($timeout)
+ {
$this->recvTimeoutSec_ = floor($timeout / 1000);
$this->recvTimeoutUsec_ =
($timeout - ($this->recvTimeoutSec_ * 1000)) * 1000;
@@ -165,7 +167,8 @@
*
* @param bool $debug
*/
- public function setDebug($debug) {
+ public function setDebug($debug)
+ {
$this->debug_ = $debug;
}
@@ -174,7 +177,8 @@
*
* @return string host
*/
- public function getHost() {
+ public function getHost()
+ {
return $this->host_;
}
@@ -183,7 +187,8 @@
*
* @return int port
*/
- public function getPort() {
+ public function getPort()
+ {
return $this->port_;
}
@@ -192,14 +197,16 @@
*
* @return bool true if the socket is open
*/
- public function isOpen() {
+ public function isOpen()
+ {
return is_resource($this->handle_);
}
/**
* Connects the socket.
*/
- public function open() {
+ public function open()
+ {
if ($this->isOpen()) {
throw new TTransportException('Socket already connected', TTransportException::ALREADY_OPEN);
}
@@ -239,7 +246,8 @@
/**
* Closes the socket.
*/
- public function close() {
+ public function close()
+ {
if (!$this->persist_) {
@fclose($this->handle_);
$this->handle_ = null;
@@ -255,7 +263,8 @@
* @param int $len Maximum number of bytes to read.
* @return string Binary data
*/
- public function read($len) {
+ public function read($len)
+ {
$null = null;
$read = array($this->handle_);
$readable = @stream_select($read, $null, $null, $this->recvTimeoutSec_, $this->recvTimeoutUsec_);
@@ -265,12 +274,12 @@
if ($data === false) {
throw new TTransportException('TSocket: Could not read '.$len.' bytes from '.
$this->host_.':'.$this->port_);
- } elseif($data == '' && feof($this->handle_)) {
+ } elseif ($data == '' && feof($this->handle_)) {
throw new TTransportException('TSocket read 0 bytes');
}
return $data;
- } else if ($readable === 0) {
+ } elseif ($readable === 0) {
throw new TTransportException('TSocket: timed out reading '.$len.' bytes from '.
$this->host_.':'.$this->port_);
} else {
@@ -284,7 +293,8 @@
*
* @param string $buf The data to write
*/
- public function write($buf) {
+ public function write($buf)
+ {
$null = null;
$write = array($this->handle_);
@@ -301,7 +311,7 @@
}
// determine how much of the buffer is left to write
$buf = TStringFuncFactory::create()->substr($buf, $written);
- } else if ($writable === 0) {
+ } elseif ($writable === 0) {
throw new TTransportException('TSocket: timed out writing '.TStringFuncFactory::create()->strlen($buf).' bytes from '.
$this->host_.':'.$this->port_);
} else {
@@ -320,7 +330,8 @@
* If you wish to have flushable buffering behaviour, wrap this TSocket
* in a TBufferedTransport.
*/
- public function flush() {
+ public function flush()
+ {
// no-op
}
}
diff --git a/lib/php/lib/Thrift/Transport/TSocketPool.php b/lib/php/lib/Thrift/Transport/TSocketPool.php
index e1610cb..18ffd8d 100644
--- a/lib/php/lib/Thrift/Transport/TSocketPool.php
+++ b/lib/php/lib/Thrift/Transport/TSocketPool.php
@@ -22,7 +22,6 @@
namespace Thrift\Transport;
-use Thrift\Transport\TSocket;
use Thrift\Exception\TException;
/**
@@ -42,8 +41,8 @@
*
* @package thrift.transport
*/
-class TSocketPool extends TSocket {
-
+class TSocketPool extends TSocket
+{
/**
* Remote servers. Array of associative arrays with 'host' and 'port' keys
*/
@@ -76,14 +75,14 @@
*
* @var bool
*/
- private $randomize_ = TRUE;
+ private $randomize_ = true;
/**
* Always try last host, even if marked down?
*
* @var bool
*/
- private $alwaysTryLast_ = TRUE;
+ private $alwaysTryLast_ = true;
/**
* Socket pool constructor
@@ -95,7 +94,7 @@
*/
public function __construct($hosts=array('localhost'),
$ports=array(9090),
- $persist=FALSE,
+ $persist=false,
$debugHandler=null) {
parent::__construct(null, 0, $persist, $debugHandler);
@@ -121,7 +120,8 @@
* @param string $host hostname or IP
* @param int $port port
*/
- public function addServer($host, $port) {
+ public function addServer($host, $port)
+ {
$this->servers_[] = array('host' => $host, 'port' => $port);
}
@@ -130,7 +130,8 @@
*
* @param int $numRetries
*/
- public function setNumRetries($numRetries) {
+ public function setNumRetries($numRetries)
+ {
$this->numRetries_ = $numRetries;
}
@@ -139,7 +140,8 @@
*
* @param int $numRetries
*/
- public function setRetryInterval($retryInterval) {
+ public function setRetryInterval($retryInterval)
+ {
$this->retryInterval_ = $retryInterval;
}
@@ -148,7 +150,8 @@
*
* @param int $numRetries
*/
- public function setMaxConsecutiveFailures($maxConsecutiveFailures) {
+ public function setMaxConsecutiveFailures($maxConsecutiveFailures)
+ {
$this->maxConsecutiveFailures_ = $maxConsecutiveFailures;
}
@@ -157,7 +160,8 @@
*
* @param bool $randomize
*/
- public function setRandomize($randomize) {
+ public function setRandomize($randomize)
+ {
$this->randomize_ = $randomize;
}
@@ -166,16 +170,17 @@
*
* @param bool $alwaysTryLast
*/
- public function setAlwaysTryLast($alwaysTryLast) {
+ public function setAlwaysTryLast($alwaysTryLast)
+ {
$this->alwaysTryLast_ = $alwaysTryLast;
}
-
/**
* Connects the socket by iterating through all the servers in the pool
* and trying to find one that works.
*/
- public function open() {
+ public function open()
+ {
// Check if we want order randomization
if ($this->randomize_) {
shuffle($this->servers_);
@@ -198,13 +203,13 @@
$lastFailtime = 0;
}
- $retryIntervalPassed = FALSE;
+ $retryIntervalPassed = false;
// Cache hit...make sure enough the retry interval has elapsed
if ($lastFailtime > 0) {
$elapsed = time() - $lastFailtime;
if ($elapsed > $this->retryInterval_) {
- $retryIntervalPassed = TRUE;
+ $retryIntervalPassed = true;
if ($this->debug_) {
call_user_func($this->debugHandler_,
'TSocketPool: retryInterval '.
@@ -216,7 +221,7 @@
// Only connect if not in the middle of a fail interval, OR if this
// is the LAST server we are trying, just hammer away on it
- $isLastServer = FALSE;
+ $isLastServer = false;
if ($this->alwaysTryLast_) {
$isLastServer = ($i == ($numServers - 1));
}
diff --git a/lib/php/lib/Thrift/Transport/TTransport.php b/lib/php/lib/Thrift/Transport/TTransport.php
index 2e44366..99c39ff 100644
--- a/lib/php/lib/Thrift/Transport/TTransport.php
+++ b/lib/php/lib/Thrift/Transport/TTransport.php
@@ -29,26 +29,26 @@
*
* @package thrift.transport
*/
-abstract class TTransport {
-
+abstract class TTransport
+{
/**
* Whether this transport is open.
*
* @return boolean true if open
*/
- public abstract function isOpen();
+ abstract public function isOpen();
/**
* Open the transport for reading/writing
*
* @throws TTransportException if cannot open
*/
- public abstract function open();
+ abstract public function open();
/**
* Close the transport.
*/
- public abstract function close();
+ abstract public function close();
/**
* Read some data into the array.
@@ -57,7 +57,7 @@
* @return string The data that has been read
* @throws TTransportException if cannot read any more data
*/
- public abstract function read($len);
+ abstract public function read($len);
/**
* Guarantees that the full amount of data is read.
@@ -65,7 +65,8 @@
* @return string The data, of exact length
* @throws TTransportException if cannot read data
*/
- public function readAll($len) {
+ public function readAll($len)
+ {
// return $this->read($len);
$data = '';
@@ -73,6 +74,7 @@
while (($got = TStringFuncFactory::create()->strlen($data)) < $len) {
$data .= $this->read($len - $got);
}
+
return $data;
}
@@ -82,7 +84,7 @@
* @param string $buf The data to write
* @throws TTransportException if writing fails
*/
- public abstract function write($buf);
+ abstract public function write($buf);
/**
* Flushes any pending data out of a buffer
diff --git a/lib/php/lib/Thrift/Type/TConstant.php b/lib/php/lib/Thrift/Type/TConstant.php
index 759cfd2..7c8eceb 100644
--- a/lib/php/lib/Thrift/Type/TConstant.php
+++ b/lib/php/lib/Thrift/Type/TConstant.php
@@ -34,13 +34,12 @@
/**
* Get a constant value
- * @param string $constant
+ * @param string $constant
* @return mixed
*/
public static function get($constant)
{
- if(is_null(static::$$constant))
- {
+ if (is_null(static::$$constant)) {
static::$$constant = call_user_func(
sprintf('static::init_%s', $constant)
);
diff --git a/lib/php/lib/Thrift/Type/TMessageType.php b/lib/php/lib/Thrift/Type/TMessageType.php
index 681c45c..bff224f 100644
--- a/lib/php/lib/Thrift/Type/TMessageType.php
+++ b/lib/php/lib/Thrift/Type/TMessageType.php
@@ -25,9 +25,10 @@
/**
* Message types for RPC
*/
-class TMessageType {
+class TMessageType
+{
const CALL = 1;
const REPLY = 2;
const EXCEPTION = 3;
const ONEWAY = 4;
-}
\ No newline at end of file
+}
diff --git a/lib/php/lib/Thrift/Type/TType.php b/lib/php/lib/Thrift/Type/TType.php
index c1cf228..71219c2 100644
--- a/lib/php/lib/Thrift/Type/TType.php
+++ b/lib/php/lib/Thrift/Type/TType.php
@@ -25,7 +25,8 @@
/**
* Data types that can be sent via Thrift
*/
-class TType {
+class TType
+{
const STOP = 0;
const VOID = 1;
const BOOL = 2;
diff --git a/lib/php/src/TStringUtils.php b/lib/php/src/TStringUtils.php
index 69672e8..894baf8 100644
--- a/lib/php/src/TStringUtils.php
+++ b/lib/php/src/TStringUtils.php
@@ -1,28 +1,33 @@
<?php
-interface TStringFunc {
+interface TStringFunc
+{
public function substr($str, $start, $length = null);
public function strlen($str);
}
class TStringFunc_Core
implements TStringFunc {
- public function substr($str, $start, $length = null) {
+ public function substr($str, $start, $length = null)
+ {
// specifying a null $length would return an empty string
- if($length === null) {
+ if ($length === null) {
return substr($str, $start);
}
+
return substr($str, $start, $length);
}
- public function strlen($str) {
+ public function strlen($str)
+ {
return strlen($str);
}
}
class TStringFunc_Mbstring
implements TStringFunc {
- public function substr($str, $start, $length = null) {
+ public function substr($str, $start, $length = null)
+ {
/**
* We need to set the charset parameter, which is the second
* optional parameter and the first optional parameter can't
@@ -30,19 +35,21 @@
* cause an empty string to be returned, so we need to
* actually calculate the proper length value.
*/
- if($length === null) {
+ if ($length === null) {
$length = $this->strlen($str) - $start;
}
return mb_substr($str, $start, $length, '8bit');
}
- public function strlen($str) {
+ public function strlen($str)
+ {
return mb_strlen($str, '8bit');
}
}
-class TStringFuncFactory {
+class TStringFuncFactory
+{
private static $_instance;
/**
@@ -51,22 +58,24 @@
*
* @return TStringFunc
*/
- public static function create() {
- if(!self::$_instance) {
+ public static function create()
+ {
+ if (!self::$_instance) {
self::_setInstance();
}
return self::$_instance;
}
- private static function _setInstance() {
+ private static function _setInstance()
+ {
/**
* Cannot use str* functions for byte counting because multibyte
* characters will be read a single bytes.
*
* See: http://us.php.net/manual/en/mbstring.overload.php
*/
- if(ini_get('mbstring.func_overload') & 2) {
+ if (ini_get('mbstring.func_overload') & 2) {
self::$_instance = new TStringFunc_Mbstring();
}
/**
diff --git a/lib/php/src/Thrift.php b/lib/php/src/Thrift.php
index c845395..4fe4392 100644
--- a/lib/php/src/Thrift.php
+++ b/lib/php/src/Thrift.php
@@ -20,11 +20,11 @@
* @package thrift
*/
-
/**
* Data types that can be sent via Thrift
*/
-class TType {
+class TType
+{
const STOP = 0;
const VOID = 1;
const BOOL = 2;
@@ -47,7 +47,8 @@
/**
* Message types for RPC
*/
-class TMessageType {
+class TMessageType
+{
const CALL = 1;
const REPLY = 2;
const EXCEPTION = 3;
@@ -67,8 +68,10 @@
* @param mixed $p1 Message (string) or type-spec (array)
* @param mixed $p2 Code (integer) or values (array)
*/
-class TException extends Exception {
- function __construct($p1=null, $p2=0) {
+class TException extends Exception
+{
+ public function __construct($p1=null, $p2=0)
+ {
if (is_array($p1) && is_array($p2)) {
$spec = $p1;
$vals = $p2;
@@ -91,7 +94,8 @@
TType::DOUBLE => 'Double',
TType::STRING => 'String');
- private function _readMap(&$var, $spec, $input) {
+ private function _readMap(&$var, $spec, $input)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -154,10 +158,12 @@
$var[$key] = $val;
}
$xfer += $input->readMapEnd();
+
return $xfer;
}
- private function _readList(&$var, $spec, $input, $set=false) {
+ private function _readList(&$var, $spec, $input, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$eread = $vread = null;
@@ -207,10 +213,12 @@
} else {
$xfer += $input->readListEnd();
}
+
return $xfer;
}
- protected function _read($class, $spec, $input) {
+ protected function _read($class, $spec, $input)
+ {
$xfer = 0;
$fname = null;
$ftype = 0;
@@ -256,10 +264,12 @@
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
+
return $xfer;
}
- private function _writeMap($var, $spec, $output) {
+ private function _writeMap($var, $spec, $output)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -314,10 +324,12 @@
}
}
$xfer += $output->writeMapEnd();
+
return $xfer;
}
- private function _writeList($var, $spec, $output, $set=false) {
+ private function _writeList($var, $spec, $output, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$ewrite = null;
@@ -357,10 +369,12 @@
} else {
$xfer += $output->writeListEnd();
}
+
return $xfer;
}
- protected function _write($class, $spec, $output) {
+ protected function _write($class, $spec, $output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin($class);
foreach ($spec as $fid => $fspec) {
@@ -392,6 +406,7 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
@@ -404,8 +419,8 @@
* of PHP. Note that code is intentionally duplicated in here to avoid making
* function calls for every field or member of a container..
*/
-abstract class TBase {
-
+abstract class TBase
+{
static $tmethod = array(TType::BOOL => 'Bool',
TType::BYTE => 'Byte',
TType::I16 => 'I16',
@@ -414,11 +429,12 @@
TType::DOUBLE => 'Double',
TType::STRING => 'String');
- abstract function read($input);
+ abstract public function read($input);
- abstract function write($output);
+ abstract public function write($output);
- public function __construct($spec=null, $vals=null) {
+ public function __construct($spec=null, $vals=null)
+ {
if (is_array($spec) && is_array($vals)) {
foreach ($spec as $fid => $fspec) {
$var = $fspec['var'];
@@ -429,7 +445,8 @@
}
}
- private function _readMap(&$var, $spec, $input) {
+ private function _readMap(&$var, $spec, $input)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -492,10 +509,12 @@
$var[$key] = $val;
}
$xfer += $input->readMapEnd();
+
return $xfer;
}
- private function _readList(&$var, $spec, $input, $set=false) {
+ private function _readList(&$var, $spec, $input, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$eread = $vread = null;
@@ -545,10 +564,12 @@
} else {
$xfer += $input->readListEnd();
}
+
return $xfer;
}
- protected function _read($class, $spec, $input) {
+ protected function _read($class, $spec, $input)
+ {
$xfer = 0;
$fname = null;
$ftype = 0;
@@ -594,10 +615,12 @@
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
+
return $xfer;
}
- private function _writeMap($var, $spec, $output) {
+ private function _writeMap($var, $spec, $output)
+ {
$xfer = 0;
$ktype = $spec['ktype'];
$vtype = $spec['vtype'];
@@ -652,10 +675,12 @@
}
}
$xfer += $output->writeMapEnd();
+
return $xfer;
}
- private function _writeList($var, $spec, $output, $set=false) {
+ private function _writeList($var, $spec, $output, $set=false)
+ {
$xfer = 0;
$etype = $spec['etype'];
$ewrite = null;
@@ -695,10 +720,12 @@
} else {
$xfer += $output->writeListEnd();
}
+
return $xfer;
}
- protected function _write($class, $spec, $output) {
+ protected function _write($class, $spec, $output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin($class);
foreach ($spec as $fid => $fspec) {
@@ -730,11 +757,13 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
}
-class TApplicationException extends TException {
+class TApplicationException extends TException
+{
static $_TSPEC =
array(1 => array('var' => 'message',
'type' => TType::STRING),
@@ -750,15 +779,18 @@
const INTERNAL_ERROR = 6;
const PROTOCOL_ERROR = 7;
- function __construct($message=null, $code=0) {
+ public function __construct($message=null, $code=0)
+ {
parent::__construct($message, $code);
}
- public function read($output) {
+ public function read($output)
+ {
return $this->_read('TApplicationException', self::$_TSPEC, $output);
}
- public function write($output) {
+ public function write($output)
+ {
$xfer = 0;
$xfer += $output->writeStructBegin('TApplicationException');
if ($message = $this->getMessage()) {
@@ -773,6 +805,7 @@
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
+
return $xfer;
}
}
@@ -786,4 +819,3 @@
include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php';
include_once $GLOBALS['THRIFT_ROOT'].'/transport/TTransport.php';
include_once $GLOBALS['THRIFT_ROOT'].'/TStringUtils.php';
-
diff --git a/lib/php/src/autoload.php b/lib/php/src/autoload.php
index 3a35545..85bd797 100644
--- a/lib/php/src/autoload.php
+++ b/lib/php/src/autoload.php
@@ -20,7 +20,6 @@
* @package thrift
*/
-
/**
* Include this file if you wish to use autoload with your PHP generated Thrift
* code. The generated code will *not* include any defined Thrift classes by
@@ -37,12 +36,13 @@
$GLOBALS['AUTOLOAD_HOOKS'] = array();
if (!function_exists('__autoload')) {
- function __autoload($class) {
+ function __autoload($class)
+ {
global $THRIFT_AUTOLOAD;
$classl = strtolower($class);
if (isset($THRIFT_AUTOLOAD[$classl])) {
include_once $GLOBALS['THRIFT_ROOT'].'/packages/'.$THRIFT_AUTOLOAD[$classl];
- } else if (!empty($GLOBALS['AUTOLOAD_HOOKS'])) {
+ } elseif (!empty($GLOBALS['AUTOLOAD_HOOKS'])) {
foreach ($GLOBALS['AUTOLOAD_HOOKS'] as $hook) {
$hook($class);
}
diff --git a/lib/php/test/Test/Thrift/Fixtures.php b/lib/php/test/Test/Thrift/Fixtures.php
index 1b86f59..35fc0d9 100644
--- a/lib/php/test/Test/Thrift/Fixtures.php
+++ b/lib/php/test/Test/Thrift/Fixtures.php
@@ -52,12 +52,9 @@
self::$testArgs['testI32'] = pow( 2, 30 );
- if ( PHP_INT_SIZE == 8 )
- {
+ if (PHP_INT_SIZE == 8) {
self::$testArgs['testI64'] = pow( 2, 60 );
- }
- else
- {
+ } else {
self::$testArgs['testI64'] = "1152921504606847000";
}
diff --git a/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php b/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
index 7e324f0..5c15bdf 100644
--- a/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
+++ b/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
@@ -21,9 +21,7 @@
namespace Test\Thrift\JsonSerialize;
use stdClass;
-use Test\Thrift\Fixtures;
use Thrift\ClassLoader\ThriftClassLoader;
-use Thrift\Serializer\TBinarySerializer;
require_once __DIR__.'/../../../../lib/Thrift/ClassLoader/ThriftClassLoader.php';
@@ -36,12 +34,14 @@
class JsonSerializeTest extends \PHPUnit_Framework_TestCase
{
- public function testEmptyStruct() {
+ public function testEmptyStruct()
+ {
$empty = new \ThriftTest\EmptyStruct(array('non_existing_key' => 'bar'));
- $this->assertEquals(new stdClass, json_decode(json_encode($empty)));
+ $this->assertEquals(new stdClass(), json_decode(json_encode($empty)));
}
- public function testStringsAndInts() {
+ public function testStringsAndInts()
+ {
$input = array(
'string_thing' => 'foo',
'i64_thing' => 1234567890,
@@ -49,13 +49,14 @@
$xtruct = new \ThriftTest\Xtruct($input);
// Xtruct's 'i32_thing' and 'byte_thing' fields should not be present here!
- $expected = new stdClass;
+ $expected = new stdClass();
$expected->string_thing = $input['string_thing'];
$expected->i64_thing = $input['i64_thing'];
$this->assertEquals($expected, json_decode(json_encode($xtruct)));
}
- public function testNestedStructs() {
+ public function testNestedStructs()
+ {
$xtruct2 = new \ThriftTest\Xtruct2(array(
'byte_thing' => 42,
'struct_thing' => new \ThriftTest\Xtruct(array(
@@ -63,29 +64,31 @@
)),
));
- $expected = new stdClass;
+ $expected = new stdClass();
$expected->byte_thing = $xtruct2->byte_thing;
- $expected->struct_thing = new stdClass;
+ $expected->struct_thing = new stdClass();
$expected->struct_thing->i32_thing = $xtruct2->struct_thing->i32_thing;
$this->assertEquals($expected, json_decode(json_encode($xtruct2)));
}
- public function testInsanity() {
+ public function testInsanity()
+ {
$xinput = array('string_thing' => 'foo');
$xtruct = new \ThriftTest\Xtruct($xinput);
$insanity = new \ThriftTest\Insanity(array(
'xtructs' => array($xtruct, $xtruct, $xtruct)
));
- $expected = new stdClass;
- $expected->xtructs = array((object)$xinput, (object)$xinput, (object)$xinput);
+ $expected = new stdClass();
+ $expected->xtructs = array((object) $xinput, (object) $xinput, (object) $xinput);
$this->assertEquals($expected, json_decode(json_encode($insanity)));
}
- public function testNestedLists() {
+ public function testNestedLists()
+ {
$bonk = new \ThriftTest\Bonk(array('message' => 'foo'));
$nested = new \ThriftTest\NestedListsBonk(array('bonk' => array(array(array($bonk)))));
- $expected = new stdClass;
- $expected->bonk = array(array(array((object)array('message' => 'foo'))));
+ $expected = new stdClass();
+ $expected->bonk = array(array(array((object) array('message' => 'foo'))));
$this->assertEquals($expected, json_decode(json_encode($nested)));
}
diff --git a/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php b/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php
index 65feadd..a983216 100644
--- a/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php
+++ b/lib/php/test/Test/Thrift/Protocol/TestBinarySerializer.php
@@ -21,7 +21,7 @@
* @package thrift.test
*/
-namespace test\Thrift\Protocol;
+namespace Test\Thrift\Protocol;
use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Serializer\TBinarySerializer;
@@ -62,4 +62,3 @@
}
}
-
diff --git a/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php b/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
index d5aa69c..7ba3441 100755
--- a/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
+++ b/lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
@@ -28,7 +28,6 @@
use Thrift\Transport\TMemoryBuffer;
use Thrift\Protocol\TJSONProtocol;
-
define( 'BUFSIZ', 8192 ); //big enough to read biggest serialized Fixture arg.
require_once __DIR__.'/../../../../lib/Thrift/ClassLoader/ThriftClassLoader.php';
@@ -263,8 +262,8 @@
public function testVoid_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testVoid']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testVoid']
+ );
$args = new \ThriftTest\ThriftTest_testVoid_args();
$args->read( $this->protocol );
}
@@ -272,8 +271,8 @@
public function testString1_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testString1']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testString1']
+ );
$args = new \ThriftTest\ThriftTest_testString_args();
$args->read( $this->protocol );
@@ -286,8 +285,8 @@
public function testString2_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testString2']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testString2']
+ );
$args = new \ThriftTest\ThriftTest_testString_args();
$args->read( $this->protocol );
@@ -312,8 +311,8 @@
public function testDouble_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testDouble']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testDouble']
+ );
$args = new \ThriftTest\ThriftTest_testDouble_args();
$args->read( $this->protocol );
@@ -326,8 +325,8 @@
public function testByte_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testByte']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testByte']
+ );
$args = new \ThriftTest\ThriftTest_testByte_args();
$args->read( $this->protocol );
@@ -340,8 +339,8 @@
public function testI32_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testI32']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testI32']
+ );
$args = new \ThriftTest\ThriftTest_testI32_args();
$args->read( $this->protocol );
@@ -354,8 +353,8 @@
public function testI64_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testI64']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testI64']
+ );
$args = new \ThriftTest\ThriftTest_testI64_args();
$args->read( $this->protocol );
@@ -369,8 +368,8 @@
public function testStruct_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testStruct']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testStruct']
+ );
$args = new \ThriftTest\ThriftTest_testStruct_args();
$args->read( $this->protocol );
@@ -384,8 +383,8 @@
public function testNest_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testNest']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testNest']
+ );
$args = new \ThriftTest\ThriftTest_testNest_args();
$args->read( $this->protocol );
@@ -399,8 +398,8 @@
public function testMap_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testMap']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testMap']
+ );
$args = new \ThriftTest\ThriftTest_testMap_args();
$args->read( $this->protocol );
@@ -414,8 +413,8 @@
public function testStringMap_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testStringMap']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testStringMap']
+ );
$args = new \ThriftTest\ThriftTest_testStringMap_args();
$args->read( $this->protocol );
@@ -429,8 +428,8 @@
public function testSet_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testSet']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testSet']
+ );
$args = new \ThriftTest\ThriftTest_testSet_args();
$args->read( $this->protocol );
@@ -444,8 +443,8 @@
public function testList_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testList']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testList']
+ );
$args = new \ThriftTest\ThriftTest_testList_args();
$args->read( $this->protocol );
@@ -459,8 +458,8 @@
public function testEnum_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testEnum']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testEnum']
+ );
$args = new \ThriftTest\ThriftTest_testEnum_args();
$args->read( $this->protocol );
@@ -474,8 +473,8 @@
public function testTypedef_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testTypedef']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testTypedef']
+ );
$args = new \ThriftTest\ThriftTest_testTypedef_args();
$args->read( $this->protocol );
@@ -488,8 +487,8 @@
public function testMapMap_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testMapMap']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testMapMap']
+ );
$result = new \ThriftTest\ThriftTest_testMapMap_result();
$result->read( $this->protocol );
@@ -502,8 +501,8 @@
public function testInsanity_Read()
{
$this->transport->write(
- TestTJSONProtocol_Fixtures::$testArgsJSON['testInsanity']
- );
+ TestTJSONProtocol_Fixtures::$testArgsJSON['testInsanity']
+ );
$result = new \ThriftTest\ThriftTest_testInsanity_result();
$result->read( $this->protocol );
@@ -535,14 +534,11 @@
self::$testArgsJSON['testI32'] = '{"1":{"i32":1073741824}}';
- if ( PHP_INT_SIZE == 8 )
- {
+ if (PHP_INT_SIZE == 8) {
self::$testArgsJSON['testI64'] = '{"1":{"i64":'.pow( 2, 60 ).'}}';
self::$testArgsJSON['testStruct'] = '{"1":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":'.pow( 2, 60 ).'}}}}';
self::$testArgsJSON['testNest'] = '{"1":{"rec":{"1":{"i8":1},"2":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":'.pow( 2, 60 ).'}}},"3":{"i32":32768}}}}';
- }
- else
- {
+ } else {
self::$testArgsJSON['testI64'] = '{"1":{"i64":1152921504606847000}}';
self::$testArgsJSON['testStruct'] = '{"1":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":1152921504606847000}}}}';
self::$testArgsJSON['testNest'] = '{"1":{"rec":{"1":{"i8":1},"2":{"rec":{"1":{"str":"worked"},"4":{"i8":1},"9":{"i32":1073741824},"11":{"i64":1152921504606847000}}},"3":{"i32":32768}}}}';
diff --git a/lib/php/test/Test/Thrift/TestValidators.php b/lib/php/test/Test/Thrift/TestValidators.php
index 4c92404..36cf000 100644
--- a/lib/php/test/Test/Thrift/TestValidators.php
+++ b/lib/php/test/Test/Thrift/TestValidators.php
@@ -38,11 +38,11 @@
// Would be nice to have PHPUnit here, but for now just hack it.
-set_exception_handler(function($e) {
+set_exception_handler(function ($e) {
my_assert(false, "Unexpected exception caught: " . $e->getMessage());
});
-set_error_handler(function($errno, $errmsg) {
+set_error_handler(function ($errno, $errmsg) {
my_assert(false, "Unexpected PHP error: " . $errmsg);
});
@@ -66,7 +66,7 @@
$bonk = new \ThriftTest\Bonk();
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocol($transport);
- assert_protocol_exception_thrown(function() use ($bonk, $protocol) { $bonk->write($protocol); },
+ assert_protocol_exception_thrown(function () use ($bonk, $protocol) { $bonk->write($protocol); },
'Bonk was able to write an empty object');
}
}
@@ -80,7 +80,7 @@
$structa = new \ThriftTest\StructA();
$transport = new TMemoryBuffer();
$protocol = new TBinaryProtocol($transport);
- assert_protocol_exception_thrown(function() use ($structa, $protocol) { $structa->write($protocol); },
+ assert_protocol_exception_thrown(function () use ($structa, $protocol) { $structa->write($protocol); },
'StructA was able to write an empty object');
}
{
@@ -100,27 +100,32 @@
assert_has_no_read_validator('TestValidators\TestService_test_result');
assert_has_no_write_validator('TestValidators\TestService_test_result');
-function assert_has_a_read_validator($class) {
+function assert_has_a_read_validator($class)
+{
my_assert(has_read_validator_method($class),
$class . ' class should have a read validator');
}
-function assert_has_no_read_validator($class) {
+function assert_has_no_read_validator($class)
+{
my_assert(!has_read_validator_method($class),
$class . ' class should not have a read validator');
}
-function assert_has_a_write_validator($class) {
+function assert_has_a_write_validator($class)
+{
my_assert(has_write_validator_method($class),
$class . ' class should have a write validator');
}
-function assert_has_no_write_validator($class) {
+function assert_has_no_write_validator($class)
+{
my_assert(!has_write_validator_method($class),
$class . ' class should not have a write validator');
}
-function assert_protocol_exception_thrown($callable, $message) {
+function assert_protocol_exception_thrown($callable, $message)
+{
try {
call_user_func($callable);
my_assert(false, $message);
@@ -128,17 +133,22 @@
}
}
-function has_write_validator_method($class) {
+function has_write_validator_method($class)
+{
$rc = new \ReflectionClass($class);
+
return $rc->hasMethod('_validateForWrite');
}
-function has_read_validator_method($class) {
+function has_read_validator_method($class)
+{
$rc = new \ReflectionClass($class);
+
return $rc->hasMethod('_validateForRead');
}
-function my_assert($something, $message) {
+function my_assert($something, $message)
+{
if (!$something) {
fwrite(STDERR, basename(__FILE__) . " FAILED: $message\n");
exit(1);