http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Protocol/TProtocol.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Protocol/TProtocol.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Protocol/TProtocol.php deleted file mode 100644 index 380ff10..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Protocol/TProtocol.php +++ /dev/null @@ -1,340 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.protocol - */ - -namespace Thrift\Protocol; - -use Thrift\Type\TType; -use Thrift\Exception\TProtocolException; - -/** - * Protocol base class module. - */ -abstract class TProtocol { - - /** - * Underlying transport - * - * @var TTransport - */ - protected $trans_; - - /** - * Constructor - */ - protected function __construct($trans) { - $this->trans_ = $trans; - } - - /** - * Accessor for transport - * - * @return TTransport - */ - public function getTransport() { - return $this->trans_; - } - - /** - * 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 - */ - public abstract function writeMessageBegin($name, $type, $seqid); - - /** - * Close the message - */ - public abstract function writeMessageEnd(); - - /** - * Writes a struct header. - * - * @param string $name Struct name - * @throws TException on write error - * @return int How many bytes written - */ - public abstract function writeStructBegin($name); - - /** - * Close a struct. - * - * @throws TException on write error - * @return int How many bytes written - */ - public abstract function writeStructEnd(); - - /* - * Starts a field. - * - * @param string $name Field name - * @param int $type Field type - * @param int $fid Field id - * @throws TException on write error - * @return int How many bytes written - */ - public abstract function writeFieldBegin($fieldName, $fieldType, $fieldId); - - public abstract function writeFieldEnd(); - - public abstract function writeFieldStop(); - - public abstract function writeMapBegin($keyType, $valType, $size); - - public abstract function writeMapEnd(); - - public abstract function writeListBegin($elemType, $size); - - public abstract function writeListEnd(); - - public abstract function writeSetBegin($elemType, $size); - - public abstract function writeSetEnd(); - - public abstract function writeBool($bool); - - public abstract function writeByte($byte); - - public abstract function writeI16($i16); - - public abstract function writeI32($i32); - - public abstract function writeI64($i64); - - public abstract function writeDouble($dub); - - public abstract function writeString($str); - - /** - * Reads the message header - * - * @param string $name Function name - * @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); - - /** - * Read the close of message - */ - public abstract function readMessageEnd(); - - public abstract function readStructBegin(&$name); - - public abstract function readStructEnd(); - - public abstract function readFieldBegin(&$name, &$fieldType, &$fieldId); - - public abstract function readFieldEnd(); - - public abstract function readMapBegin(&$keyType, &$valType, &$size); - - public abstract function readMapEnd(); - - public abstract function readListBegin(&$elemType, &$size); - - public abstract function readListEnd(); - - public abstract function readSetBegin(&$elemType, &$size); - - public abstract function readSetEnd(); - - public abstract function readBool(&$bool); - - public abstract function readByte(&$byte); - - public abstract function readI16(&$i16); - - public abstract function readI32(&$i32); - - public abstract function readI64(&$i64); - - public abstract function readDouble(&$dub); - - public abstract function readString(&$str); - - /** - * The skip function is a utility to parse over unrecognized date without - * causing corruption. - * - * @param TType $type What type is it - */ - public function skip($type) { - switch ($type) { - case TType::BOOL: - return $this->readBool($bool); - case TType::BYTE: - return $this->readByte($byte); - case TType::I16: - return $this->readI16($i16); - case TType::I32: - return $this->readI32($i32); - case TType::I64: - return $this->readI64($i64); - case TType::DOUBLE: - return $this->readDouble($dub); - case TType::STRING: - return $this->readString($str); - case TType::STRUCT: - { - $result = $this->readStructBegin($name); - while (true) { - $result += $this->readFieldBegin($name, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - $result += $this->skip($ftype); - $result += $this->readFieldEnd(); - } - $result += $this->readStructEnd(); - return $result; - } - case TType::MAP: - { - $result = $this->readMapBegin($keyType, $valType, $size); - for ($i = 0; $i < $size; $i++) { - $result += $this->skip($keyType); - $result += $this->skip($valType); - } - $result += $this->readMapEnd(); - return $result; - } - case TType::SET: - { - $result = $this->readSetBegin($elemType, $size); - for ($i = 0; $i < $size; $i++) { - $result += $this->skip($elemType); - } - $result += $this->readSetEnd(); - return $result; - } - case TType::LST: - { - $result = $this->readListBegin($elemType, $size); - for ($i = 0; $i < $size; $i++) { - $result += $this->skip($elemType); - } - $result += $this->readListEnd(); - return $result; - } - default: - throw new TProtocolException('Unknown field type: '.$type, - TProtocolException::INVALID_DATA); - } - } - - /** - * Utility for skipping binary data - * - * @param TTransport $itrans TTransport object - * @param int $type Field type - */ - public static function skipBinary($itrans, $type) { - switch ($type) { - case TType::BOOL: - return $itrans->readAll(1); - case TType::BYTE: - return $itrans->readAll(1); - case TType::I16: - return $itrans->readAll(2); - case TType::I32: - return $itrans->readAll(4); - case TType::I64: - return $itrans->readAll(8); - case TType::DOUBLE: - return $itrans->readAll(8); - case TType::STRING: - $len = unpack('N', $itrans->readAll(4)); - $len = $len[1]; - if ($len > 0x7fffffff) { - $len = 0 - (($len - 1) ^ 0xffffffff); - } - return 4 + $itrans->readAll($len); - case TType::STRUCT: - { - $result = 0; - while (true) { - $ftype = 0; - $fid = 0; - $data = $itrans->readAll(1); - $arr = unpack('c', $data); - $ftype = $arr[1]; - if ($ftype == TType::STOP) { - break; - } - // I16 field id - $result += $itrans->readAll(2); - $result += self::skipBinary($itrans, $ftype); - } - return $result; - } - case TType::MAP: - { - // Ktype - $data = $itrans->readAll(1); - $arr = unpack('c', $data); - $ktype = $arr[1]; - // Vtype - $data = $itrans->readAll(1); - $arr = unpack('c', $data); - $vtype = $arr[1]; - // Size - $data = $itrans->readAll(4); - $arr = unpack('N', $data); - $size = $arr[1]; - if ($size > 0x7fffffff) { - $size = 0 - (($size - 1) ^ 0xffffffff); - } - $result = 6; - for ($i = 0; $i < $size; $i++) { - $result += self::skipBinary($itrans, $ktype); - $result += self::skipBinary($itrans, $vtype); - } - return $result; - } - case TType::SET: - case TType::LST: - { - // Vtype - $data = $itrans->readAll(1); - $arr = unpack('c', $data); - $vtype = $arr[1]; - // Size - $data = $itrans->readAll(4); - $arr = unpack('N', $data); - $size = $arr[1]; - if ($size > 0x7fffffff) { - $size = 0 - (($size - 1) ^ 0xffffffff); - } - $result = 5; - for ($i = 0; $i < $size; $i++) { - $result += self::skipBinary($itrans, $vtype); - } - return $result; - } - default: - throw new TProtocolException('Unknown field type: '.$type, - TProtocolException::INVALID_DATA); - } - } -}
http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Serializer/TBinarySerializer.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Serializer/TBinarySerializer.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Serializer/TBinarySerializer.php deleted file mode 100644 index 2a7cc3e..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Serializer/TBinarySerializer.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.protocol - * @author: rmarin ([email protected]) - */ - -namespace Thrift\Serializer; - -use Thrift\Transport\TMemoryBuffer; -use Thrift\Protocol\TBinaryProtocolAccelerated; -use Thrift\Type\TMessageType; - -/** - * Utility class for serializing and deserializing - * a thrift object using TBinaryProtocolAccelerated. - */ -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) { - $transport = new TMemoryBuffer(); - $protocol = new TBinaryProtocolAccelerated($transport); - if (function_exists('thrift_protocol_write_binary')) { - thrift_protocol_write_binary($protocol, $object->getName(), - TMessageType::REPLY, $object, - 0, $protocol->isStrictWrite()); - - $protocol->readMessageBegin($unused_name, $unused_type, - $unused_seqid); - } else { - $object->write($protocol); - } - $protocol->getTransport()->flush(); - return $transport->getBuffer(); - } - - public static function deserialize($string_object, $class_name) { - $transport = new TMemoryBuffer(); - $protocol = new TBinaryProtocolAccelerated($transport); - if (function_exists('thrift_protocol_read_binary')) { - $protocol->writeMessageBegin('', TMessageType::REPLY, 0); - $transport->write($string_object); - return thrift_protocol_read_binary($protocol, $class_name, - $protocol->isStrictRead()); - } else { - $transport->write($string_object); - $object = new $class_name(); - $object->read($protocol); - return $object; - } - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TForkingServer.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TForkingServer.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TForkingServer.php deleted file mode 100644 index 6fca305..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TForkingServer.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php - -namespace Thrift\Server; - -use Thrift\Server\TServer; -use Thrift\Transport\TTransport; -use Thrift\Exception\TException; -use Thrift\Exception\TTransportException; - -/** - * A forking implementation of a Thrift server. - * - * @package thrift.server - */ -class TForkingServer extends TServer { - /** - * Flag for the main serving loop - * - * @var bool - */ - private $stop_ = false; - - /** - * List of children. - * - * @var array - */ - protected $children_ = array(); - - /** - * Listens for new client using the supplied - * transport. We fork when a new connection - * arrives. - * - * @return void - */ - public function serve() { - $this->transport_->listen(); - - while (!$this->stop_) { - try { - $transport = $this->transport_->accept(); - - if ($transport != null) { - $pid = pcntl_fork(); - - if ($pid > 0) { - $this->handleParent($transport, $pid); - } - else if ($pid === 0) { - $this->handleChild($transport); - } - else { - throw new TException('Failed to fork'); - } - } - } - catch (TTransportException $e) { } - - $this->collectChildren(); - } - } - - /** - * Code run by the parent - * - * @param TTransport $transport - * @param int $pid - * @return void - */ - private function handleParent(TTransport $transport, $pid) { - $this->children_[$pid] = $transport; - } - - /** - * Code run by the child. - * - * @param TTransport $transport - * @return void - */ - private function handleChild(TTransport $transport) { - try { - $inputTransport = $this->inputTransportFactory_->getTransport($transport); - $outputTransport = $this->outputTransportFactory_->getTransport($transport); - $inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport); - $outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport); - while ($this->processor_->process($inputProtocol, $outputProtocol)) { } - @$transport->close(); - } - catch (TTransportException $e) { } - - exit(0); - } - - /** - * Collects any children we may have - * - * @return void - */ - private function collectChildren() { - foreach ($this->children_ as $pid => $transport) { - if (pcntl_waitpid($pid, $status, WNOHANG) > 0) { - unset($this->children_[$pid]); - if ($transport) @$transport->close(); - } - } - } - - /** - * Stops the server running. Kills the transport - * and then stops the main serving loop - * - * @return void - */ - public function stop() { - $this->transport_->close(); - $this->stop_ = true; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServer.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServer.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServer.php deleted file mode 100644 index 343bf4b..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServer.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php - -namespace Thrift\Server; - -use Thrift\Server\TServerTransport; -use Thrift\Factory\TTransportFactory; -use Thrift\Factory\TProtocolFactory; - -/** - * Generic class for a Thrift server. - * - * @package thrift.server - */ -abstract class TServer { - - /** - * Processor to handle new clients - * - * @var TProcessor - */ - protected $processor_; - - /** - * Server transport to be used for listening - * and accepting new clients - * - * @var TServerTransport - */ - protected $transport_; - - /** - * Input transport factory - * - * @var TTransportFactory - */ - protected $inputTransportFactory_; - - /** - * Output transport factory - * - * @var TTransportFactory - */ - protected $outputTransportFactory_; - - /** - * Input protocol factory - * - * @var TProtocolFactory - */ - protected $inputProtocolFactory_; - - /** - * Output protocol factory - * - * @var TProtocolFactory - */ - protected $outputProtocolFactory_; - - /** - * Sets up all the factories, etc - * - * @param object $processor - * @param TServerTransport $transport - * @param TTransportFactory $inputTransportFactory - * @param TTransportFactory $outputTransportFactory - * @param TProtocolFactory $inputProtocolFactory - * @param TProtocolFactory $outputProtocolFactory - * @return void - */ - public function __construct($processor, - TServerTransport $transport, - TTransportFactory $inputTransportFactory, - TTransportFactory $outputTransportFactory, - TProtocolFactory $inputProtocolFactory, - TProtocolFactory $outputProtocolFactory) { - $this->processor_ = $processor; - $this->transport_ = $transport; - $this->inputTransportFactory_ = $inputTransportFactory; - $this->outputTransportFactory_ = $outputTransportFactory; - $this->inputProtocolFactory_ = $inputProtocolFactory; - $this->outputProtocolFactory_ = $outputProtocolFactory; - } - - /** - * Serves the server. This should never return - * unless a problem permits it to do so or it - * is interrupted intentionally - * - * @abstract - * @return void - */ - abstract public function serve(); - - /** - * Stops the server serving - * - * @abstract - * @return void - */ - abstract public function stop(); -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerSocket.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerSocket.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerSocket.php deleted file mode 100644 index 00a6fb9..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerSocket.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -namespace Thrift\Server; - -use Thrift\Server\TServerTransport; -use Thrift\Transport\TSocket; - -/** - * Socket implementation of a server agent. - * - * @package thrift.transport - */ -class TServerSocket extends TServerTransport { - - /** - * Handle for the listener socket - * - * @var resource - */ - private $listener_; - - /** - * Port for the listener to listen on - * - * @var int - */ - private $port_; - - /** - * Timeout when listening for a new client - * - * @var int - */ - private $acceptTimeout_ = 30000; - - /** - * Host to listen on - * - * @var string - */ - private $host_; - - /** - * ServerSocket constructor - * - * @param string $host Host to listen on - * @param int $port Port to listen on - * @return void - */ - public function __construct($host = 'localhost', $port = 9090) { - $this->host_ = $host; - $this->port_ = $port; - } - - /** - * Sets the accept timeout - * - * @param int $acceptTimeout - * @return void - */ - public function setAcceptTimeout($acceptTimeout) { - $this->acceptTimeout_ = $acceptTimeout; - } - - /** - * Opens a new socket server handle - * - * @return void - */ - public function listen() { - $this->listener_ = stream_socket_server('tcp://' . $this->host_ . ':' . $this->port_); - } - - /** - * Closes the socket server handle - * - * @return void - */ - public function close() { - @fclose($this->listener_); - $this->listener_ = null; - } - - /** - * Implementation of accept. If not client is accepted in the given time - * - * @return TSocket - */ - protected function acceptImpl() { - $handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0); - if(!$handle) return null; - - $socket = new TSocket(); - $socket->setHandle($handle); - - return $socket; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerTransport.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerTransport.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerTransport.php deleted file mode 100644 index 5324712..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TServerTransport.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Thrift\Server; - -use Thrift\Exception\TTransportException; - -/** - * Generic class for Server agent. - * - * @package thrift.transport - */ -abstract class TServerTransport { - /** - * List for new clients - * - * @abstract - * @return void - */ - abstract public function listen(); - - /** - * Close the server - * - * @abstract - * @return void - */ - abstract public function close(); - - /** - * Subclasses should use this to implement - * accept. - * - * @abstract - * @return TTransport - */ - protected abstract function acceptImpl(); - - /** - * Uses the accept implemtation. If null is returned, an - * exception is thrown. - * - * @throws TTransportException - * @return TTransport - */ - public function accept() { - $transport = $this->acceptImpl(); - - if ($transport == null) { - throw new TTransportException("accept() may not return NULL"); - } - - return $transport; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TSimpleServer.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TSimpleServer.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TSimpleServer.php deleted file mode 100644 index 790e48f..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Server/TSimpleServer.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -namespace Thrift\Server; - -use Thrift\Server\TServer; -use Thrift\Exception\TTransportException; - -/** - * Simple implemtation of a Thrift server. - * - * @package thrift.server - */ -class TSimpleServer extends TServer { - /** - * Flag for the main serving loop - * - * @var bool - */ - private $stop_ = false; - - /** - * Listens for new client using the supplied - * transport. It handles TTransportExceptions - * to avoid timeouts etc killing it - * - * @return void - */ - public function serve() { - $this->transport_->listen(); - - while (!$this->stop_) { - try { - $transport = $this->transport_->accept(); - - if ($transport != null) { - $inputTransport = $this->inputTransportFactory_->getTransport($transport); - $outputTransport = $this->outputTransportFactory_->getTransport($transport); - $inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport); - $outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport); - while ($this->processor_->process($inputProtocol, $outputProtocol)) { } - } - } - catch (TTransportException $e) { } - } - } - - /** - * Stops the server running. Kills the transport - * and then stops the main serving loop - * - * @return void - */ - public function stop() { - $this->transport_->close(); - $this->stop_ = true; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Core.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Core.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Core.php deleted file mode 100644 index e38a5b2..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Core.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -namespace Thrift\StringFunc; - -use Thrift\StringFunc\TStringFunc; - -class Core implements TStringFunc { - public function substr($str, $start, $length = null) { - // specifying a null $length would return an empty string - if($length === null) { - return substr($str, $start); - } - return substr($str, $start, $length); - } - - public function strlen($str) { - return strlen($str); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Mbstring.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Mbstring.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Mbstring.php deleted file mode 100644 index c1ace13..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/Mbstring.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -namespace Thrift\StringFunc; - -use Thrift\StringFunc\TStringFunc; - -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 - * be null or false as a "magic" value because that would - * cause an empty string to be returned, so we need to - * actually calculate the proper length value. - */ - if($length === null) { - $length = $this->strlen($str) - $start; - } - - return mb_substr($str, $start, $length, '8bit'); - } - - public function strlen($str) { - return mb_strlen($str, '8bit'); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/TStringFunc.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/TStringFunc.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/TStringFunc.php deleted file mode 100644 index c5bb390..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/StringFunc/TStringFunc.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -namespace Thrift\StringFunc; - -interface TStringFunc { - public function substr($str, $start, $length = null); - public function strlen($str); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Thrift.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Thrift.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Thrift.php deleted file mode 100644 index c845395..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Thrift.php +++ /dev/null @@ -1,789 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift - */ - - -/** - * Data types that can be sent via Thrift - */ -class TType { - const STOP = 0; - const VOID = 1; - const BOOL = 2; - const BYTE = 3; - const I08 = 3; - const DOUBLE = 4; - const I16 = 6; - const I32 = 8; - const I64 = 10; - const STRING = 11; - const UTF7 = 11; - const STRUCT = 12; - const MAP = 13; - const SET = 14; - const LST = 15; // N.B. cannot use LIST keyword in PHP! - const UTF8 = 16; - const UTF16 = 17; -} - -/** - * Message types for RPC - */ -class TMessageType { - const CALL = 1; - const REPLY = 2; - const EXCEPTION = 3; - const ONEWAY = 4; -} - -/** - * NOTE(mcslee): This currently contains a ton of duplicated code from TBase - * because we need to save CPU cycles and this is not yet in an extension. - * Ideally we'd multiply-inherit TException from both Exception and Base, but - * that's not possible in PHP and there are no modules either, so for now we - * apologetically take a trip to HackTown. - * - * Can be called with standard Exception constructor (message, code) or with - * Thrift Base object constructor (spec, vals). - * - * @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) { - if (is_array($p1) && is_array($p2)) { - $spec = $p1; - $vals = $p2; - foreach ($spec as $fid => $fspec) { - $var = $fspec['var']; - if (isset($vals[$var])) { - $this->$var = $vals[$var]; - } - } - } else { - parent::__construct($p1, $p2); - } - } - - static $tmethod = array(TType::BOOL => 'Bool', - TType::BYTE => 'Byte', - TType::I16 => 'I16', - TType::I32 => 'I32', - TType::I64 => 'I64', - TType::DOUBLE => 'Double', - TType::STRING => 'String'); - - private function _readMap(&$var, $spec, $input) { - $xfer = 0; - $ktype = $spec['ktype']; - $vtype = $spec['vtype']; - $kread = $vread = null; - if (isset(TBase::$tmethod[$ktype])) { - $kread = 'read'.TBase::$tmethod[$ktype]; - } else { - $kspec = $spec['key']; - } - if (isset(TBase::$tmethod[$vtype])) { - $vread = 'read'.TBase::$tmethod[$vtype]; - } else { - $vspec = $spec['val']; - } - $var = array(); - $_ktype = $_vtype = $size = 0; - $xfer += $input->readMapBegin($_ktype, $_vtype, $size); - for ($i = 0; $i < $size; ++$i) { - $key = $val = null; - if ($kread !== null) { - $xfer += $input->$kread($key); - } else { - switch ($ktype) { - case TType::STRUCT: - $class = $kspec['class']; - $key = new $class(); - $xfer += $key->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($key, $kspec, $input); - break; - case TType::LST: - $xfer += $this->_readList($key, $kspec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($key, $kspec, $input, true); - break; - } - } - if ($vread !== null) { - $xfer += $input->$vread($val); - } else { - switch ($vtype) { - case TType::STRUCT: - $class = $vspec['class']; - $val = new $class(); - $xfer += $val->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($val, $vspec, $input); - break; - case TType::LST: - $xfer += $this->_readList($val, $vspec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($val, $vspec, $input, true); - break; - } - } - $var[$key] = $val; - } - $xfer += $input->readMapEnd(); - return $xfer; - } - - private function _readList(&$var, $spec, $input, $set=false) { - $xfer = 0; - $etype = $spec['etype']; - $eread = $vread = null; - if (isset(TBase::$tmethod[$etype])) { - $eread = 'read'.TBase::$tmethod[$etype]; - } else { - $espec = $spec['elem']; - } - $var = array(); - $_etype = $size = 0; - if ($set) { - $xfer += $input->readSetBegin($_etype, $size); - } else { - $xfer += $input->readListBegin($_etype, $size); - } - for ($i = 0; $i < $size; ++$i) { - $elem = null; - if ($eread !== null) { - $xfer += $input->$eread($elem); - } else { - $espec = $spec['elem']; - switch ($etype) { - case TType::STRUCT: - $class = $espec['class']; - $elem = new $class(); - $xfer += $elem->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($elem, $espec, $input); - break; - case TType::LST: - $xfer += $this->_readList($elem, $espec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($elem, $espec, $input, true); - break; - } - } - if ($set) { - $var[$elem] = true; - } else { - $var []= $elem; - } - } - if ($set) { - $xfer += $input->readSetEnd(); - } else { - $xfer += $input->readListEnd(); - } - return $xfer; - } - - protected function _read($class, $spec, $input) { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - if (isset($spec[$fid])) { - $fspec = $spec[$fid]; - $var = $fspec['var']; - if ($ftype == $fspec['type']) { - $xfer = 0; - if (isset(TBase::$tmethod[$ftype])) { - $func = 'read'.TBase::$tmethod[$ftype]; - $xfer += $input->$func($this->$var); - } else { - switch ($ftype) { - case TType::STRUCT: - $class = $fspec['class']; - $this->$var = new $class(); - $xfer += $this->$var->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($this->$var, $fspec, $input); - break; - case TType::LST: - $xfer += $this->_readList($this->$var, $fspec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($this->$var, $fspec, $input, true); - break; - } - } - } else { - $xfer += $input->skip($ftype); - } - } else { - $xfer += $input->skip($ftype); - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - private function _writeMap($var, $spec, $output) { - $xfer = 0; - $ktype = $spec['ktype']; - $vtype = $spec['vtype']; - $kwrite = $vwrite = null; - if (isset(TBase::$tmethod[$ktype])) { - $kwrite = 'write'.TBase::$tmethod[$ktype]; - } else { - $kspec = $spec['key']; - } - if (isset(TBase::$tmethod[$vtype])) { - $vwrite = 'write'.TBase::$tmethod[$vtype]; - } else { - $vspec = $spec['val']; - } - $xfer += $output->writeMapBegin($ktype, $vtype, count($var)); - foreach ($var as $key => $val) { - if (isset($kwrite)) { - $xfer += $output->$kwrite($key); - } else { - switch ($ktype) { - case TType::STRUCT: - $xfer += $key->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($key, $kspec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($key, $kspec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($key, $kspec, $output, true); - break; - } - } - if (isset($vwrite)) { - $xfer += $output->$vwrite($val); - } else { - switch ($vtype) { - case TType::STRUCT: - $xfer += $val->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($val, $vspec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($val, $vspec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($val, $vspec, $output, true); - break; - } - } - } - $xfer += $output->writeMapEnd(); - return $xfer; - } - - private function _writeList($var, $spec, $output, $set=false) { - $xfer = 0; - $etype = $spec['etype']; - $ewrite = null; - if (isset(TBase::$tmethod[$etype])) { - $ewrite = 'write'.TBase::$tmethod[$etype]; - } else { - $espec = $spec['elem']; - } - if ($set) { - $xfer += $output->writeSetBegin($etype, count($var)); - } else { - $xfer += $output->writeListBegin($etype, count($var)); - } - foreach ($var as $key => $val) { - $elem = $set ? $key : $val; - if (isset($ewrite)) { - $xfer += $output->$ewrite($elem); - } else { - switch ($etype) { - case TType::STRUCT: - $xfer += $elem->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($elem, $espec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($elem, $espec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($elem, $espec, $output, true); - break; - } - } - } - if ($set) { - $xfer += $output->writeSetEnd(); - } else { - $xfer += $output->writeListEnd(); - } - return $xfer; - } - - protected function _write($class, $spec, $output) { - $xfer = 0; - $xfer += $output->writeStructBegin($class); - foreach ($spec as $fid => $fspec) { - $var = $fspec['var']; - if ($this->$var !== null) { - $ftype = $fspec['type']; - $xfer += $output->writeFieldBegin($var, $ftype, $fid); - if (isset(TBase::$tmethod[$ftype])) { - $func = 'write'.TBase::$tmethod[$ftype]; - $xfer += $output->$func($this->$var); - } else { - switch ($ftype) { - case TType::STRUCT: - $xfer += $this->$var->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($this->$var, $fspec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($this->$var, $fspec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($this->$var, $fspec, $output, true); - break; - } - } - $xfer += $output->writeFieldEnd(); - } - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } - -} - -/** - * Base class from which other Thrift structs extend. This is so that we can - * cut back on the size of the generated code which is turning out to have a - * nontrivial cost just to load thanks to the wondrously abysmal implementation - * 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 { - - static $tmethod = array(TType::BOOL => 'Bool', - TType::BYTE => 'Byte', - TType::I16 => 'I16', - TType::I32 => 'I32', - TType::I64 => 'I64', - TType::DOUBLE => 'Double', - TType::STRING => 'String'); - - abstract function read($input); - - abstract function write($output); - - public function __construct($spec=null, $vals=null) { - if (is_array($spec) && is_array($vals)) { - foreach ($spec as $fid => $fspec) { - $var = $fspec['var']; - if (isset($vals[$var])) { - $this->$var = $vals[$var]; - } - } - } - } - - private function _readMap(&$var, $spec, $input) { - $xfer = 0; - $ktype = $spec['ktype']; - $vtype = $spec['vtype']; - $kread = $vread = null; - if (isset(TBase::$tmethod[$ktype])) { - $kread = 'read'.TBase::$tmethod[$ktype]; - } else { - $kspec = $spec['key']; - } - if (isset(TBase::$tmethod[$vtype])) { - $vread = 'read'.TBase::$tmethod[$vtype]; - } else { - $vspec = $spec['val']; - } - $var = array(); - $_ktype = $_vtype = $size = 0; - $xfer += $input->readMapBegin($_ktype, $_vtype, $size); - for ($i = 0; $i < $size; ++$i) { - $key = $val = null; - if ($kread !== null) { - $xfer += $input->$kread($key); - } else { - switch ($ktype) { - case TType::STRUCT: - $class = $kspec['class']; - $key = new $class(); - $xfer += $key->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($key, $kspec, $input); - break; - case TType::LST: - $xfer += $this->_readList($key, $kspec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($key, $kspec, $input, true); - break; - } - } - if ($vread !== null) { - $xfer += $input->$vread($val); - } else { - switch ($vtype) { - case TType::STRUCT: - $class = $vspec['class']; - $val = new $class(); - $xfer += $val->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($val, $vspec, $input); - break; - case TType::LST: - $xfer += $this->_readList($val, $vspec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($val, $vspec, $input, true); - break; - } - } - $var[$key] = $val; - } - $xfer += $input->readMapEnd(); - return $xfer; - } - - private function _readList(&$var, $spec, $input, $set=false) { - $xfer = 0; - $etype = $spec['etype']; - $eread = $vread = null; - if (isset(TBase::$tmethod[$etype])) { - $eread = 'read'.TBase::$tmethod[$etype]; - } else { - $espec = $spec['elem']; - } - $var = array(); - $_etype = $size = 0; - if ($set) { - $xfer += $input->readSetBegin($_etype, $size); - } else { - $xfer += $input->readListBegin($_etype, $size); - } - for ($i = 0; $i < $size; ++$i) { - $elem = null; - if ($eread !== null) { - $xfer += $input->$eread($elem); - } else { - $espec = $spec['elem']; - switch ($etype) { - case TType::STRUCT: - $class = $espec['class']; - $elem = new $class(); - $xfer += $elem->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($elem, $espec, $input); - break; - case TType::LST: - $xfer += $this->_readList($elem, $espec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($elem, $espec, $input, true); - break; - } - } - if ($set) { - $var[$elem] = true; - } else { - $var []= $elem; - } - } - if ($set) { - $xfer += $input->readSetEnd(); - } else { - $xfer += $input->readListEnd(); - } - return $xfer; - } - - protected function _read($class, $spec, $input) { - $xfer = 0; - $fname = null; - $ftype = 0; - $fid = 0; - $xfer += $input->readStructBegin($fname); - while (true) { - $xfer += $input->readFieldBegin($fname, $ftype, $fid); - if ($ftype == TType::STOP) { - break; - } - if (isset($spec[$fid])) { - $fspec = $spec[$fid]; - $var = $fspec['var']; - if ($ftype == $fspec['type']) { - $xfer = 0; - if (isset(TBase::$tmethod[$ftype])) { - $func = 'read'.TBase::$tmethod[$ftype]; - $xfer += $input->$func($this->$var); - } else { - switch ($ftype) { - case TType::STRUCT: - $class = $fspec['class']; - $this->$var = new $class(); - $xfer += $this->$var->read($input); - break; - case TType::MAP: - $xfer += $this->_readMap($this->$var, $fspec, $input); - break; - case TType::LST: - $xfer += $this->_readList($this->$var, $fspec, $input, false); - break; - case TType::SET: - $xfer += $this->_readList($this->$var, $fspec, $input, true); - break; - } - } - } else { - $xfer += $input->skip($ftype); - } - } else { - $xfer += $input->skip($ftype); - } - $xfer += $input->readFieldEnd(); - } - $xfer += $input->readStructEnd(); - return $xfer; - } - - private function _writeMap($var, $spec, $output) { - $xfer = 0; - $ktype = $spec['ktype']; - $vtype = $spec['vtype']; - $kwrite = $vwrite = null; - if (isset(TBase::$tmethod[$ktype])) { - $kwrite = 'write'.TBase::$tmethod[$ktype]; - } else { - $kspec = $spec['key']; - } - if (isset(TBase::$tmethod[$vtype])) { - $vwrite = 'write'.TBase::$tmethod[$vtype]; - } else { - $vspec = $spec['val']; - } - $xfer += $output->writeMapBegin($ktype, $vtype, count($var)); - foreach ($var as $key => $val) { - if (isset($kwrite)) { - $xfer += $output->$kwrite($key); - } else { - switch ($ktype) { - case TType::STRUCT: - $xfer += $key->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($key, $kspec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($key, $kspec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($key, $kspec, $output, true); - break; - } - } - if (isset($vwrite)) { - $xfer += $output->$vwrite($val); - } else { - switch ($vtype) { - case TType::STRUCT: - $xfer += $val->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($val, $vspec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($val, $vspec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($val, $vspec, $output, true); - break; - } - } - } - $xfer += $output->writeMapEnd(); - return $xfer; - } - - private function _writeList($var, $spec, $output, $set=false) { - $xfer = 0; - $etype = $spec['etype']; - $ewrite = null; - if (isset(TBase::$tmethod[$etype])) { - $ewrite = 'write'.TBase::$tmethod[$etype]; - } else { - $espec = $spec['elem']; - } - if ($set) { - $xfer += $output->writeSetBegin($etype, count($var)); - } else { - $xfer += $output->writeListBegin($etype, count($var)); - } - foreach ($var as $key => $val) { - $elem = $set ? $key : $val; - if (isset($ewrite)) { - $xfer += $output->$ewrite($elem); - } else { - switch ($etype) { - case TType::STRUCT: - $xfer += $elem->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($elem, $espec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($elem, $espec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($elem, $espec, $output, true); - break; - } - } - } - if ($set) { - $xfer += $output->writeSetEnd(); - } else { - $xfer += $output->writeListEnd(); - } - return $xfer; - } - - protected function _write($class, $spec, $output) { - $xfer = 0; - $xfer += $output->writeStructBegin($class); - foreach ($spec as $fid => $fspec) { - $var = $fspec['var']; - if ($this->$var !== null) { - $ftype = $fspec['type']; - $xfer += $output->writeFieldBegin($var, $ftype, $fid); - if (isset(TBase::$tmethod[$ftype])) { - $func = 'write'.TBase::$tmethod[$ftype]; - $xfer += $output->$func($this->$var); - } else { - switch ($ftype) { - case TType::STRUCT: - $xfer += $this->$var->write($output); - break; - case TType::MAP: - $xfer += $this->_writeMap($this->$var, $fspec, $output); - break; - case TType::LST: - $xfer += $this->_writeList($this->$var, $fspec, $output, false); - break; - case TType::SET: - $xfer += $this->_writeList($this->$var, $fspec, $output, true); - break; - } - } - $xfer += $output->writeFieldEnd(); - } - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} - -class TApplicationException extends TException { - static $_TSPEC = - array(1 => array('var' => 'message', - 'type' => TType::STRING), - 2 => array('var' => 'code', - 'type' => TType::I32)); - - const UNKNOWN = 0; - const UNKNOWN_METHOD = 1; - const INVALID_MESSAGE_TYPE = 2; - const WRONG_METHOD_NAME = 3; - const BAD_SEQUENCE_ID = 4; - const MISSING_RESULT = 5; - const INTERNAL_ERROR = 6; - const PROTOCOL_ERROR = 7; - - function __construct($message=null, $code=0) { - parent::__construct($message, $code); - } - - public function read($output) { - return $this->_read('TApplicationException', self::$_TSPEC, $output); - } - - public function write($output) { - $xfer = 0; - $xfer += $output->writeStructBegin('TApplicationException'); - if ($message = $this->getMessage()) { - $xfer += $output->writeFieldBegin('message', TType::STRING, 1); - $xfer += $output->writeString($message); - $xfer += $output->writeFieldEnd(); - } - if ($code = $this->getCode()) { - $xfer += $output->writeFieldBegin('type', TType::I32, 2); - $xfer += $output->writeI32($code); - $xfer += $output->writeFieldEnd(); - } - $xfer += $output->writeFieldStop(); - $xfer += $output->writeStructEnd(); - return $xfer; - } -} - -/** - * Set global THRIFT ROOT automatically via inclusion here - */ -if (!isset($GLOBALS['THRIFT_ROOT'])) { - $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__); -} -include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php'; -include_once $GLOBALS['THRIFT_ROOT'].'/transport/TTransport.php'; -include_once $GLOBALS['THRIFT_ROOT'].'/TStringUtils.php'; - http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TBufferedTransport.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TBufferedTransport.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TBufferedTransport.php deleted file mode 100644 index 0d3ad98..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TBufferedTransport.php +++ /dev/null @@ -1,165 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.transport - */ - -namespace Thrift\Transport; - -use Thrift\Transport\TTransport; -use Thrift\Factory\TStringFuncFactory; - -/** - * Buffered transport. Stores data to an internal buffer that it doesn't - * actually write out until flush is called. For reading, we do a greedy - * read and then serve data out of the internal buffer. - * - * @package thrift.transport - */ -class TBufferedTransport extends TTransport { - - /** - * Constructor. Creates a buffered transport around an underlying transport - */ - public function __construct($transport=null, $rBufSize=512, $wBufSize=512) { - $this->transport_ = $transport; - $this->rBufSize_ = $rBufSize; - $this->wBufSize_ = $wBufSize; - } - - /** - * The underlying transport - * - * @var TTransport - */ - protected $transport_ = null; - - /** - * The receive buffer size - * - * @var int - */ - protected $rBufSize_ = 512; - - /** - * The write buffer size - * - * @var int - */ - protected $wBufSize_ = 512; - - /** - * The write buffer. - * - * @var string - */ - protected $wBuf_ = ''; - - /** - * The read buffer. - * - * @var string - */ - protected $rBuf_ = ''; - - public function isOpen() { - return $this->transport_->isOpen(); - } - - public function open() { - $this->transport_->open(); - } - - public function close() { - $this->transport_->close(); - } - - public function putBack($data) { - if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) { - $this->rBuf_ = $data; - } else { - $this->rBuf_ = ($data . $this->rBuf_); - } - } - - /** - * The reason that we customize readAll here is that the majority of PHP - * streams are already internally buffered by PHP. The socket stream, for - * example, buffers internally and blocks if you call read with $len greater - * than the amount of data available, unlike recv() in C. - * - * Therefore, use the readAll method of the wrapped transport inside - * the buffered readAll. - */ - public function readAll($len) { - $have = TStringFuncFactory::create()->strlen($this->rBuf_); - if ($have == 0) { - $data = $this->transport_->readAll($len); - } else if ($have < $len) { - $data = $this->rBuf_; - $this->rBuf_ = ''; - $data .= $this->transport_->readAll($len - $have); - } else if ($have == $len) { - $data = $this->rBuf_; - $this->rBuf_ = ''; - } else if ($have > $len) { - $data = TStringFuncFactory::create()->substr($this->rBuf_, 0, $len); - $this->rBuf_ = TStringFuncFactory::create()->substr($this->rBuf_, $len); - } - return $data; - } - - public function read($len) { - if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) { - $this->rBuf_ = $this->transport_->read($this->rBufSize_); - } - - 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) { - $this->wBuf_ .= $buf; - if (TStringFuncFactory::create()->strlen($this->wBuf_) >= $this->wBufSize_) { - $out = $this->wBuf_; - - // Note that we clear the internal wBuf_ prior to the underlying write - // to ensure we're in a sane state (i.e. internal buffer cleaned) - // if the underlying write throws up an exception - $this->wBuf_ = ''; - $this->transport_->write($out); - } - } - - public function flush() { - if (TStringFuncFactory::create()->strlen($this->wBuf_) > 0) { - $this->transport_->write($this->wBuf_); - $this->wBuf_ = ''; - } - $this->transport_->flush(); - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TFramedTransport.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TFramedTransport.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TFramedTransport.php deleted file mode 100644 index d80d548..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TFramedTransport.php +++ /dev/null @@ -1,183 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.transport - */ - -namespace Thrift\Transport; - -use Thrift\Transport\TTransport; -use Thrift\Factory\TStringFuncFactory; - -/** - * Framed transport. Writes and reads data in chunks that are stamped with - * their length. - * - * @package thrift.transport - */ -class TFramedTransport extends TTransport { - - /** - * Underlying transport object. - * - * @var TTransport - */ - private $transport_; - - /** - * Buffer for read data. - * - * @var string - */ - private $rBuf_; - - /** - * Buffer for queued output data - * - * @var string - */ - private $wBuf_; - - /** - * Whether to frame reads - * - * @var bool - */ - private $read_; - - /** - * Whether to frame writes - * - * @var bool - */ - private $write_; - - /** - * Constructor. - * - * @param TTransport $transport Underlying transport - */ - public function __construct($transport=null, $read=true, $write=true) { - $this->transport_ = $transport; - $this->read_ = $read; - $this->write_ = $write; - } - - public function isOpen() { - return $this->transport_->isOpen(); - } - - public function open() { - $this->transport_->open(); - } - - public function close() { - $this->transport_->close(); - } - - /** - * Reads from the buffer. When more data is required reads another entire - * chunk and serves future reads out of that. - * - * @param int $len How much data - */ - public function read($len) { - if (!$this->read_) { - return $this->transport_->read($len); - } - - if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) { - $this->readFrame(); - } - - // Just return full buff - 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; - } - - /** - * Put previously read data back into the buffer - * - * @param string $data data to return - */ - public function putBack($data) { - if (TStringFuncFactory::create()->strlen($this->rBuf_) === 0) { - $this->rBuf_ = $data; - } else { - $this->rBuf_ = ($data . $this->rBuf_); - } - } - - /** - * Reads a chunk of data into the internal read buffer. - */ - private function readFrame() { - $buf = $this->transport_->readAll(4); - $val = unpack('N', $buf); - $sz = $val[1]; - - $this->rBuf_ = $this->transport_->readAll($sz); - } - - /** - * Writes some data to the pending output buffer. - * - * @param string $buf The data - * @param int $len Limit of bytes to write - */ - public function write($buf, $len=null) { - if (!$this->write_) { - return $this->transport_->write($buf, $len); - } - - if ($len !== null && $len < TStringFuncFactory::create()->strlen($buf)) { - $buf = TStringFuncFactory::create()->substr($buf, 0, $len); - } - $this->wBuf_ .= $buf; - } - - /** - * Writes the output buffer to the stream in the format of a 4-byte length - * followed by the actual data. - */ - public function flush() { - if (!$this->write_ || TStringFuncFactory::create()->strlen($this->wBuf_) == 0) { - return $this->transport_->flush(); - } - - $out = pack('N', TStringFuncFactory::create()->strlen($this->wBuf_)); - $out .= $this->wBuf_; - - // Note that we clear the internal wBuf_ prior to the underlying write - // to ensure we're in a sane state (i.e. internal buffer cleaned) - // if the underlying write throws up an exception - $this->wBuf_ = ''; - $this->transport_->write($out); - $this->transport_->flush(); - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/THttpClient.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/THttpClient.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/THttpClient.php deleted file mode 100644 index f46b18a..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/THttpClient.php +++ /dev/null @@ -1,221 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.transport - */ - -namespace Thrift\Transport; - -use Thrift\Transport\TTransport; -use Thrift\Exception\TTransportException; -use Thrift\Factory\TStringFuncFactory; - -/** - * HTTP client for Thrift - * - * @package thrift.transport - */ -class THttpClient extends TTransport { - - /** - * The host to connect to - * - * @var string - */ - protected $host_; - - /** - * The port to connect on - * - * @var int - */ - protected $port_; - - /** - * The URI to request - * - * @var string - */ - protected $uri_; - - /** - * The scheme to use for the request, i.e. http, https - * - * @var string - */ - protected $scheme_; - - /** - * Buffer for the HTTP request data - * - * @var string - */ - protected $buf_; - - /** - * Input socket stream. - * - * @var resource - */ - protected $handle_; - - /** - * Read timeout - * - * @var float - */ - protected $timeout_; - - /** - * http headers - * - * @var array - */ - protected $headers_; - - /** - * Make a new HTTP client. - * - * @param string $host - * @param int $port - * @param string $uri - */ - public function __construct($host, $port=80, $uri='', $scheme = 'http') { - if ((TStringFuncFactory::create()->strlen($uri) > 0) && ($uri{0} != '/')) { - $uri = '/'.$uri; - } - $this->scheme_ = $scheme; - $this->host_ = $host; - $this->port_ = $port; - $this->uri_ = $uri; - $this->buf_ = ''; - $this->handle_ = null; - $this->timeout_ = null; - $this->headers_ = array(); - } - - /** - * Set read timeout - * - * @param float $timeout - */ - public function setTimeoutSecs($timeout) { - $this->timeout_ = $timeout; - } - - /** - * Whether this transport is open. - * - * @return boolean true if open - */ - public function isOpen() { - return true; - } - - /** - * Open the transport for reading/writing - * - * @throws TTransportException if cannot open - */ - public function open() {} - - /** - * Close the transport. - */ - public function close() { - if ($this->handle_) { - @fclose($this->handle_); - $this->handle_ = null; - } - } - - /** - * Read some data into the array. - * - * @param int $len How much to read - * @return string The data that has been read - * @throws TTransportException if cannot read any more data - */ - public function read($len) { - $data = @fread($this->handle_, $len); - if ($data === FALSE || $data === '') { - $md = stream_get_meta_data($this->handle_); - if ($md['timed_out']) { - throw new TTransportException('THttpClient: timed out reading '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::TIMED_OUT); - } else { - throw new TTransportException('THttpClient: Could not read '.$len.' bytes from '.$this->host_.':'.$this->port_.$this->uri_, TTransportException::UNKNOWN); - } - } - return $data; - } - - /** - * Writes some data into the pending buffer - * - * @param string $buf The data to write - * @throws TTransportException if writing fails - */ - public function write($buf) { - $this->buf_ .= $buf; - } - - /** - * Opens and sends the actual request over the HTTP connection - * - * @throws TTransportException if a writing error occurs - */ - public function flush() { - // God, PHP really has some esoteric ways of doing simple things. - $host = $this->host_.($this->port_ != 80 ? ':'.$this->port_ : ''); - - $headers = array(); - $defaultHeaders = array('Host' => $host, - 'Accept' => 'application/x-thrift', - 'User-Agent' => 'PHP/THttpClient', - 'Content-Type' => 'application/x-thrift', - 'Content-Length' => TStringFuncFactory::create()->strlen($this->buf_)); - foreach (array_merge($defaultHeaders, $this->headers_) as $key => $value) { - $headers[] = "$key: $value"; - } - - $options = array('method' => 'POST', - 'header' => implode("\r\n", $headers), - 'max_redirects' => 1, - 'content' => $this->buf_); - if ($this->timeout_ > 0) { - $options['timeout'] = $this->timeout_; - } - $this->buf_ = ''; - - $contextid = stream_context_create(array('http' => $options)); - $this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_, 'r', false, $contextid); - - // Connect failed? - if ($this->handle_ === FALSE) { - $this->handle_ = null; - $error = 'THttpClient: Could not connect to '.$host.$this->uri_; - throw new TTransportException($error, TTransportException::NOT_OPEN); - } - } - - public function addHeaders($headers) { - $this->headers_ = array_merge($this->headers_, $headers); - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TMemoryBuffer.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TMemoryBuffer.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TMemoryBuffer.php deleted file mode 100644 index 911fab6..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TMemoryBuffer.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.transport - */ - -namespace Thrift\Transport; - -use Thrift\Transport\TTransport; -use Thrift\Exception\TTransportException; -use Thrift\Factory\TStringFuncFactory; - -/** - * A memory buffer is a tranpsort that simply reads from and writes to an - * in-memory string buffer. Anytime you call write on it, the data is simply - * placed into a buffer, and anytime you call read, data is read from that - * buffer. - * - * @package thrift.transport - */ -class TMemoryBuffer extends TTransport { - - /** - * Constructor. Optionally pass an initial value - * for the buffer. - */ - public function __construct($buf = '') { - $this->buf_ = $buf; - } - - protected $buf_ = ''; - - public function isOpen() { - return true; - } - - public function open() {} - - public function close() {} - - public function write($buf) { - $this->buf_ .= $buf; - } - - public function read($len) { - $bufLength = TStringFuncFactory::create()->strlen($this->buf_); - - if ($bufLength === 0) { - throw new TTransportException('TMemoryBuffer: Could not read ' . - $len . ' bytes from buffer.', - TTransportException::UNKNOWN); - } - - if ($bufLength <= $len) { - $ret = $this->buf_; - $this->buf_ = ''; - return $ret; - } - - $ret = TStringFuncFactory::create()->substr($this->buf_, 0, $len); - $this->buf_ = TStringFuncFactory::create()->substr($this->buf_, $len); - - return $ret; - } - - function getBuffer() { - return $this->buf_; - } - - public function available() { - return TStringFuncFactory::create()->strlen($this->buf_); - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TNullTransport.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TNullTransport.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TNullTransport.php deleted file mode 100644 index 4bf10ed..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TNullTransport.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.transport - */ - -namespace Thrift\Transport; - -use Thrift\Transport\TTransport; -use Thrift\Exception\TTransportException; - -/** - * Transport that only accepts writes and ignores them. - * This is useful for measuring the serialized size of structures. - * - * @package thrift.transport - */ -class TNullTransport extends TTransport { - - public function isOpen() { - return true; - } - - public function open() {} - - public function close() {} - - public function read($len) { - throw new TTransportException("Can't read from TNullTransport."); - } - - public function write($buf) {} - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TPhpStream.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TPhpStream.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TPhpStream.php deleted file mode 100644 index 691d0cf..0000000 --- a/airavata-api/airavata-client-sdks/airavata-php-sdk/src/main/resources/lib/Thrift/Transport/TPhpStream.php +++ /dev/null @@ -1,114 +0,0 @@ -<?php -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - * @package thrift.transport - */ - -namespace Thrift\Transport; - -use Thrift\Transport\TTransport; -use Thrift\Exception\TException; -use Thrift\Factory\TStringFuncFactory; - -/** - * Php stream transport. Reads to and writes from the php standard streams - * php://input and php://output - * - * @package thrift.transport - */ -class TPhpStream extends TTransport { - - const MODE_R = 1; - const MODE_W = 2; - - private $inStream_ = null; - - private $outStream_ = null; - - private $read_ = false; - - private $write_ = false; - - public function __construct($mode) { - $this->read_ = $mode & self::MODE_R; - $this->write_ = $mode & self::MODE_W; - } - - public function open() { - if ($this->read_) { - $this->inStream_ = @fopen(self::inStreamName(), 'r'); - if (!is_resource($this->inStream_)) { - throw new TException('TPhpStream: Could not open php://input'); - } - } - if ($this->write_) { - $this->outStream_ = @fopen('php://output', 'w'); - if (!is_resource($this->outStream_)) { - throw new TException('TPhpStream: Could not open php://output'); - } - } - } - - public function close() { - if ($this->read_) { - @fclose($this->inStream_); - $this->inStream_ = null; - } - if ($this->write_) { - @fclose($this->outStream_); - $this->outStream_ = null; - } - } - - public function isOpen() { - return - (!$this->read_ || is_resource($this->inStream_)) && - (!$this->write_ || is_resource($this->outStream_)); - } - - 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) { - while (TStringFuncFactory::create()->strlen($buf) > 0) { - $got = @fwrite($this->outStream_, $buf); - if ($got === 0 || $got === FALSE) { - throw new TException('TPhpStream: Could not write '.TStringFuncFactory::create()->strlen($buf).' bytes'); - } - $buf = TStringFuncFactory::create()->substr($buf, $got); - } - } - - public function flush() { - @fflush($this->outStream_); - } - - private static function inStreamName() { - if (php_sapi_name() == 'cli') { - return 'php://stdin'; - } - return 'php://input'; - } - -}
