mirror of
https://e.coding.net/circlecloud/MinecraftAccount.git
synced 2026-02-15 10:59:22 +00:00
53
ThinkPHP/Library/Vendor/Hprose/HproseClassManager.php
vendored
Normal file
53
ThinkPHP/Library/Vendor/Hprose/HproseClassManager.php
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseClassManager.php *
|
||||
* *
|
||||
* hprose class manager library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 12, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
class HproseClassManager {
|
||||
private static $classCache1 = array();
|
||||
private static $classCache2 = array();
|
||||
public static function register($class, $alias) {
|
||||
self::$classCache1[$alias] = $class;
|
||||
self::$classCache2[$class] = $alias;
|
||||
}
|
||||
public static function getClassAlias($class) {
|
||||
if (array_key_exists($class, self::$classCache2)) {
|
||||
return self::$classCache2[$class];
|
||||
}
|
||||
$alias = str_replace('\\', '_', $class);
|
||||
self::register($class, $alias);
|
||||
return $alias;
|
||||
}
|
||||
public static function getClass($alias) {
|
||||
if (array_key_exists($alias, self::$classCache1)) {
|
||||
return self::$classCache1[$alias];
|
||||
}
|
||||
if (!class_exists($alias)) {
|
||||
$class = str_replace('_', '\\', $alias);
|
||||
if (class_exists($class)) {
|
||||
self::register($class, $alias);
|
||||
return $class;
|
||||
}
|
||||
eval("class " . $alias . " { }");
|
||||
}
|
||||
return $alias;
|
||||
}
|
||||
}
|
||||
?>
|
||||
134
ThinkPHP/Library/Vendor/Hprose/HproseClient.php
vendored
Normal file
134
ThinkPHP/Library/Vendor/Hprose/HproseClient.php
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseClient.php *
|
||||
* *
|
||||
* hprose client library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 13, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
require_once('HproseCommon.php');
|
||||
require_once('HproseIO.php');
|
||||
|
||||
abstract class HproseClient {
|
||||
protected $url;
|
||||
private $filter;
|
||||
private $simple;
|
||||
protected abstract function send($request);
|
||||
public function __construct($url = '') {
|
||||
$this->useService($url);
|
||||
$this->filter = NULL;
|
||||
$this->simple = false;
|
||||
}
|
||||
public function useService($url = '', $namespace = '') {
|
||||
if ($url) {
|
||||
$this->url = $url;
|
||||
}
|
||||
return new HproseProxy($this, $namespace);
|
||||
}
|
||||
public function invoke($functionName, &$arguments = array(), $byRef = false, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
if ($simple === NULL) $simple = $this->simple;
|
||||
$stream = new HproseStringStream(HproseTags::TagCall);
|
||||
$hproseWriter = ($simple ? new HproseSimpleWriter($stream) : new HproseWriter($stream));
|
||||
$hproseWriter->writeString($functionName);
|
||||
if (count($arguments) > 0 || $byRef) {
|
||||
$hproseWriter->reset();
|
||||
$hproseWriter->writeList($arguments);
|
||||
if ($byRef) {
|
||||
$hproseWriter->writeBoolean(true);
|
||||
}
|
||||
}
|
||||
$stream->write(HproseTags::TagEnd);
|
||||
$request = $stream->toString();
|
||||
if ($this->filter) $request = $this->filter->outputFilter($request);
|
||||
$stream->close();
|
||||
$response = $this->send($request);
|
||||
if ($this->filter) $response = $this->filter->inputFilter($response);
|
||||
if ($resultMode == HproseResultMode::RawWithEndTag) {
|
||||
return $response;
|
||||
}
|
||||
if ($resultMode == HproseResultMode::Raw) {
|
||||
return substr($response, 0, -1);
|
||||
}
|
||||
$stream = new HproseStringStream($response);
|
||||
$hproseReader = new HproseReader($stream);
|
||||
$result = NULL;
|
||||
while (($tag = $hproseReader->checkTags(
|
||||
array(HproseTags::TagResult,
|
||||
HproseTags::TagArgument,
|
||||
HproseTags::TagError,
|
||||
HproseTags::TagEnd))) !== HproseTags::TagEnd) {
|
||||
switch ($tag) {
|
||||
case HproseTags::TagResult:
|
||||
if ($resultMode == HproseResultMode::Serialized) {
|
||||
$result = $hproseReader->readRaw()->toString();
|
||||
}
|
||||
else {
|
||||
$hproseReader->reset();
|
||||
$result = &$hproseReader->unserialize();
|
||||
}
|
||||
break;
|
||||
case HproseTags::TagArgument:
|
||||
$hproseReader->reset();
|
||||
$args = &$hproseReader->readList(true);
|
||||
for ($i = 0; $i < count($arguments); $i++) {
|
||||
$arguments[$i] = &$args[$i];
|
||||
}
|
||||
break;
|
||||
case HproseTags::TagError:
|
||||
$hproseReader->reset();
|
||||
throw new HproseException($hproseReader->readString(true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function getFilter() {
|
||||
return $this->filter;
|
||||
}
|
||||
public function setFilter($filter) {
|
||||
$this->filter = $filter;
|
||||
}
|
||||
public function getSimpleMode() {
|
||||
return $this->simple;
|
||||
}
|
||||
public function setSimpleMode($simple = true) {
|
||||
$this->simple = $simple;
|
||||
}
|
||||
public function __call($function, $arguments) {
|
||||
return $this->invoke($function, $arguments);
|
||||
}
|
||||
public function __get($name) {
|
||||
return new HproseProxy($this, $name . '_');
|
||||
}
|
||||
}
|
||||
|
||||
class HproseProxy {
|
||||
private $client;
|
||||
private $namespace;
|
||||
public function __construct($client, $namespace = '') {
|
||||
$this->client = $client;
|
||||
$this->namespace = $namespace;
|
||||
}
|
||||
public function __call($function, $arguments) {
|
||||
$function = $this->namespace . $function;
|
||||
return $this->client->invoke($function, $arguments);
|
||||
}
|
||||
public function __get($name) {
|
||||
return new HproseProxy($this->client, $this->namespace . $name . '_');
|
||||
}
|
||||
}
|
||||
?>
|
||||
816
ThinkPHP/Library/Vendor/Hprose/HproseCommon.php
vendored
Normal file
816
ThinkPHP/Library/Vendor/Hprose/HproseCommon.php
vendored
Normal file
@@ -0,0 +1,816 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseCommon.php *
|
||||
* *
|
||||
* hprose common library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 15, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
class HproseResultMode {
|
||||
const Normal = 0;
|
||||
const Serialized = 1;
|
||||
const Raw = 2;
|
||||
const RawWithEndTag = 3;
|
||||
}
|
||||
|
||||
class HproseException extends Exception {}
|
||||
|
||||
interface HproseFilter {
|
||||
function inputFilter($data);
|
||||
function outputFilter($data);
|
||||
}
|
||||
|
||||
class HproseDate {
|
||||
public $year;
|
||||
public $month;
|
||||
public $day;
|
||||
public $utc = false;
|
||||
public function __construct() {
|
||||
$args_num = func_num_args();
|
||||
$args = func_get_args();
|
||||
switch ($args_num) {
|
||||
case 0:
|
||||
$time = getdate();
|
||||
$this->year = $time['year'];
|
||||
$this->month = $time['mon'];
|
||||
$this->day = $time['mday'];
|
||||
break;
|
||||
case 1:
|
||||
$time = false;
|
||||
if (is_int($args[0])) {
|
||||
$time = getdate($args[0]);
|
||||
}
|
||||
elseif (is_string($args[0])) {
|
||||
$time = getdate(strtotime($args[0]));
|
||||
}
|
||||
if (is_array($time)) {
|
||||
$this->year = $time['year'];
|
||||
$this->month = $time['mon'];
|
||||
$this->day = $time['mday'];
|
||||
}
|
||||
elseif ($args[0] instanceof HproseDate) {
|
||||
$this->year = $args[0]->year;
|
||||
$this->month = $args[0]->month;
|
||||
$this->day = $args[0]->day;
|
||||
}
|
||||
else {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
$this->utc = $args[3];
|
||||
case 3:
|
||||
if (!self::isValidDate($args[0], $args[1], $args[2])) {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
$this->year = $args[0];
|
||||
$this->month = $args[1];
|
||||
$this->day = $args[2];
|
||||
break;
|
||||
default:
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
}
|
||||
public function addDays($days) {
|
||||
if (!is_int($days)) return false;
|
||||
$year = $this->year;
|
||||
if ($days == 0) return true;
|
||||
if ($days >= 146097 || $days <= -146097) {
|
||||
$remainder = $days % 146097;
|
||||
if ($remainder < 0) {
|
||||
$remainder += 146097;
|
||||
}
|
||||
$years = 400 * (int)(($days - $remainder) / 146097);
|
||||
$year += $years;
|
||||
if ($year < 1 || $year > 9999) return false;
|
||||
$days = $remainder;
|
||||
}
|
||||
if ($days >= 36524 || $days <= -36524) {
|
||||
$remainder = $days % 36524;
|
||||
if ($remainder < 0) {
|
||||
$remainder += 36524;
|
||||
}
|
||||
$years = 100 * (int)(($days - $remainder) / 36524);
|
||||
$year += $years;
|
||||
if ($year < 1 || $year > 9999) return false;
|
||||
$days = $remainder;
|
||||
}
|
||||
if ($days >= 1461 || $days <= -1461) {
|
||||
$remainder = $days % 1461;
|
||||
if ($remainder < 0) {
|
||||
$remainder += 1461;
|
||||
}
|
||||
$years = 4 * (int)(($days - $remainder) / 1461);
|
||||
$year += $years;
|
||||
if ($year < 1 || $year > 9999) return false;
|
||||
$days = $remainder;
|
||||
}
|
||||
$month = $this->month;
|
||||
while ($days >= 365) {
|
||||
if ($year >= 9999) return false;
|
||||
if ($month <= 2) {
|
||||
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
|
||||
$days -= 366;
|
||||
}
|
||||
else {
|
||||
$days -= 365;
|
||||
}
|
||||
$year++;
|
||||
}
|
||||
else {
|
||||
$year++;
|
||||
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
|
||||
$days -= 366;
|
||||
}
|
||||
else {
|
||||
$days -= 365;
|
||||
}
|
||||
}
|
||||
}
|
||||
while ($days < 0) {
|
||||
if ($year <= 1) return false;
|
||||
if ($month <= 2) {
|
||||
$year--;
|
||||
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
|
||||
$days += 366;
|
||||
}
|
||||
else {
|
||||
$days += 365;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) {
|
||||
$days += 366;
|
||||
}
|
||||
else {
|
||||
$days += 365;
|
||||
}
|
||||
$year--;
|
||||
}
|
||||
}
|
||||
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
$day = $this->day;
|
||||
while ($day + $days > $daysInMonth) {
|
||||
$days -= $daysInMonth - $day + 1;
|
||||
$month++;
|
||||
if ($month > 12) {
|
||||
if ($year >= 9999) return false;
|
||||
$year++;
|
||||
$month = 1;
|
||||
}
|
||||
$day = 1;
|
||||
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
}
|
||||
$day += $days;
|
||||
$this->year = $year;
|
||||
$this->month = $month;
|
||||
$this->day = $day;
|
||||
return true;
|
||||
}
|
||||
public function addMonths($months) {
|
||||
if (!is_int($months)) return false;
|
||||
if ($months == 0) return true;
|
||||
$month = $this->month + $months;
|
||||
$months = ($month - 1) % 12 + 1;
|
||||
if ($months < 1) {
|
||||
$months += 12;
|
||||
}
|
||||
$years = (int)(($month - $months) / 12);
|
||||
if ($this->addYears($years)) {
|
||||
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $months, $this->year);
|
||||
if ($this->day > $daysInMonth) {
|
||||
$months++;
|
||||
$this->day -= $daysInMonth;
|
||||
}
|
||||
$this->month = (int)$months;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function addYears($years) {
|
||||
if (!is_int($years)) return false;
|
||||
if ($years == 0) return true;
|
||||
$year = $this->year + $years;
|
||||
if ($year < 1 || $year > 9999) return false;
|
||||
$this->year = $year;
|
||||
return true;
|
||||
}
|
||||
public function timestamp() {
|
||||
if ($this->utc) {
|
||||
return gmmktime(0, 0, 0, $this->month, $this->day, $this->year);
|
||||
}
|
||||
else {
|
||||
return mktime(0, 0, 0, $this->month, $this->day, $this->year);
|
||||
}
|
||||
}
|
||||
public function toString($fullformat = true) {
|
||||
$format = ($fullformat ? '%04d-%02d-%02d': '%04d%02d%02d');
|
||||
$str = sprintf($format, $this->year, $this->month, $this->day);
|
||||
if ($this->utc) {
|
||||
$str .= 'Z';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
public function __toString() {
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
public static function isLeapYear($year) {
|
||||
return (($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false;
|
||||
}
|
||||
public static function daysInMonth($year, $month) {
|
||||
if (($month < 1) || ($month > 12)) {
|
||||
return false;
|
||||
}
|
||||
return cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
}
|
||||
public static function isValidDate($year, $month, $day) {
|
||||
if (($year >= 1) && ($year <= 9999)) {
|
||||
return checkdate($month, $day, $year);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function dayOfWeek() {
|
||||
$num = func_num_args();
|
||||
if ($num == 3) {
|
||||
$args = func_get_args();
|
||||
$y = $args[0];
|
||||
$m = $args[1];
|
||||
$d = $args[2];
|
||||
}
|
||||
else {
|
||||
$y = $this->year;
|
||||
$m = $this->month;
|
||||
$d = $this->day;
|
||||
}
|
||||
$d += $m < 3 ? $y-- : $y - 2;
|
||||
return ((int)(23 * $m / 9) + $d + 4 + (int)($y / 4) - (int)($y / 100) + (int)($y / 400)) % 7;
|
||||
}
|
||||
public function dayOfYear() {
|
||||
static $daysToMonth365 = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);
|
||||
static $daysToMonth366 = array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366);
|
||||
$num = func_num_args();
|
||||
if ($num == 3) {
|
||||
$args = func_get_args();
|
||||
$y = $args[0];
|
||||
$m = $args[1];
|
||||
$d = $args[2];
|
||||
}
|
||||
else {
|
||||
$y = $this->year;
|
||||
$m = $this->month;
|
||||
$d = $this->day;
|
||||
}
|
||||
$days = self::isLeapYear($y) ? $daysToMonth365 : $daysToMonth366;
|
||||
return $days[$m - 1] + $d;
|
||||
}
|
||||
}
|
||||
|
||||
class HproseTime {
|
||||
public $hour;
|
||||
public $minute;
|
||||
public $second;
|
||||
public $microsecond = 0;
|
||||
public $utc = false;
|
||||
public function __construct() {
|
||||
$args_num = func_num_args();
|
||||
$args = func_get_args();
|
||||
switch ($args_num) {
|
||||
case 0:
|
||||
$time = getdate();
|
||||
$timeofday = gettimeofday();
|
||||
$this->hour = $time['hours'];
|
||||
$this->minute = $time['minutes'];
|
||||
$this->second = $time['seconds'];
|
||||
$this->microsecond = $timeofday['usec'];
|
||||
break;
|
||||
case 1:
|
||||
$time = false;
|
||||
if (is_int($args[0])) {
|
||||
$time = getdate($args[0]);
|
||||
}
|
||||
elseif (is_string($args[0])) {
|
||||
$time = getdate(strtotime($args[0]));
|
||||
}
|
||||
if (is_array($time)) {
|
||||
$this->hour = $time['hours'];
|
||||
$this->minute = $time['minutes'];
|
||||
$this->second = $time['seconds'];
|
||||
}
|
||||
elseif ($args[0] instanceof HproseTime) {
|
||||
$this->hour = $args[0]->hour;
|
||||
$this->minute = $args[0]->minute;
|
||||
$this->second = $args[0]->second;
|
||||
$this->microsecond = $args[0]->microsecond;
|
||||
}
|
||||
else {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
$this->utc = $args[4];
|
||||
case 4:
|
||||
if (($args[3] < 0) || ($args[3] > 999999)) {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
$this->microsecond = $args[3];
|
||||
case 3:
|
||||
if (!self::isValidTime($args[0], $args[1], $args[2])) {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
$this->hour = $args[0];
|
||||
$this->minute = $args[1];
|
||||
$this->second = $args[2];
|
||||
break;
|
||||
default:
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
}
|
||||
public function timestamp() {
|
||||
if ($this->utc) {
|
||||
return gmmktime($this->hour, $this->minute, $this->second) +
|
||||
($this->microsecond / 1000000);
|
||||
}
|
||||
else {
|
||||
return mktime($this->hour, $this->minute, $this->second) +
|
||||
($this->microsecond / 1000000);
|
||||
}
|
||||
}
|
||||
public function toString($fullformat = true) {
|
||||
if ($this->microsecond == 0) {
|
||||
$format = ($fullformat ? '%02d:%02d:%02d': '%02d%02d%02d');
|
||||
$str = sprintf($format, $this->hour, $this->minute, $this->second);
|
||||
}
|
||||
if ($this->microsecond % 1000 == 0) {
|
||||
$format = ($fullformat ? '%02d:%02d:%02d.%03d': '%02d%02d%02d.%03d');
|
||||
$str = sprintf($format, $this->hour, $this->minute, $this->second, (int)($this->microsecond / 1000));
|
||||
}
|
||||
else {
|
||||
$format = ($fullformat ? '%02d:%02d:%02d.%06d': '%02d%02d%02d.%06d');
|
||||
$str = sprintf($format, $this->hour, $this->minute, $this->second, $this->microsecond);
|
||||
}
|
||||
if ($this->utc) {
|
||||
$str .= 'Z';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
public function __toString() {
|
||||
return $this->toString();
|
||||
}
|
||||
public static function isValidTime($hour, $minute, $second, $microsecond = 0) {
|
||||
return !(($hour < 0) || ($hour > 23) ||
|
||||
($minute < 0) || ($minute > 59) ||
|
||||
($second < 0) || ($second > 59) ||
|
||||
($microsecond < 0) || ($microsecond > 999999));
|
||||
}
|
||||
}
|
||||
|
||||
class HproseDateTime extends HproseDate {
|
||||
public $hour;
|
||||
public $minute;
|
||||
public $second;
|
||||
public $microsecond = 0;
|
||||
public function __construct() {
|
||||
$args_num = func_num_args();
|
||||
$args = func_get_args();
|
||||
switch ($args_num) {
|
||||
case 0:
|
||||
$time = getdate();
|
||||
$timeofday = gettimeofday();
|
||||
$this->year = $time['year'];
|
||||
$this->month = $time['mon'];
|
||||
$this->day = $time['mday'];
|
||||
$this->hour = $time['hours'];
|
||||
$this->minute = $time['minutes'];
|
||||
$this->second = $time['seconds'];
|
||||
$this->microsecond = $timeofday['usec'];
|
||||
break;
|
||||
case 1:
|
||||
$time = false;
|
||||
if (is_int($args[0])) {
|
||||
$time = getdate($args[0]);
|
||||
}
|
||||
elseif (is_string($args[0])) {
|
||||
$time = getdate(strtotime($args[0]));
|
||||
}
|
||||
if (is_array($time)) {
|
||||
$this->year = $time['year'];
|
||||
$this->month = $time['mon'];
|
||||
$this->day = $time['mday'];
|
||||
$this->hour = $time['hours'];
|
||||
$this->minute = $time['minutes'];
|
||||
$this->second = $time['seconds'];
|
||||
}
|
||||
elseif ($args[0] instanceof HproseDate) {
|
||||
$this->year = $args[0]->year;
|
||||
$this->month = $args[0]->month;
|
||||
$this->day = $args[0]->day;
|
||||
$this->hour = 0;
|
||||
$this->minute = 0;
|
||||
$this->second = 0;
|
||||
}
|
||||
elseif ($args[0] instanceof HproseTime) {
|
||||
$this->year = 1970;
|
||||
$this->month = 1;
|
||||
$this->day = 1;
|
||||
$this->hour = $args[0]->hour;
|
||||
$this->minute = $args[0]->minute;
|
||||
$this->second = $args[0]->second;
|
||||
$this->microsecond = $args[0]->microsecond;
|
||||
}
|
||||
elseif ($args[0] instanceof HproseDateTime) {
|
||||
$this->year = $args[0]->year;
|
||||
$this->month = $args[0]->month;
|
||||
$this->day = $args[0]->day;
|
||||
$this->hour = $args[0]->hour;
|
||||
$this->minute = $args[0]->minute;
|
||||
$this->second = $args[0]->second;
|
||||
$this->microsecond = $args[0]->microsecond;
|
||||
}
|
||||
else {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (($args[0] instanceof HproseDate) && ($args[1] instanceof HproseTime)) {
|
||||
$this->year = $args[0]->year;
|
||||
$this->month = $args[0]->month;
|
||||
$this->day = $args[0]->day;
|
||||
$this->hour = $args[1]->hour;
|
||||
$this->minute = $args[1]->minute;
|
||||
$this->second = $args[1]->second;
|
||||
$this->microsecond = $args[1]->microsecond;
|
||||
}
|
||||
else {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (!self::isValidDate($args[0], $args[1], $args[2])) {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
$this->year = $args[0];
|
||||
$this->month = $args[1];
|
||||
$this->day = $args[2];
|
||||
$this->hour = 0;
|
||||
$this->minute = 0;
|
||||
$this->second = 0;
|
||||
break;
|
||||
case 8:
|
||||
$this->utc = $args[7];
|
||||
case 7:
|
||||
if (($args[6] < 0) || ($args[6] > 999999)) {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
$this->microsecond = $args[6];
|
||||
case 6:
|
||||
if (!self::isValidDate($args[0], $args[1], $args[2])) {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
if (!self::isValidTime($args[3], $args[4], $args[5])) {
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
$this->year = $args[0];
|
||||
$this->month = $args[1];
|
||||
$this->day = $args[2];
|
||||
$this->hour = $args[3];
|
||||
$this->minute = $args[4];
|
||||
$this->second = $args[5];
|
||||
break;
|
||||
default:
|
||||
throw new HproseException('Unexpected arguments');
|
||||
}
|
||||
}
|
||||
|
||||
public function addMicroseconds($microseconds) {
|
||||
if (!is_int($microseconds)) return false;
|
||||
if ($microseconds == 0) return true;
|
||||
$microsecond = $this->microsecond + $microseconds;
|
||||
$microseconds = $microsecond % 1000000;
|
||||
if ($microseconds < 0) {
|
||||
$microseconds += 1000000;
|
||||
}
|
||||
$seconds = (int)(($microsecond - $microseconds) / 1000000);
|
||||
if ($this->addSeconds($seconds)) {
|
||||
$this->microsecond = (int)$microseconds;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function addSeconds($seconds) {
|
||||
if (!is_int($seconds)) return false;
|
||||
if ($seconds == 0) return true;
|
||||
$second = $this->second + $seconds;
|
||||
$seconds = $second % 60;
|
||||
if ($seconds < 0) {
|
||||
$seconds += 60;
|
||||
}
|
||||
$minutes = (int)(($second - $seconds) / 60);
|
||||
if ($this->addMinutes($minutes)) {
|
||||
$this->second = (int)$seconds;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function addMinutes($minutes) {
|
||||
if (!is_int($minutes)) return false;
|
||||
if ($minutes == 0) return true;
|
||||
$minute = $this->minute + $minutes;
|
||||
$minutes = $minute % 60;
|
||||
if ($minutes < 0) {
|
||||
$minutes += 60;
|
||||
}
|
||||
$hours = (int)(($minute - $minutes) / 60);
|
||||
if ($this->addHours($hours)) {
|
||||
$this->minute = (int)$minutes;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function addHours($hours) {
|
||||
if (!is_int($hours)) return false;
|
||||
if ($hours == 0) return true;
|
||||
$hour = $this->hour + $hours;
|
||||
$hours = $hour % 24;
|
||||
if ($hours < 0) {
|
||||
$hours += 24;
|
||||
}
|
||||
$days = (int)(($hour - $hours) / 24);
|
||||
if ($this->addDays($days)) {
|
||||
$this->hour = (int)$hours;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function after($when) {
|
||||
if (!($when instanceof HproseDateTime)) {
|
||||
$when = new HproseDateTime($when);
|
||||
}
|
||||
if ($this->utc != $when->utc) return ($this->timestamp() > $when->timestamp());
|
||||
if ($this->year < $when->year) return false;
|
||||
if ($this->year > $when->year) return true;
|
||||
if ($this->month < $when->month) return false;
|
||||
if ($this->month > $when->month) return true;
|
||||
if ($this->day < $when->day) return false;
|
||||
if ($this->day > $when->day) return true;
|
||||
if ($this->hour < $when->hour) return false;
|
||||
if ($this->hour > $when->hour) return true;
|
||||
if ($this->minute < $when->minute) return false;
|
||||
if ($this->minute > $when->minute) return true;
|
||||
if ($this->second < $when->second) return false;
|
||||
if ($this->second > $when->second) return true;
|
||||
if ($this->microsecond < $when->microsecond) return false;
|
||||
if ($this->microsecond > $when->microsecond) return true;
|
||||
return false;
|
||||
}
|
||||
public function before($when) {
|
||||
if (!($when instanceof HproseDateTime)) {
|
||||
$when = new HproseDateTime($when);
|
||||
}
|
||||
if ($this->utc != $when->utc) return ($this->timestamp() < $when->timestamp());
|
||||
if ($this->year < $when->year) return true;
|
||||
if ($this->year > $when->year) return false;
|
||||
if ($this->month < $when->month) return true;
|
||||
if ($this->month > $when->month) return false;
|
||||
if ($this->day < $when->day) return true;
|
||||
if ($this->day > $when->day) return false;
|
||||
if ($this->hour < $when->hour) return true;
|
||||
if ($this->hour > $when->hour) return false;
|
||||
if ($this->minute < $when->minute) return true;
|
||||
if ($this->minute > $when->minute) return false;
|
||||
if ($this->second < $when->second) return true;
|
||||
if ($this->second > $when->second) return false;
|
||||
if ($this->microsecond < $when->microsecond) return true;
|
||||
if ($this->microsecond > $when->microsecond) return false;
|
||||
return false;
|
||||
}
|
||||
public function equals($when) {
|
||||
if (!($when instanceof HproseDateTime)) {
|
||||
$when = new HproseDateTime($when);
|
||||
}
|
||||
if ($this->utc != $when->utc) return ($this->timestamp() == $when->timestamp());
|
||||
return (($this->year == $when->year) &&
|
||||
($this->month == $when->month) &&
|
||||
($this->day == $when->day) &&
|
||||
($this->hour == $when->hour) &&
|
||||
($this->minute == $when->minute) &&
|
||||
($this->second == $when->second) &&
|
||||
($this->microsecond == $when->microsecond));
|
||||
}
|
||||
public function timestamp() {
|
||||
if ($this->utc) {
|
||||
return gmmktime($this->hour,
|
||||
$this->minute,
|
||||
$this->second,
|
||||
$this->month,
|
||||
$this->day,
|
||||
$this->year) +
|
||||
($this->microsecond / 1000000);
|
||||
}
|
||||
else {
|
||||
return mktime($this->hour,
|
||||
$this->minute,
|
||||
$this->second,
|
||||
$this->month,
|
||||
$this->day,
|
||||
$this->year) +
|
||||
($this->microsecond / 1000000);
|
||||
}
|
||||
}
|
||||
public function toString($fullformat = true) {
|
||||
if ($this->microsecond == 0) {
|
||||
$format = ($fullformat ? '%04d-%02d-%02dT%02d:%02d:%02d'
|
||||
: '%04d%02d%02dT%02d%02d%02d');
|
||||
$str = sprintf($format,
|
||||
$this->year, $this->month, $this->day,
|
||||
$this->hour, $this->minute, $this->second);
|
||||
}
|
||||
if ($this->microsecond % 1000 == 0) {
|
||||
$format = ($fullformat ? '%04d-%02d-%02dT%02d:%02d:%02d.%03d'
|
||||
: '%04d%02d%02dT%02d%02d%02d.%03d');
|
||||
$str = sprintf($format,
|
||||
$this->year, $this->month, $this->day,
|
||||
$this->hour, $this->minute, $this->second,
|
||||
(int)($this->microsecond / 1000));
|
||||
}
|
||||
else {
|
||||
$format = ($fullformat ? '%04d-%02d-%02dT%02d:%02d:%02d.%06d'
|
||||
: '%04d%02d%02dT%02d%02d%02d.%06d');
|
||||
$str = sprintf($format,
|
||||
$this->year, $this->month, $this->day,
|
||||
$this->hour, $this->minute, $this->second,
|
||||
$this->microsecond);
|
||||
}
|
||||
if ($this->utc) {
|
||||
$str .= 'Z';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
public function __toString() {
|
||||
return $this->toString();
|
||||
}
|
||||
public static function isValidTime($hour, $minute, $second, $microsecond = 0) {
|
||||
return HproseTime::isValidTime($hour, $minute, $second, $microsecond);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
integer is_utf8(string $s)
|
||||
if $s is UTF-8 String, return 1 else 0
|
||||
*/
|
||||
if (function_exists('mb_detect_encoding')) {
|
||||
function is_utf8($s) {
|
||||
return mb_detect_encoding($s, 'UTF-8', true) === 'UTF-8';
|
||||
}
|
||||
}
|
||||
elseif (function_exists('iconv')) {
|
||||
function is_utf8($s) {
|
||||
return iconv('UTF-8', 'UTF-8//IGNORE', $s) === $s;
|
||||
}
|
||||
}
|
||||
else {
|
||||
function is_utf8($s) {
|
||||
$len = strlen($s);
|
||||
for($i = 0; $i < $len; ++$i){
|
||||
$c = ord($s{$i});
|
||||
switch ($c >> 4) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
break;
|
||||
case 12:
|
||||
case 13:
|
||||
if ((ord($s{++$i}) >> 6) != 0x2) return false;
|
||||
break;
|
||||
case 14:
|
||||
if ((ord($s{++$i}) >> 6) != 0x2) return false;
|
||||
if ((ord($s{++$i}) >> 6) != 0x2) return false;
|
||||
break;
|
||||
case 15:
|
||||
$b = $s{++$i};
|
||||
if ((ord($b) >> 6) != 0x2) return false;
|
||||
if ((ord($s{++$i}) >> 6) != 0x2) return false;
|
||||
if ((ord($s{++$i}) >> 6) != 0x2) return false;
|
||||
if (((($c & 0xf) << 2) | (($b >> 4) & 0x3)) > 0x10) return false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
integer ustrlen(string $s)
|
||||
$s must be a UTF-8 String, return the Unicode code unit (not code point) length
|
||||
*/
|
||||
if (function_exists('iconv')) {
|
||||
function ustrlen($s) {
|
||||
return strlen(iconv('UTF-8', 'UTF-16LE', $s)) >> 1;
|
||||
}
|
||||
}
|
||||
elseif (function_exists('mb_convert_encoding')) {
|
||||
function ustrlen($s) {
|
||||
return strlen(mb_convert_encoding($s, "UTF-16LE", "UTF-8")) >> 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
function ustrlen($s) {
|
||||
$pos = 0;
|
||||
$length = strlen($s);
|
||||
$len = $length;
|
||||
while ($pos < $length) {
|
||||
$a = ord($s{$pos++});
|
||||
if ($a < 0x80) {
|
||||
continue;
|
||||
}
|
||||
elseif (($a & 0xE0) == 0xC0) {
|
||||
++$pos;
|
||||
--$len;
|
||||
}
|
||||
elseif (($a & 0xF0) == 0xE0) {
|
||||
$pos += 2;
|
||||
$len -= 2;
|
||||
}
|
||||
elseif (($a & 0xF8) == 0xF0) {
|
||||
$pos += 3;
|
||||
$len -= 2;
|
||||
}
|
||||
}
|
||||
return $len;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
bool is_list(array $a)
|
||||
if $a is list, return true else false
|
||||
*/
|
||||
function is_list(array $a) {
|
||||
$count = count($a);
|
||||
if ($count === 0) return true;
|
||||
return !array_diff_key($a, array_fill(0, $count, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
mixed array_ref_search(mixed &$value, array $array)
|
||||
if $value ref in $array, return the index else false
|
||||
*/
|
||||
function array_ref_search(&$value, &$array) {
|
||||
if (!is_array($value)) return array_search($value, $array, true);
|
||||
$temp = $value;
|
||||
foreach ($array as $i => &$ref) {
|
||||
if (($ref === ($value = 1)) && ($ref === ($value = 0))) {
|
||||
$value = $temp;
|
||||
return $i;
|
||||
}
|
||||
}
|
||||
$value = $temp;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
string spl_object_hash(object $obj)
|
||||
This function returns a unique identifier for the object.
|
||||
This id can be used as a hash key for storing objects or for identifying an object.
|
||||
*/
|
||||
if (!function_exists('spl_object_hash')) {
|
||||
function spl_object_hash($object) {
|
||||
ob_start();
|
||||
var_dump($object);
|
||||
preg_match('[#(\d+)]', ob_get_clean(), $match);
|
||||
return $match[1];
|
||||
}
|
||||
}
|
||||
?>
|
||||
40
ThinkPHP/Library/Vendor/Hprose/HproseFormatter.php
vendored
Normal file
40
ThinkPHP/Library/Vendor/Hprose/HproseFormatter.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseFormatter.php *
|
||||
* *
|
||||
* hprose formatter library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 12, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
require_once('HproseIOStream.php');
|
||||
require_once('HproseReader.php');
|
||||
require_once('HproseWriter.php');
|
||||
|
||||
class HproseFormatter {
|
||||
public static function serialize(&$var, $simple = false) {
|
||||
$stream = new HproseStringStream();
|
||||
$hproseWriter = ($simple ? new HproseSimpleWriter($stream) : new HproseWriter($stream));
|
||||
$hproseWriter->serialize($var);
|
||||
return $stream->toString();
|
||||
}
|
||||
public static function &unserialize($data, $simple = false) {
|
||||
$stream = new HproseStringStream($data);
|
||||
$hproseReader = ($simple ? new HproseSimpleReader($stream) : new HproseReader($stream));
|
||||
return $hproseReader->unserialize();
|
||||
}
|
||||
}
|
||||
?>
|
||||
314
ThinkPHP/Library/Vendor/Hprose/HproseHttpClient.php
vendored
Normal file
314
ThinkPHP/Library/Vendor/Hprose/HproseHttpClient.php
vendored
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseHttpClient.php *
|
||||
* *
|
||||
* hprose http client library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 12, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
require_once('HproseCommon.php');
|
||||
require_once('HproseIO.php');
|
||||
require_once('HproseClient.php');
|
||||
|
||||
abstract class HproseBaseHttpClient extends HproseClient {
|
||||
protected $host;
|
||||
protected $path;
|
||||
protected $secure;
|
||||
protected $proxy;
|
||||
protected $header;
|
||||
protected $timeout;
|
||||
protected $keepAlive;
|
||||
protected $keepAliveTimeout;
|
||||
protected static $cookieManager = array();
|
||||
static function hproseKeepCookieInSession() {
|
||||
$_SESSION['HPROSE_COOKIE_MANAGER'] = self::$cookieManager;
|
||||
}
|
||||
public static function keepSession() {
|
||||
if (array_key_exists('HPROSE_COOKIE_MANAGER', $_SESSION)) {
|
||||
self::$cookieManager = $_SESSION['HPROSE_COOKIE_MANAGER'];
|
||||
}
|
||||
register_shutdown_function(array('HproseBaseHttpClient', 'hproseKeepCookieInSession'));
|
||||
}
|
||||
protected function setCookie($headers) {
|
||||
foreach ($headers as $header) {
|
||||
@list($name, $value) = explode(':', $header, 2);
|
||||
if (strtolower($name) == 'set-cookie' ||
|
||||
strtolower($name) == 'set-cookie2') {
|
||||
$cookies = explode(';', trim($value));
|
||||
$cookie = array();
|
||||
list($name, $value) = explode('=', trim($cookies[0]), 2);
|
||||
$cookie['name'] = $name;
|
||||
$cookie['value'] = $value;
|
||||
for ($i = 1; $i < count($cookies); $i++) {
|
||||
list($name, $value) = explode('=', trim($cookies[$i]), 2);
|
||||
$cookie[strtoupper($name)] = $value;
|
||||
}
|
||||
// Tomcat can return SetCookie2 with path wrapped in "
|
||||
if (array_key_exists('PATH', $cookie)) {
|
||||
$cookie['PATH'] = trim($cookie['PATH'], '"');
|
||||
}
|
||||
else {
|
||||
$cookie['PATH'] = '/';
|
||||
}
|
||||
if (array_key_exists('EXPIRES', $cookie)) {
|
||||
$cookie['EXPIRES'] = strtotime($cookie['EXPIRES']);
|
||||
}
|
||||
if (array_key_exists('DOMAIN', $cookie)) {
|
||||
$cookie['DOMAIN'] = strtolower($cookie['DOMAIN']);
|
||||
}
|
||||
else {
|
||||
$cookie['DOMAIN'] = $this->host;
|
||||
}
|
||||
$cookie['SECURE'] = array_key_exists('SECURE', $cookie);
|
||||
if (!array_key_exists($cookie['DOMAIN'], self::$cookieManager)) {
|
||||
self::$cookieManager[$cookie['DOMAIN']] = array();
|
||||
}
|
||||
self::$cookieManager[$cookie['DOMAIN']][$cookie['name']] = $cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected abstract function formatCookie($cookies);
|
||||
protected function getCookie() {
|
||||
$cookies = array();
|
||||
foreach (self::$cookieManager as $domain => $cookieList) {
|
||||
if (strpos($this->host, $domain) !== false) {
|
||||
$names = array();
|
||||
foreach ($cookieList as $cookie) {
|
||||
if (array_key_exists('EXPIRES', $cookie) && (time() > $cookie['EXPIRES'])) {
|
||||
$names[] = $cookie['name'];
|
||||
}
|
||||
elseif (strpos($this->path, $cookie['PATH']) === 0) {
|
||||
if ((($this->secure && $cookie['SECURE']) ||
|
||||
!$cookie['SECURE']) && !is_null($cookie['value'])) {
|
||||
$cookies[] = $cookie['name'] . '=' . $cookie['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($names as $name) {
|
||||
unset(self::$cookieManager[$domain][$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->formatCookie($cookies);
|
||||
}
|
||||
public function __construct($url = '') {
|
||||
parent::__construct($url);
|
||||
$this->header = array('Content-type' => 'application/hprose');
|
||||
}
|
||||
public function useService($url = '', $namespace = '') {
|
||||
$serviceProxy = parent::useService($url, $namespace);
|
||||
if ($url) {
|
||||
$url = parse_url($url);
|
||||
$this->secure = (strtolower($url['scheme']) == 'https');
|
||||
$this->host = strtolower($url['host']);
|
||||
$this->path = $url['path'];
|
||||
$this->timeout = 30000;
|
||||
$this->keepAlive = false;
|
||||
$this->keepAliveTimeout = 300;
|
||||
}
|
||||
return $serviceProxy;
|
||||
}
|
||||
public function setHeader($name, $value) {
|
||||
$lname = strtolower($name);
|
||||
if ($lname != 'content-type' &&
|
||||
$lname != 'content-length' &&
|
||||
$lname != 'host') {
|
||||
if ($value) {
|
||||
$this->header[$name] = $value;
|
||||
}
|
||||
else {
|
||||
unset($this->header[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function setProxy($proxy = NULL) {
|
||||
$this->proxy = $proxy;
|
||||
}
|
||||
public function setTimeout($timeout) {
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
public function getTimeout() {
|
||||
return $this->timeout;
|
||||
}
|
||||
public function setKeepAlive($keepAlive = true) {
|
||||
$this->keepAlive = $keepAlive;
|
||||
}
|
||||
public function getKeepAlive() {
|
||||
return $this->keeepAlive;
|
||||
}
|
||||
public function setKeepAliveTimeout($timeout) {
|
||||
$this->keepAliveTimeout = $timeout;
|
||||
}
|
||||
public function getKeepAliveTimeout() {
|
||||
return $this->keepAliveTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('SaeFetchurl')) {
|
||||
class HproseHttpClient extends HproseBaseHttpClient {
|
||||
protected function formatCookie($cookies) {
|
||||
if (count($cookies) > 0) {
|
||||
return implode('; ', $cookies);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
protected function send($request) {
|
||||
$f = new SaeFetchurl();
|
||||
$cookie = $this->getCookie();
|
||||
if ($cookie != '') {
|
||||
$f->setHeader("Cookie", $cookie);
|
||||
}
|
||||
if ($this->keepAlive) {
|
||||
$f->setHeader("Connection", "keep-alive");
|
||||
$f->setHeader("Keep-Alive", $this->keepAliveTimeout);
|
||||
}
|
||||
else {
|
||||
$f->setHeader("Connection", "close");
|
||||
}
|
||||
foreach ($this->header as $name => $value) {
|
||||
$f->setHeader($name, $value);
|
||||
}
|
||||
$f->setMethod("post");
|
||||
$f->setPostData($request);
|
||||
$f->setConnectTimeout($this->timeout);
|
||||
$f->setSendTimeout($this->timeout);
|
||||
$f->setReadTimeout($this->timeout);
|
||||
$response = $f->fetch($this->url);
|
||||
if ($f->errno()) {
|
||||
throw new HproseException($f->errno() . ": " . $f->errmsg());
|
||||
}
|
||||
$http_response_header = $f->responseHeaders(false);
|
||||
$this->setCookie($http_response_header);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (function_exists('curl_init')) {
|
||||
class HproseHttpClient extends HproseBaseHttpClient {
|
||||
private $curl;
|
||||
protected function formatCookie($cookies) {
|
||||
if (count($cookies) > 0) {
|
||||
return "Cookie: " . implode('; ', $cookies);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
public function __construct($url = '') {
|
||||
parent::__construct($url);
|
||||
$this->curl = curl_init();
|
||||
}
|
||||
protected function send($request) {
|
||||
curl_setopt($this->curl, CURLOPT_URL, $this->url);
|
||||
curl_setopt($this->curl, CURLOPT_HEADER, TRUE);
|
||||
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($this->curl, CURLOPT_POST, TRUE);
|
||||
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request);
|
||||
$headers_array = array($this->getCookie(),
|
||||
"Content-Length: " . strlen($request));
|
||||
if ($this->keepAlive) {
|
||||
$headers_array[] = "Connection: keep-alive";
|
||||
$headers_array[] = "Keep-Alive: " . $this->keepAliveTimeout;
|
||||
}
|
||||
else {
|
||||
$headers_array[] = "Connection: close";
|
||||
}
|
||||
foreach ($this->header as $name => $value) {
|
||||
$headers_array[] = $name . ": " . $value;
|
||||
}
|
||||
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers_array);
|
||||
if ($this->proxy) {
|
||||
curl_setopt($this->curl, CURLOPT_PROXY, $this->proxy);
|
||||
}
|
||||
if (defined(CURLOPT_TIMEOUT_MS)) {
|
||||
curl_setopt($this->curl, CURLOPT_TIMEOUT_MS, $this->timeout);
|
||||
}
|
||||
else {
|
||||
curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout / 1000);
|
||||
}
|
||||
$response = curl_exec($this->curl);
|
||||
$errno = curl_errno($this->curl);
|
||||
if ($errno) {
|
||||
throw new HproseException($errno . ": " . curl_error($this->curl));
|
||||
}
|
||||
do {
|
||||
list($response_headers, $response) = explode("\r\n\r\n", $response, 2);
|
||||
$http_response_header = explode("\r\n", $response_headers);
|
||||
$http_response_firstline = array_shift($http_response_header);
|
||||
if (preg_match('@^HTTP/[0-9]\.[0-9]\s([0-9]{3})\s(.*)@',
|
||||
$http_response_firstline, $matches)) {
|
||||
$response_code = $matches[1];
|
||||
$response_status = trim($matches[2]);
|
||||
}
|
||||
else {
|
||||
$response_code = "500";
|
||||
$response_status = "Unknown Error.";
|
||||
}
|
||||
} while (substr($response_code, 0, 1) == "1");
|
||||
if ($response_code != '200') {
|
||||
throw new HproseException($response_code . ": " . $response_status);
|
||||
}
|
||||
$this->setCookie($http_response_header);
|
||||
return $response;
|
||||
}
|
||||
public function __destruct() {
|
||||
curl_close($this->curl);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
class HproseHttpClient extends HproseBaseHttpClient {
|
||||
protected function formatCookie($cookies) {
|
||||
if (count($cookies) > 0) {
|
||||
return "Cookie: " . implode('; ', $cookies) . "\r\n";
|
||||
}
|
||||
return '';
|
||||
}
|
||||
public function __errorHandler($errno, $errstr, $errfile, $errline) {
|
||||
throw new Exception($errstr, $errno);
|
||||
}
|
||||
protected function send($request) {
|
||||
$opts = array (
|
||||
'http' => array (
|
||||
'method' => 'POST',
|
||||
'header'=> $this->getCookie() .
|
||||
"Content-Length: " . strlen($request) . "\r\n" .
|
||||
($this->keepAlive ?
|
||||
"Connection: keep-alive\r\n" .
|
||||
"Keep-Alive: " . $this->keepAliveTimeout . "\r\n" :
|
||||
"Connection: close\r\n"),
|
||||
'content' => $request,
|
||||
'timeout' => $this->timeout / 1000.0,
|
||||
),
|
||||
);
|
||||
foreach ($this->header as $name => $value) {
|
||||
$opts['http']['header'] .= "$name: $value\r\n";
|
||||
}
|
||||
if ($this->proxy) {
|
||||
$opts['http']['proxy'] = $this->proxy;
|
||||
$opts['http']['request_fulluri'] = true;
|
||||
}
|
||||
$context = stream_context_create($opts);
|
||||
set_error_handler(array(&$this, '__errorHandler'));
|
||||
$response = file_get_contents($this->url, false, $context);
|
||||
restore_error_handler();
|
||||
$this->setCookie($http_response_header);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
483
ThinkPHP/Library/Vendor/Hprose/HproseHttpServer.php
vendored
Normal file
483
ThinkPHP/Library/Vendor/Hprose/HproseHttpServer.php
vendored
Normal file
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseHttpServer.php *
|
||||
* *
|
||||
* hprose http server library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 13, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
require_once('HproseCommon.php');
|
||||
require_once('HproseIO.php');
|
||||
|
||||
class HproseHttpServer {
|
||||
private $errorTable = array(E_ERROR => 'Error',
|
||||
E_WARNING => 'Warning',
|
||||
E_PARSE => 'Parse Error',
|
||||
E_NOTICE => 'Notice',
|
||||
E_CORE_ERROR => 'Core Error',
|
||||
E_CORE_WARNING => 'Core Warning',
|
||||
E_COMPILE_ERROR => 'Compile Error',
|
||||
E_COMPILE_WARNING => 'Compile Warning',
|
||||
E_USER_ERROR => 'User Error',
|
||||
E_USER_WARNING => 'User Warning',
|
||||
E_USER_NOTICE => 'User Notice',
|
||||
E_STRICT => 'Run-time Notice',
|
||||
E_RECOVERABLE_ERROR => 'Error');
|
||||
private $functions;
|
||||
private $funcNames;
|
||||
private $resultModes;
|
||||
private $simpleModes;
|
||||
private $debug;
|
||||
private $crossDomain;
|
||||
private $P3P;
|
||||
private $get;
|
||||
private $input;
|
||||
private $output;
|
||||
private $error;
|
||||
private $filter;
|
||||
private $simple;
|
||||
public $onBeforeInvoke;
|
||||
public $onAfterInvoke;
|
||||
public $onSendHeader;
|
||||
public $onSendError;
|
||||
public function __construct() {
|
||||
$this->functions = array();
|
||||
$this->funcNames = array();
|
||||
$this->resultModes = array();
|
||||
$this->simpleModes = array();
|
||||
$this->debug = false;
|
||||
$this->crossDomain = false;
|
||||
$this->P3P = false;
|
||||
$this->get = true;
|
||||
$this->filter = NULL;
|
||||
$this->simple = false;
|
||||
$this->error_types = E_ALL & ~E_NOTICE;
|
||||
$this->onBeforeInvoke = NULL;
|
||||
$this->onAfterInvoke = NULL;
|
||||
$this->onSendHeader = NULL;
|
||||
$this->onSendError = NULL;
|
||||
}
|
||||
/*
|
||||
__filterHandler & __errorHandler must be public,
|
||||
however we should never call them directly.
|
||||
*/
|
||||
public function __filterHandler($data) {
|
||||
if (preg_match('/<b>.*? error<\/b>:(.*?)<br/', $data, $match)) {
|
||||
if ($this->debug) {
|
||||
$error = preg_replace('/<.*?>/', '', $match[1]);
|
||||
}
|
||||
else {
|
||||
$error = preg_replace('/ in <b>.*<\/b>$/', '', $match[1]);
|
||||
}
|
||||
$data = HproseTags::TagError .
|
||||
HproseFormatter::serialize(trim($error), true) .
|
||||
HproseTags::TagEnd;
|
||||
}
|
||||
if ($this->filter) $data = $this->filter->outputFilter($data);
|
||||
return $data;
|
||||
}
|
||||
public function __errorHandler($errno, $errstr, $errfile, $errline) {
|
||||
if ($this->debug) {
|
||||
$errstr .= " in $errfile on line $errline";
|
||||
}
|
||||
$this->error = $this->errorTable[$errno] . ": " . $errstr;
|
||||
$this->sendError();
|
||||
return true;
|
||||
}
|
||||
private function sendHeader() {
|
||||
if ($this->onSendHeader) {
|
||||
call_user_func($this->onSendHeader);
|
||||
}
|
||||
header("Content-Type: text/plain");
|
||||
if ($this->P3P) {
|
||||
header('P3P: CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi ' .
|
||||
'CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL ' .
|
||||
'UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"');
|
||||
}
|
||||
if ($this->crossDomain) {
|
||||
if (array_key_exists('HTTP_ORIGIN', $_SERVER) && $_SERVER['HTTP_ORIGIN'] != "null") {
|
||||
header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN']);
|
||||
header("Access-Control-Allow-Credentials: true");
|
||||
}
|
||||
else {
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
}
|
||||
}
|
||||
private function sendError() {
|
||||
if ($this->onSendError) {
|
||||
call_user_func($this->onSendError, $this->error);
|
||||
}
|
||||
ob_clean();
|
||||
$this->output->write(HproseTags::TagError);
|
||||
$writer = new HproseSimpleWriter($this->output);
|
||||
$writer->writeString($this->error);
|
||||
$this->output->write(HproseTags::TagEnd);
|
||||
ob_end_flush();
|
||||
}
|
||||
private function doInvoke() {
|
||||
$simpleReader = new HproseSimpleReader($this->input);
|
||||
do {
|
||||
$functionName = $simpleReader->readString(true);
|
||||
$aliasName = strtolower($functionName);
|
||||
$resultMode = HproseResultMode::Normal;
|
||||
if (array_key_exists($aliasName, $this->functions)) {
|
||||
$function = $this->functions[$aliasName];
|
||||
$resultMode = $this->resultModes[$aliasName];
|
||||
$simple = $this->simpleModes[$aliasName];
|
||||
}
|
||||
elseif (array_key_exists('*', $this->functions)) {
|
||||
$function = $this->functions['*'];
|
||||
$resultMode = $this->resultModes['*'];
|
||||
$simple = $this->resultModes['*'];
|
||||
}
|
||||
else {
|
||||
throw new HproseException("Can't find this function " . $functionName . "().");
|
||||
}
|
||||
if ($simple === NULL) $simple = $this->simple;
|
||||
$writer = ($simple ? new HproseSimpleWriter($this->output) : new HproseWriter($this->output));
|
||||
$args = array();
|
||||
$byref = false;
|
||||
$tag = $simpleReader->checkTags(array(HproseTags::TagList,
|
||||
HproseTags::TagEnd,
|
||||
HproseTags::TagCall));
|
||||
if ($tag == HproseTags::TagList) {
|
||||
$reader = new HproseReader($this->input);
|
||||
$args = &$reader->readList();
|
||||
$tag = $reader->checkTags(array(HproseTags::TagTrue,
|
||||
HproseTags::TagEnd,
|
||||
HproseTags::TagCall));
|
||||
if ($tag == HproseTags::TagTrue) {
|
||||
$byref = true;
|
||||
$tag = $reader->checkTags(array(HproseTags::TagEnd,
|
||||
HproseTags::TagCall));
|
||||
}
|
||||
}
|
||||
if ($this->onBeforeInvoke) {
|
||||
call_user_func($this->onBeforeInvoke, $functionName, $args, $byref);
|
||||
}
|
||||
if (array_key_exists('*', $this->functions) && ($function === $this->functions['*'])) {
|
||||
$arguments = array($functionName, &$args);
|
||||
}
|
||||
elseif ($byref) {
|
||||
$arguments = array();
|
||||
for ($i = 0; $i < count($args); $i++) {
|
||||
$arguments[$i] = &$args[$i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$arguments = $args;
|
||||
}
|
||||
$result = call_user_func_array($function, $arguments);
|
||||
if ($this->onAfterInvoke) {
|
||||
call_user_func($this->onAfterInvoke, $functionName, $args, $byref, $result);
|
||||
}
|
||||
// some service functions/methods may echo content, we need clean it
|
||||
ob_clean();
|
||||
if ($resultMode == HproseResultMode::RawWithEndTag) {
|
||||
$this->output->write($result);
|
||||
return;
|
||||
}
|
||||
elseif ($resultMode == HproseResultMode::Raw) {
|
||||
$this->output->write($result);
|
||||
}
|
||||
else {
|
||||
$this->output->write(HproseTags::TagResult);
|
||||
if ($resultMode == HproseResultMode::Serialized) {
|
||||
$this->output->write($result);
|
||||
}
|
||||
else {
|
||||
$writer->reset();
|
||||
$writer->serialize($result);
|
||||
}
|
||||
if ($byref) {
|
||||
$this->output->write(HproseTags::TagArgument);
|
||||
$writer->reset();
|
||||
$writer->writeList($args);
|
||||
}
|
||||
}
|
||||
} while ($tag == HproseTags::TagCall);
|
||||
$this->output->write(HproseTags::TagEnd);
|
||||
ob_end_flush();
|
||||
}
|
||||
private function doFunctionList() {
|
||||
$functions = array_values($this->funcNames);
|
||||
$writer = new HproseSimpleWriter($this->output);
|
||||
$this->output->write(HproseTags::TagFunctions);
|
||||
$writer->writeList($functions);
|
||||
$this->output->write(HproseTags::TagEnd);
|
||||
ob_end_flush();
|
||||
}
|
||||
private function getDeclaredOnlyMethods($class) {
|
||||
$all = get_class_methods($class);
|
||||
if ($parent_class = get_parent_class($class)) {
|
||||
$inherit = get_class_methods($parent_class);
|
||||
$result = array_diff($all, $inherit);
|
||||
}
|
||||
else {
|
||||
$result = $all;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function addMissingFunction($function, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
$this->addFunction($function, '*', $resultMode, $simple);
|
||||
}
|
||||
public function addFunction($function, $alias = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
if (is_callable($function)) {
|
||||
if ($alias === NULL) {
|
||||
if (is_string($function)) {
|
||||
$alias = $function;
|
||||
}
|
||||
else {
|
||||
$alias = $function[1];
|
||||
}
|
||||
}
|
||||
if (is_string($alias)) {
|
||||
$aliasName = strtolower($alias);
|
||||
$this->functions[$aliasName] = $function;
|
||||
$this->funcNames[$aliasName] = $alias;
|
||||
$this->resultModes[$aliasName] = $resultMode;
|
||||
$this->simpleModes[$aliasName] = $simple;
|
||||
}
|
||||
else {
|
||||
throw new HproseException('Argument alias is not a string');
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new HproseException('Argument function is not a callable variable');
|
||||
}
|
||||
}
|
||||
public function addFunctions($functions, $aliases = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
$aliases_is_null = ($aliases === NULL);
|
||||
$count = count($functions);
|
||||
if (!$aliases_is_null && $count != count($aliases)) {
|
||||
throw new HproseException('The count of functions is not matched with aliases');
|
||||
}
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$function = $functions[$i];
|
||||
if ($aliases_is_null) {
|
||||
$this->addFunction($function, NULL, $resultMode, $simple);
|
||||
}
|
||||
else {
|
||||
$this->addFunction($function, $aliases[$i], $resultMode, $simple);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function addMethod($methodname, $belongto, $alias = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
if ($alias === NULL) {
|
||||
$alias = $methodname;
|
||||
}
|
||||
if (is_string($belongto)) {
|
||||
$this->addFunction(array($belongto, $methodname), $alias, $resultMode, $simple);
|
||||
}
|
||||
else {
|
||||
$this->addFunction(array(&$belongto, $methodname), $alias, $resultMode, $simple);
|
||||
}
|
||||
}
|
||||
public function addMethods($methods, $belongto, $aliases = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
$aliases_is_null = ($aliases === NULL);
|
||||
$count = count($methods);
|
||||
if (is_string($aliases)) {
|
||||
$aliasPrefix = $aliases;
|
||||
$aliases = array();
|
||||
foreach ($methods as $name) {
|
||||
$aliases[] = $aliasPrefix . '_' . $name;
|
||||
}
|
||||
}
|
||||
if (!$aliases_is_null && $count != count($aliases)) {
|
||||
throw new HproseException('The count of methods is not matched with aliases');
|
||||
}
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$method = $methods[$i];
|
||||
if (is_string($belongto)) {
|
||||
$function = array($belongto, $method);
|
||||
}
|
||||
else {
|
||||
$function = array(&$belongto, $method);
|
||||
}
|
||||
if ($aliases_is_null) {
|
||||
$this->addFunction($function, $method, $resultMode, $simple);
|
||||
}
|
||||
else {
|
||||
$this->addFunction($function, $aliases[$i], $resultMode, $simple);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function addInstanceMethods($object, $class = NULL, $aliasPrefix = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
if ($class === NULL) $class = get_class($object);
|
||||
$this->addMethods($this->getDeclaredOnlyMethods($class), $object, $aliasPrefix, $resultMode, $simple);
|
||||
}
|
||||
public function addClassMethods($class, $execclass = NULL, $aliasPrefix = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) {
|
||||
if ($execclass === NULL) $execclass = $class;
|
||||
$this->addMethods($this->getDeclaredOnlyMethods($class), $execclass, $aliasPrefix, $resultMode, $simple);
|
||||
}
|
||||
public function add() {
|
||||
$args_num = func_num_args();
|
||||
$args = func_get_args();
|
||||
switch ($args_num) {
|
||||
case 1: {
|
||||
if (is_callable($args[0])) {
|
||||
return $this->addFunction($args[0]);
|
||||
}
|
||||
elseif (is_array($args[0])) {
|
||||
return $this->addFunctions($args[0]);
|
||||
}
|
||||
elseif (is_object($args[0])) {
|
||||
return $this->addInstanceMethods($args[0]);
|
||||
}
|
||||
elseif (is_string($args[0])) {
|
||||
return $this->addClassMethods($args[0]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (is_callable($args[0]) && is_string($args[1])) {
|
||||
return $this->addFunction($args[0], $args[1]);
|
||||
}
|
||||
elseif (is_string($args[0])) {
|
||||
if (is_string($args[1]) && !is_callable(array($args[1], $args[0]))) {
|
||||
if (class_exists($args[1])) {
|
||||
return $this->addClassMethods($args[0], $args[1]);
|
||||
}
|
||||
else {
|
||||
return $this->addClassMethods($args[0], NULL, $args[1]);
|
||||
}
|
||||
}
|
||||
return $this->addMethod($args[0], $args[1]);
|
||||
}
|
||||
elseif (is_array($args[0])) {
|
||||
if (is_array($args[1])) {
|
||||
return $this->addFunctions($args[0], $args[1]);
|
||||
}
|
||||
else {
|
||||
return $this->addMethods($args[0], $args[1]);
|
||||
}
|
||||
}
|
||||
elseif (is_object($args[0])) {
|
||||
return $this->addInstanceMethods($args[0], $args[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (is_callable($args[0]) && is_null($args[1]) && is_string($args[2])) {
|
||||
return $this->addFunction($args[0], $args[2]);
|
||||
}
|
||||
elseif (is_string($args[0]) && is_string($args[2])) {
|
||||
if (is_string($args[1]) && !is_callable(array($args[0], $args[1]))) {
|
||||
return $this->addClassMethods($args[0], $args[1], $args[2]);
|
||||
}
|
||||
else {
|
||||
return $this->addMethod($args[0], $args[1], $args[2]);
|
||||
}
|
||||
}
|
||||
elseif (is_array($args[0])) {
|
||||
if (is_null($args[1]) && is_array($args[2])) {
|
||||
return $this->addFunctions($args[0], $args[2]);
|
||||
}
|
||||
else {
|
||||
return $this->addMethods($args[0], $args[1], $args[2]);
|
||||
}
|
||||
}
|
||||
elseif (is_object($args[0])) {
|
||||
return $this->addInstanceMethods($args[0], $args[1], $args[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
throw new HproseException('Wrong arguments');
|
||||
}
|
||||
}
|
||||
public function isDebugEnabled() {
|
||||
return $this->debug;
|
||||
}
|
||||
public function setDebugEnabled($enable = true) {
|
||||
$this->debug = $enable;
|
||||
}
|
||||
public function isCrossDomainEnabled() {
|
||||
return $this->crossDomain;
|
||||
}
|
||||
public function setCrossDomainEnabled($enable = true) {
|
||||
$this->crossDomain = $enable;
|
||||
}
|
||||
public function isP3PEnabled() {
|
||||
return $this->P3P;
|
||||
}
|
||||
public function setP3PEnabled($enable = true) {
|
||||
$this->P3P = $enable;
|
||||
}
|
||||
public function isGetEnabled() {
|
||||
return $this->get;
|
||||
}
|
||||
public function setGetEnabled($enable = true) {
|
||||
$this->get = $enable;
|
||||
}
|
||||
public function getFilter() {
|
||||
return $this->filter;
|
||||
}
|
||||
public function setFilter($filter) {
|
||||
$this->filter = $filter;
|
||||
}
|
||||
public function getSimpleMode() {
|
||||
return $this->simple;
|
||||
}
|
||||
public function setSimpleMode($simple = true) {
|
||||
$this->simple = $simple;
|
||||
}
|
||||
public function getErrorTypes() {
|
||||
return $this->error_types;
|
||||
}
|
||||
public function setErrorTypes($error_types) {
|
||||
$this->error_types = $error_types;
|
||||
}
|
||||
public function handle() {
|
||||
if (!isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = file_get_contents("php://input");
|
||||
if ($this->filter) $HTTP_RAW_POST_DATA = $this->filter->inputFilter($HTTP_RAW_POST_DATA);
|
||||
$this->input = new HproseStringStream($HTTP_RAW_POST_DATA);
|
||||
$this->output = new HproseFileStream(fopen('php://output', 'wb'));
|
||||
set_error_handler(array(&$this, '__errorHandler'), $this->error_types);
|
||||
ob_start(array(&$this, "__filterHandler"));
|
||||
ob_implicit_flush(0);
|
||||
ob_clean();
|
||||
$this->sendHeader();
|
||||
if (($_SERVER['REQUEST_METHOD'] == 'GET') and $this->get) {
|
||||
return $this->doFunctionList();
|
||||
}
|
||||
elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
try {
|
||||
switch ($this->input->getc()) {
|
||||
case HproseTags::TagCall: return $this->doInvoke();
|
||||
case HproseTags::TagEnd: return $this->doFunctionList();
|
||||
default: throw new HproseException("Wrong Request: \r\n" . $HTTP_RAW_POST_DATA);
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->error = $e->getMessage();
|
||||
if ($this->debug) {
|
||||
$this->error .= "\nfile: " . $e->getFile() .
|
||||
"\nline: " . $e->getLine() .
|
||||
"\ntrace: " . $e->getTraceAsString();
|
||||
}
|
||||
$this->sendError();
|
||||
}
|
||||
}
|
||||
$this->input->close();
|
||||
$this->output->close();
|
||||
}
|
||||
public function start() {
|
||||
$this->handle();
|
||||
}
|
||||
}
|
||||
?>
|
||||
29
ThinkPHP/Library/Vendor/Hprose/HproseIO.php
vendored
Normal file
29
ThinkPHP/Library/Vendor/Hprose/HproseIO.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseIO.php *
|
||||
* *
|
||||
* hprose io library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 10, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
require_once('HproseTags.php');
|
||||
require_once('HproseClassManager.php');
|
||||
require_once('HproseReader.php');
|
||||
require_once('HproseWriter.php');
|
||||
require_once('HproseFormatter.php');
|
||||
|
||||
?>
|
||||
349
ThinkPHP/Library/Vendor/Hprose/HproseIOStream.php
vendored
Normal file
349
ThinkPHP/Library/Vendor/Hprose/HproseIOStream.php
vendored
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseIOStream.php *
|
||||
* *
|
||||
* hprose io stream library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 12, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
abstract class HproseAbstractStream {
|
||||
public abstract function close();
|
||||
public abstract function getc();
|
||||
public abstract function read($length);
|
||||
public abstract function readuntil($char);
|
||||
public abstract function seek($offset, $whence = SEEK_SET);
|
||||
public abstract function mark();
|
||||
public abstract function unmark();
|
||||
public abstract function reset();
|
||||
public abstract function skip($n);
|
||||
public abstract function eof();
|
||||
public abstract function write($string, $length = -1);
|
||||
}
|
||||
|
||||
class HproseStringStream extends HproseAbstractStream {
|
||||
protected $buffer;
|
||||
protected $pos;
|
||||
protected $mark;
|
||||
protected $length;
|
||||
public function __construct($string = '') {
|
||||
$this->buffer = $string;
|
||||
$this->pos = 0;
|
||||
$this->mark = -1;
|
||||
$this->length = strlen($string);
|
||||
}
|
||||
public function close() {
|
||||
$this->buffer = NULL;
|
||||
$this->pos = 0;
|
||||
$this->mark = -1;
|
||||
$this->length = 0;
|
||||
}
|
||||
public function length() {
|
||||
return $this->length;
|
||||
}
|
||||
public function getc() {
|
||||
return $this->buffer{$this->pos++};
|
||||
}
|
||||
public function read($length) {
|
||||
$s = substr($this->buffer, $this->pos, $length);
|
||||
$this->skip($length);
|
||||
return $s;
|
||||
}
|
||||
public function readuntil($tag) {
|
||||
$pos = strpos($this->buffer, $tag, $this->pos);
|
||||
if ($pos !== false) {
|
||||
$s = substr($this->buffer, $this->pos, $pos - $this->pos);
|
||||
$this->pos = $pos + strlen($tag);
|
||||
}
|
||||
else {
|
||||
$s = substr($this->buffer, $this->pos);
|
||||
$this->pos = $this->length;
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
public function seek($offset, $whence = SEEK_SET) {
|
||||
switch ($whence) {
|
||||
case SEEK_SET:
|
||||
$this->pos = $offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
$this->pos += $offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
$this->pos = $this->length + $offset;
|
||||
break;
|
||||
}
|
||||
$this->mark = -1;
|
||||
return 0;
|
||||
}
|
||||
public function mark() {
|
||||
$this->mark = $this->pos;
|
||||
}
|
||||
public function unmark() {
|
||||
$this->mark = -1;
|
||||
}
|
||||
public function reset() {
|
||||
if ($this->mark != -1) {
|
||||
$this->pos = $this->mark;
|
||||
}
|
||||
}
|
||||
public function skip($n) {
|
||||
$this->pos += $n;
|
||||
}
|
||||
public function eof() {
|
||||
return ($this->pos >= $this->length);
|
||||
}
|
||||
public function write($string, $length = -1) {
|
||||
if ($length == -1) {
|
||||
$this->buffer .= $string;
|
||||
$length = strlen($string);
|
||||
}
|
||||
else {
|
||||
$this->buffer .= substr($string, 0, $length);
|
||||
}
|
||||
$this->length += $length;
|
||||
}
|
||||
public function toString() {
|
||||
return $this->buffer;
|
||||
}
|
||||
}
|
||||
|
||||
class HproseFileStream extends HproseAbstractStream {
|
||||
protected $fp;
|
||||
protected $buf;
|
||||
protected $unmark;
|
||||
protected $pos;
|
||||
protected $length;
|
||||
public function __construct($fp) {
|
||||
$this->fp = $fp;
|
||||
$this->buf = "";
|
||||
$this->unmark = true;
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
}
|
||||
public function close() {
|
||||
return fclose($this->fp);
|
||||
}
|
||||
public function getc() {
|
||||
if ($this->pos == -1) {
|
||||
return fgetc($this->fp);
|
||||
}
|
||||
elseif ($this->pos < $this->length) {
|
||||
return $this->buf{$this->pos++};
|
||||
}
|
||||
elseif ($this->unmark) {
|
||||
$this->buf = "";
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
return fgetc($this->fp);
|
||||
}
|
||||
elseif (($c = fgetc($this->fp)) !== false) {
|
||||
$this->buf .= $c;
|
||||
$this->pos++;
|
||||
$this->length++;
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
public function read($length) {
|
||||
if ($this->pos == -1) {
|
||||
return fread($this->fp, $length);
|
||||
}
|
||||
elseif ($this->pos < $this->length) {
|
||||
$len = $this->length - $this->pos;
|
||||
if ($len < $length) {
|
||||
$s = fread($this->fp, $length - $len);
|
||||
$this->buf .= $s;
|
||||
$this->length += strlen($s);
|
||||
}
|
||||
$s = substr($this->buf, $this->pos, $length);
|
||||
$this->pos += strlen($s);
|
||||
}
|
||||
elseif ($this->unmark) {
|
||||
$this->buf = "";
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
return fread($this->fp, $length);
|
||||
}
|
||||
elseif (($s = fread($this->fp, $length)) !== "") {
|
||||
$this->buf .= $s;
|
||||
$len = strlen($s);
|
||||
$this->pos += $len;
|
||||
$this->length += $len;
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
public function readuntil($char) {
|
||||
$s = '';
|
||||
while ((($c = $this->getc()) != $char) && $c !== false) $s .= $c;
|
||||
return $s;
|
||||
}
|
||||
public function seek($offset, $whence = SEEK_SET) {
|
||||
if (fseek($this->fp, $offset, $whence) == 0) {
|
||||
$this->buf = "";
|
||||
$this->unmark = true;
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public function mark() {
|
||||
$this->unmark = false;
|
||||
if ($this->pos == -1) {
|
||||
$this->buf = "";
|
||||
$this->pos = 0;
|
||||
$this->length = 0;
|
||||
}
|
||||
elseif ($this->pos > 0) {
|
||||
$this->buf = substr($this->buf, $this->pos);
|
||||
$this->length -= $this->pos;
|
||||
$this->pos = 0;
|
||||
}
|
||||
}
|
||||
public function unmark() {
|
||||
$this->unmark = true;
|
||||
}
|
||||
public function reset() {
|
||||
$this->pos = 0;
|
||||
}
|
||||
public function skip($n) {
|
||||
$this->read($n);
|
||||
}
|
||||
public function eof() {
|
||||
if (($this->pos != -1) && ($this->pos < $this->length)) return false;
|
||||
return feof($this->fp);
|
||||
}
|
||||
public function write($string, $length = -1) {
|
||||
if ($length == -1) $length = strlen($string);
|
||||
return fwrite($this->fp, $string, $length);
|
||||
}
|
||||
}
|
||||
|
||||
class HproseProcStream extends HproseAbstractStream {
|
||||
protected $process;
|
||||
protected $pipes;
|
||||
protected $buf;
|
||||
protected $unmark;
|
||||
protected $pos;
|
||||
protected $length;
|
||||
public function __construct($process, $pipes) {
|
||||
$this->process = $process;
|
||||
$this->pipes = $pipes;
|
||||
$this->buf = "";
|
||||
$this->unmark = true;
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
}
|
||||
public function close() {
|
||||
fclose($this->pipes[0]);
|
||||
fclose($this->pipes[1]);
|
||||
proc_close($this->process);
|
||||
}
|
||||
public function getc() {
|
||||
if ($this->pos == -1) {
|
||||
return fgetc($this->pipes[1]);
|
||||
}
|
||||
elseif ($this->pos < $this->length) {
|
||||
return $this->buf{$this->pos++};
|
||||
}
|
||||
elseif ($this->unmark) {
|
||||
$this->buf = "";
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
return fgetc($this->pipes[1]);
|
||||
}
|
||||
elseif (($c = fgetc($this->pipes[1])) !== false) {
|
||||
$this->buf .= $c;
|
||||
$this->pos++;
|
||||
$this->length++;
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
public function read($length) {
|
||||
if ($this->pos == -1) {
|
||||
return fread($this->pipes[1], $length);
|
||||
}
|
||||
elseif ($this->pos < $this->length) {
|
||||
$len = $this->length - $this->pos;
|
||||
if ($len < $length) {
|
||||
$s = fread($this->pipes[1], $length - $len);
|
||||
$this->buf .= $s;
|
||||
$this->length += strlen($s);
|
||||
}
|
||||
$s = substr($this->buf, $this->pos, $length);
|
||||
$this->pos += strlen($s);
|
||||
}
|
||||
elseif ($this->unmark) {
|
||||
$this->buf = "";
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
return fread($this->pipes[1], $length);
|
||||
}
|
||||
elseif (($s = fread($this->pipes[1], $length)) !== "") {
|
||||
$this->buf .= $s;
|
||||
$len = strlen($s);
|
||||
$this->pos += $len;
|
||||
$this->length += $len;
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
public function readuntil($char) {
|
||||
$s = '';
|
||||
while ((($c = $this->getc()) != $char) && $c !== false) $s .= $c;
|
||||
return $s;
|
||||
}
|
||||
public function seek($offset, $whence = SEEK_SET) {
|
||||
if (fseek($this->pipes[1], $offset, $whence) == 0) {
|
||||
$this->buf = "";
|
||||
$this->unmark = true;
|
||||
$this->pos = -1;
|
||||
$this->length = 0;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public function mark() {
|
||||
$this->unmark = false;
|
||||
if ($this->pos == -1) {
|
||||
$this->buf = "";
|
||||
$this->pos = 0;
|
||||
$this->length = 0;
|
||||
}
|
||||
elseif ($this->pos > 0) {
|
||||
$this->buf = substr($this->buf, $this->pos);
|
||||
$this->length -= $this->pos;
|
||||
$this->pos = 0;
|
||||
}
|
||||
}
|
||||
public function unmark() {
|
||||
$this->unmark = true;
|
||||
}
|
||||
public function reset() {
|
||||
$this->pos = 0;
|
||||
}
|
||||
public function skip($n) {
|
||||
$this->read($n);
|
||||
}
|
||||
public function eof() {
|
||||
if (($this->pos != -1) && ($this->pos < $this->length)) return false;
|
||||
return feof($this->pipes[1]);
|
||||
}
|
||||
public function write($string, $length = -1) {
|
||||
if ($length == -1) $length = strlen($string);
|
||||
return fwrite($this->pipes[0], $string, $length);
|
||||
}
|
||||
}
|
||||
?>
|
||||
672
ThinkPHP/Library/Vendor/Hprose/HproseReader.php
vendored
Normal file
672
ThinkPHP/Library/Vendor/Hprose/HproseReader.php
vendored
Normal file
@@ -0,0 +1,672 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseReader.php *
|
||||
* *
|
||||
* hprose reader library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 12, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
require_once('HproseCommon.php');
|
||||
require_once('HproseTags.php');
|
||||
require_once('HproseClassManager.php');
|
||||
|
||||
class HproseRawReader {
|
||||
public $stream;
|
||||
function __construct(&$stream) {
|
||||
$this->stream = &$stream;
|
||||
}
|
||||
public function readRaw($ostream = NULL, $tag = NULL) {
|
||||
if (is_null($ostream)) {
|
||||
$ostream = new HproseStringStream();
|
||||
}
|
||||
if (is_null($tag)) {
|
||||
$tag = $this->stream->getc();
|
||||
}
|
||||
switch ($tag) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case HproseTags::TagNull:
|
||||
case HproseTags::TagEmpty:
|
||||
case HproseTags::TagTrue:
|
||||
case HproseTags::TagFalse:
|
||||
case HproseTags::TagNaN:
|
||||
$ostream->write($tag);
|
||||
break;
|
||||
case HproseTags::TagInfinity:
|
||||
$ostream->write($tag);
|
||||
$ostream->write($this->stream->getc());
|
||||
break;
|
||||
case HproseTags::TagInteger:
|
||||
case HproseTags::TagLong:
|
||||
case HproseTags::TagDouble:
|
||||
case HproseTags::TagRef:
|
||||
$this->readNumberRaw($ostream, $tag);
|
||||
break;
|
||||
case HproseTags::TagDate:
|
||||
case HproseTags::TagTime:
|
||||
$this->readDateTimeRaw($ostream, $tag);
|
||||
break;
|
||||
case HproseTags::TagUTF8Char:
|
||||
$this->readUTF8CharRaw($ostream, $tag);
|
||||
break;
|
||||
case HproseTags::TagBytes:
|
||||
$this->readBytesRaw($ostream, $tag);
|
||||
break;
|
||||
case HproseTags::TagString:
|
||||
$this->readStringRaw($ostream, $tag);
|
||||
break;
|
||||
case HproseTags::TagGuid:
|
||||
$this->readGuidRaw($ostream, $tag);
|
||||
break;
|
||||
case HproseTags::TagList:
|
||||
case HproseTags::TagMap:
|
||||
case HproseTags::TagObject:
|
||||
$this->readComplexRaw($ostream, $tag);
|
||||
break;
|
||||
case HproseTags::TagClass:
|
||||
$this->readComplexRaw($ostream, $tag);
|
||||
$this->readRaw($ostream);
|
||||
break;
|
||||
case HproseTags::TagError:
|
||||
$ostream->write($tag);
|
||||
$this->readRaw($ostream);
|
||||
break;
|
||||
case false:
|
||||
throw new HproseException("No byte found in stream");
|
||||
default:
|
||||
throw new HproseException("Unexpected serialize tag '" + $tag + "' in stream");
|
||||
}
|
||||
return $ostream;
|
||||
}
|
||||
|
||||
private function readNumberRaw($ostream, $tag) {
|
||||
$s = $tag .
|
||||
$this->stream->readuntil(HproseTags::TagSemicolon) .
|
||||
HproseTags::TagSemicolon;
|
||||
$ostream->write($s);
|
||||
}
|
||||
|
||||
private function readDateTimeRaw($ostream, $tag) {
|
||||
$s = $tag;
|
||||
do {
|
||||
$tag = $this->stream->getc();
|
||||
$s .= $tag;
|
||||
} while ($tag != HproseTags::TagSemicolon &&
|
||||
$tag != HproseTags::TagUTC);
|
||||
$ostream->write($s);
|
||||
}
|
||||
|
||||
private function readUTF8CharRaw($ostream, $tag) {
|
||||
$s = $tag;
|
||||
$tag = $this->stream->getc();
|
||||
$s .= $tag;
|
||||
$a = ord($tag);
|
||||
if (($a & 0xE0) == 0xC0) {
|
||||
$s .= $this->stream->getc();
|
||||
}
|
||||
elseif (($a & 0xF0) == 0xE0) {
|
||||
$s .= $this->stream->read(2);
|
||||
}
|
||||
elseif ($a > 0x7F) {
|
||||
throw new HproseException("bad utf-8 encoding");
|
||||
}
|
||||
$ostream->write($s);
|
||||
}
|
||||
|
||||
private function readBytesRaw($ostream, $tag) {
|
||||
$len = $this->stream->readuntil(HproseTags::TagQuote);
|
||||
$s = $tag . $len . HproseTags::TagQuote . $this->stream->read((int)$len) . HproseTags::TagQuote;
|
||||
$this->stream->skip(1);
|
||||
$ostream->write($s);
|
||||
}
|
||||
|
||||
private function readStringRaw($ostream, $tag) {
|
||||
$len = $this->stream->readuntil(HproseTags::TagQuote);
|
||||
$s = $tag . $len . HproseTags::TagQuote;
|
||||
$len = (int)$len;
|
||||
$this->stream->mark();
|
||||
$utf8len = 0;
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
switch (ord($this->stream->getc()) >> 4) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7: {
|
||||
// 0xxx xxxx
|
||||
$utf8len++;
|
||||
break;
|
||||
}
|
||||
case 12:
|
||||
case 13: {
|
||||
// 110x xxxx 10xx xxxx
|
||||
$this->stream->skip(1);
|
||||
$utf8len += 2;
|
||||
break;
|
||||
}
|
||||
case 14: {
|
||||
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||
$this->stream->skip(2);
|
||||
$utf8len += 3;
|
||||
break;
|
||||
}
|
||||
case 15: {
|
||||
// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
|
||||
$this->stream->skip(3);
|
||||
$utf8len += 4;
|
||||
++$i;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new HproseException('bad utf-8 encoding');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->stream->reset();
|
||||
$this->stream->unmark();
|
||||
$s .= $this->stream->read($utf8len) . HproseTags::TagQuote;
|
||||
$this->stream->skip(1);
|
||||
$ostream->write($s);
|
||||
}
|
||||
|
||||
private function readGuidRaw($ostream, $tag) {
|
||||
$s = $tag . $this->stream->read(38);
|
||||
$ostream->write($s);
|
||||
}
|
||||
|
||||
private function readComplexRaw($ostream, $tag) {
|
||||
$s = $tag .
|
||||
$this->stream->readuntil(HproseTags::TagOpenbrace) .
|
||||
HproseTags::TagOpenbrace;
|
||||
$ostream->write($s);
|
||||
while (($tag = $this->stream->getc()) != HproseTags::TagClosebrace) {
|
||||
$this->readRaw($ostream, $tag);
|
||||
}
|
||||
$ostream->write($tag);
|
||||
}
|
||||
}
|
||||
|
||||
class HproseSimpleReader extends HproseRawReader {
|
||||
private $classref;
|
||||
function __construct(&$stream) {
|
||||
parent::__construct($stream);
|
||||
$this->classref = array();
|
||||
}
|
||||
public function &unserialize($tag = NULL) {
|
||||
if (is_null($tag)) {
|
||||
$tag = $this->stream->getc();
|
||||
}
|
||||
$result = NULL;
|
||||
switch ($tag) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
$result = (int)$tag; break;
|
||||
case HproseTags::TagInteger: $result = $this->readInteger(); break;
|
||||
case HproseTags::TagLong: $result = $this->readLong(); break;
|
||||
case HproseTags::TagDouble: $result = $this->readDouble(); break;
|
||||
case HproseTags::TagNull: break;
|
||||
case HproseTags::TagEmpty: $result = ''; break;
|
||||
case HproseTags::TagTrue: $result = true; break;
|
||||
case HproseTags::TagFalse: $result = false; break;
|
||||
case HproseTags::TagNaN: $result = log(-1); break;
|
||||
case HproseTags::TagInfinity: $result = $this->readInfinity(); break;
|
||||
case HproseTags::TagDate: $result = $this->readDate(); break;
|
||||
case HproseTags::TagTime: $result = $this->readTime(); break;
|
||||
case HproseTags::TagBytes: $result = $this->readBytes(); break;
|
||||
case HproseTags::TagUTF8Char: $result = $this->readUTF8Char(); break;
|
||||
case HproseTags::TagString: $result = $this->readString(); break;
|
||||
case HproseTags::TagGuid: $result = $this->readGuid(); break;
|
||||
case HproseTags::TagList: $result = &$this->readList(); break;
|
||||
case HproseTags::TagMap: $result = &$this->readMap(); break;
|
||||
case HproseTags::TagClass: $this->readClass(); $result = &$this->unserialize(); break;
|
||||
case HproseTags::TagObject: $result = $this->readObject(); break;
|
||||
case HproseTags::TagError: throw new HproseException($this->readString(true));
|
||||
case false: throw new HproseException('No byte found in stream');
|
||||
default: throw new HproseException("Unexpected serialize tag '$tag' in stream");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function checkTag($expectTag, $tag = NULL) {
|
||||
if (is_null($tag)) $tag = $this->stream->getc();
|
||||
if ($tag != $expectTag) {
|
||||
throw new HproseException("Tag '$expectTag' expected, but '$tag' found in stream");
|
||||
}
|
||||
}
|
||||
public function checkTags($expectTags, $tag = NULL) {
|
||||
if (is_null($tag)) $tag = $this->stream->getc();
|
||||
if (!in_array($tag, $expectTags)) {
|
||||
$expectTags = implode('', $expectTags);
|
||||
throw new HproseException("Tag '$expectTags' expected, but '$tag' found in stream");
|
||||
}
|
||||
return $tag;
|
||||
}
|
||||
public function readInteger($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->stream->getc();
|
||||
if (($tag >= '0') && ($tag <= '9')) {
|
||||
return (int)$tag;
|
||||
}
|
||||
$this->checkTag(HproseTags::TagInteger, $tag);
|
||||
}
|
||||
return (int)($this->stream->readuntil(HproseTags::TagSemicolon));
|
||||
}
|
||||
public function readLong($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->stream->getc();
|
||||
if (($tag >= '0') && ($tag <= '9')) {
|
||||
return $tag;
|
||||
}
|
||||
$this->checkTag(HproseTags::TagLong, $tag);
|
||||
}
|
||||
return $this->stream->readuntil(HproseTags::TagSemicolon);
|
||||
}
|
||||
public function readDouble($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->stream->getc();
|
||||
if (($tag >= '0') && ($tag <= '9')) {
|
||||
return (double)$tag;
|
||||
}
|
||||
$this->checkTag(HproseTags::TagDouble, $tag);
|
||||
}
|
||||
return (double)($this->stream->readuntil(HproseTags::TagSemicolon));
|
||||
}
|
||||
public function readNaN() {
|
||||
$this->checkTag(HproseTags::TagNaN);
|
||||
return log(-1);
|
||||
}
|
||||
public function readInfinity($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagInfinity);
|
||||
return (($this->stream->getc() == HproseTags::TagNeg) ? log(0) : -log(0));
|
||||
}
|
||||
public function readNull() {
|
||||
$this->checkTag(HproseTags::TagNull);
|
||||
return NULL;
|
||||
}
|
||||
public function readEmpty() {
|
||||
$this->checkTag(HproseTags::TagEmpty);
|
||||
return '';
|
||||
}
|
||||
public function readBoolean() {
|
||||
$tag = $this->checkTags(array(HproseTags::TagTrue, HproseTags::TagFalse));
|
||||
return ($tag == HproseTags::TagTrue);
|
||||
}
|
||||
public function readDate($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagDate);
|
||||
$year = (int)($this->stream->read(4));
|
||||
$month = (int)($this->stream->read(2));
|
||||
$day = (int)($this->stream->read(2));
|
||||
$tag = $this->stream->getc();
|
||||
if ($tag == HproseTags::TagTime) {
|
||||
$hour = (int)($this->stream->read(2));
|
||||
$minute = (int)($this->stream->read(2));
|
||||
$second = (int)($this->stream->read(2));
|
||||
$microsecond = 0;
|
||||
$tag = $this->stream->getc();
|
||||
if ($tag == HproseTags::TagPoint) {
|
||||
$microsecond = (int)($this->stream->read(3)) * 1000;
|
||||
$tag = $this->stream->getc();
|
||||
if (($tag >= '0') && ($tag <= '9')) {
|
||||
$microsecond += (int)($tag) * 100 + (int)($this->stream->read(2));
|
||||
$tag = $this->stream->getc();
|
||||
if (($tag >= '0') && ($tag <= '9')) {
|
||||
$this->stream->skip(2);
|
||||
$tag = $this->stream->getc();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($tag == HproseTags::TagUTC) {
|
||||
$date = new HproseDateTime($year, $month, $day,
|
||||
$hour, $minute, $second,
|
||||
$microsecond, true);
|
||||
}
|
||||
else {
|
||||
$date = new HproseDateTime($year, $month, $day,
|
||||
$hour, $minute, $second,
|
||||
$microsecond);
|
||||
}
|
||||
}
|
||||
elseif ($tag == HproseTags::TagUTC) {
|
||||
$date = new HproseDate($year, $month, $day, true);
|
||||
}
|
||||
else {
|
||||
$date = new HproseDate($year, $month, $day);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
public function readTime($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagTime);
|
||||
$hour = (int)($this->stream->read(2));
|
||||
$minute = (int)($this->stream->read(2));
|
||||
$second = (int)($this->stream->read(2));
|
||||
$microsecond = 0;
|
||||
$tag = $this->stream->getc();
|
||||
if ($tag == HproseTags::TagPoint) {
|
||||
$microsecond = (int)($this->stream->read(3)) * 1000;
|
||||
$tag = $this->stream->getc();
|
||||
if (($tag >= '0') && ($tag <= '9')) {
|
||||
$microsecond += (int)($tag) * 100 + (int)($this->stream->read(2));
|
||||
$tag = $this->stream->getc();
|
||||
if (($tag >= '0') && ($tag <= '9')) {
|
||||
$this->stream->skip(2);
|
||||
$tag = $this->stream->getc();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($tag == HproseTags::TagUTC) {
|
||||
$time = new HproseTime($hour, $minute, $second, $microsecond, true);
|
||||
}
|
||||
else {
|
||||
$time = new HproseTime($hour, $minute, $second, $microsecond);
|
||||
}
|
||||
return $time;
|
||||
}
|
||||
public function readBytes($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagBytes);
|
||||
$count = (int)($this->stream->readuntil(HproseTags::TagQuote));
|
||||
$bytes = $this->stream->read($count);
|
||||
$this->stream->skip(1);
|
||||
return $bytes;
|
||||
}
|
||||
public function readUTF8Char($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagUTF8Char);
|
||||
$c = $this->stream->getc();
|
||||
$s = $c;
|
||||
$a = ord($c);
|
||||
if (($a & 0xE0) == 0xC0) {
|
||||
$s .= $this->stream->getc();
|
||||
}
|
||||
elseif (($a & 0xF0) == 0xE0) {
|
||||
$s .= $this->stream->read(2);
|
||||
}
|
||||
elseif ($a > 0x7F) {
|
||||
throw new HproseException("bad utf-8 encoding");
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
public function readString($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagString);
|
||||
$len = (int)$this->stream->readuntil(HproseTags::TagQuote);
|
||||
$this->stream->mark();
|
||||
$utf8len = 0;
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
switch (ord($this->stream->getc()) >> 4) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7: {
|
||||
// 0xxx xxxx
|
||||
$utf8len++;
|
||||
break;
|
||||
}
|
||||
case 12:
|
||||
case 13: {
|
||||
// 110x xxxx 10xx xxxx
|
||||
$this->stream->skip(1);
|
||||
$utf8len += 2;
|
||||
break;
|
||||
}
|
||||
case 14: {
|
||||
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||
$this->stream->skip(2);
|
||||
$utf8len += 3;
|
||||
break;
|
||||
}
|
||||
case 15: {
|
||||
// 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
|
||||
$this->stream->skip(3);
|
||||
$utf8len += 4;
|
||||
++$i;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new HproseException('bad utf-8 encoding');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->stream->reset();
|
||||
$this->stream->unmark();
|
||||
$s = $this->stream->read($utf8len);
|
||||
$this->stream->skip(1);
|
||||
return $s;
|
||||
}
|
||||
public function readGuid($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagGuid);
|
||||
$this->stream->skip(1);
|
||||
$s = $this->stream->read(36);
|
||||
$this->stream->skip(1);
|
||||
return $s;
|
||||
}
|
||||
protected function &readListBegin() {
|
||||
$list = array();
|
||||
return $list;
|
||||
}
|
||||
protected function &readListEnd(&$list) {
|
||||
$count = (int)$this->stream->readuntil(HproseTags::TagOpenbrace);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$list[] = &$this->unserialize();
|
||||
}
|
||||
$this->stream->skip(1);
|
||||
return $list;
|
||||
}
|
||||
public function &readList($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagList);
|
||||
$list = &$this->readListBegin();
|
||||
return $this->readListEnd($list);
|
||||
}
|
||||
protected function &readMapBegin() {
|
||||
$map = array();
|
||||
return $map;
|
||||
}
|
||||
protected function &readMapEnd(&$map) {
|
||||
$count = (int)$this->stream->readuntil(HproseTags::TagOpenbrace);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$key = &$this->unserialize();
|
||||
$map[$key] = &$this->unserialize();
|
||||
}
|
||||
$this->stream->skip(1);
|
||||
return $map;
|
||||
}
|
||||
public function &readMap($includeTag = false) {
|
||||
if ($includeTag) $this->checkTag(HproseTags::TagMap);
|
||||
$map = &$this->readMapBegin();
|
||||
return $this->readMapEnd($map);
|
||||
}
|
||||
protected function readObjectBegin() {
|
||||
list($classname, $fields) = $this->classref[(int)$this->stream->readuntil(HproseTags::TagOpenbrace)];
|
||||
$object = new $classname;
|
||||
return array($object, $fields);
|
||||
}
|
||||
protected function readObjectEnd($object, $fields) {
|
||||
$count = count($fields);
|
||||
if (class_exists('ReflectionClass')) {
|
||||
$reflector = new ReflectionClass($object);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$field = $fields[$i];
|
||||
if ($reflector->hasProperty($field)) {
|
||||
$property = $reflector->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($object, $this->unserialize());
|
||||
}
|
||||
else {
|
||||
$object->$field = &$this->unserialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$object->$fields[$i] = &$this->unserialize();
|
||||
}
|
||||
}
|
||||
$this->stream->skip(1);
|
||||
return $object;
|
||||
}
|
||||
public function readObject($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagClass, HproseTags::TagObject));
|
||||
if ($tag == HproseTags::TagClass) {
|
||||
$this->readClass();
|
||||
return $this->readObject(true);
|
||||
}
|
||||
}
|
||||
list($object, $fields) = $this->readObjectBegin();
|
||||
return $this->readObjectEnd($object, $fields);
|
||||
}
|
||||
protected function readClass() {
|
||||
$classname = HproseClassManager::getClass(self::readString());
|
||||
$count = (int)$this->stream->readuntil(HproseTags::TagOpenbrace);
|
||||
$fields = array();
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$fields[] = $this->readString(true);
|
||||
}
|
||||
$this->stream->skip(1);
|
||||
$this->classref[] = array($classname, $fields);
|
||||
}
|
||||
public function reset() {
|
||||
$this->classref = array();
|
||||
}
|
||||
}
|
||||
|
||||
class HproseReader extends HproseSimpleReader {
|
||||
private $ref;
|
||||
function __construct(&$stream) {
|
||||
parent::__construct($stream);
|
||||
$this->ref = array();
|
||||
}
|
||||
public function &unserialize($tag = NULL) {
|
||||
if (is_null($tag)) {
|
||||
$tag = $this->stream->getc();
|
||||
}
|
||||
if ($tag == HproseTags::TagRef) {
|
||||
return $this->readRef();
|
||||
}
|
||||
return parent::unserialize($tag);
|
||||
}
|
||||
public function readDate($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagDate, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
}
|
||||
$date = parent::readDate();
|
||||
$this->ref[] = $date;
|
||||
return $date;
|
||||
}
|
||||
public function readTime($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagTime, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
}
|
||||
$time = parent::readTime();
|
||||
$this->ref[] = $time;
|
||||
return $time;
|
||||
}
|
||||
public function readBytes($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagBytes, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
}
|
||||
$bytes = parent::readBytes();
|
||||
$this->ref[] = $bytes;
|
||||
return $bytes;
|
||||
}
|
||||
public function readString($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagString, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
}
|
||||
$str = parent::readString();
|
||||
$this->ref[] = $str;
|
||||
return $str;
|
||||
}
|
||||
public function readGuid($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagGuid, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
}
|
||||
$guid = parent::readGuid();
|
||||
$this->ref[] = $guid;
|
||||
return $guid;
|
||||
}
|
||||
public function &readList($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagList, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
}
|
||||
$list = &$this->readListBegin();
|
||||
$this->ref[] = &$list;
|
||||
return $this->readListEnd($list);
|
||||
}
|
||||
public function &readMap($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagMap, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
}
|
||||
$map = &$this->readMapBegin();
|
||||
$this->ref[] = &$map;
|
||||
return $this->readMapEnd($map);
|
||||
}
|
||||
public function readObject($includeTag = false) {
|
||||
if ($includeTag) {
|
||||
$tag = $this->checkTags(array(HproseTags::TagClass, HproseTags::TagObject, HproseTags::TagRef));
|
||||
if ($tag == HproseTags::TagRef) return $this->readRef();
|
||||
if ($tag == HproseTags::TagClass) {
|
||||
$this->readClass();
|
||||
return $this->readObject(true);
|
||||
}
|
||||
}
|
||||
list($object, $fields) = $this->readObjectBegin();
|
||||
$this->ref[] = $object;
|
||||
return $this->readObjectEnd($object, $fields);
|
||||
}
|
||||
private function &readRef() {
|
||||
$ref = &$this->ref[(int)$this->stream->readuntil(HproseTags::TagSemicolon)];
|
||||
if (gettype($ref) == 'array') {
|
||||
$result = &$ref;
|
||||
}
|
||||
else {
|
||||
$result = $ref;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function reset() {
|
||||
parent::reset();
|
||||
$this->ref = array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
62
ThinkPHP/Library/Vendor/Hprose/HproseTags.php
vendored
Normal file
62
ThinkPHP/Library/Vendor/Hprose/HproseTags.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseTags.php *
|
||||
* *
|
||||
* hprose tags library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 10, 2010 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
class HproseTags {
|
||||
/* Serialize Tags */
|
||||
const TagInteger = 'i';
|
||||
const TagLong = 'l';
|
||||
const TagDouble = 'd';
|
||||
const TagNull = 'n';
|
||||
const TagEmpty = 'e';
|
||||
const TagTrue = 't';
|
||||
const TagFalse = 'f';
|
||||
const TagNaN = 'N';
|
||||
const TagInfinity = 'I';
|
||||
const TagDate = 'D';
|
||||
const TagTime = 'T';
|
||||
const TagUTC = 'Z';
|
||||
const TagBytes = 'b';
|
||||
const TagUTF8Char = 'u';
|
||||
const TagString = 's';
|
||||
const TagGuid = 'g';
|
||||
const TagList = 'a';
|
||||
const TagMap = 'm';
|
||||
const TagClass = 'c';
|
||||
const TagObject = 'o';
|
||||
const TagRef = 'r';
|
||||
/* Serialize Marks */
|
||||
const TagPos = '+';
|
||||
const TagNeg = '-';
|
||||
const TagSemicolon = ';';
|
||||
const TagOpenbrace = '{';
|
||||
const TagClosebrace = '}';
|
||||
const TagQuote = '"';
|
||||
const TagPoint = '.';
|
||||
/* Protocol Tags */
|
||||
const TagFunctions = 'F';
|
||||
const TagCall = 'C';
|
||||
const TagResult = 'R';
|
||||
const TagArgument = 'A';
|
||||
const TagError = 'E';
|
||||
const TagEnd = 'z';
|
||||
}
|
||||
?>
|
||||
301
ThinkPHP/Library/Vendor/Hprose/HproseWriter.php
vendored
Normal file
301
ThinkPHP/Library/Vendor/Hprose/HproseWriter.php
vendored
Normal file
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
/**********************************************************\
|
||||
| |
|
||||
| hprose |
|
||||
| |
|
||||
| Official WebSite: http://www.hprose.com/ |
|
||||
| http://www.hprose.net/ |
|
||||
| http://www.hprose.org/ |
|
||||
| |
|
||||
\**********************************************************/
|
||||
|
||||
/**********************************************************\
|
||||
* *
|
||||
* HproseWriter.php *
|
||||
* *
|
||||
* hprose writer library for php5. *
|
||||
* *
|
||||
* LastModified: Nov 13, 2013 *
|
||||
* Author: Ma Bingyao <andot@hprfc.com> *
|
||||
* *
|
||||
\**********************************************************/
|
||||
|
||||
require_once('HproseCommon.php');
|
||||
require_once('HproseTags.php');
|
||||
require_once('HproseClassManager.php');
|
||||
|
||||
class HproseSimpleWriter {
|
||||
public $stream;
|
||||
private $classref;
|
||||
private $fieldsref;
|
||||
function __construct(&$stream) {
|
||||
$this->stream = &$stream;
|
||||
$this->classref = array();
|
||||
$this->fieldsref = array();
|
||||
}
|
||||
public function serialize(&$var) {
|
||||
if ((!isset($var)) || ($var === NULL)) {
|
||||
$this->writeNull();
|
||||
}
|
||||
elseif (is_scalar($var)) {
|
||||
if (is_int($var)) {
|
||||
$this->writeInteger($var);
|
||||
}
|
||||
elseif (is_bool($var)) {
|
||||
$this->writeBoolean($var);
|
||||
}
|
||||
elseif (is_float($var)) {
|
||||
$this->writeDouble($var);
|
||||
}
|
||||
elseif (is_string($var)) {
|
||||
if ($var === '') {
|
||||
$this->writeEmpty();
|
||||
}
|
||||
elseif ((strlen($var) < 4) && is_utf8($var) && (ustrlen($var) == 1)) {
|
||||
$this->writeUTF8Char($var);
|
||||
}
|
||||
elseif (is_utf8($var)) {
|
||||
$this->writeString($var, true);
|
||||
}
|
||||
else {
|
||||
$this->writeBytes($var, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (is_array($var)) {
|
||||
if (is_list($var)) {
|
||||
$this->writeList($var, true);
|
||||
}
|
||||
else {
|
||||
$this->writeMap($var, true);
|
||||
}
|
||||
}
|
||||
elseif (is_object($var)) {
|
||||
if ($var instanceof stdClass) {
|
||||
$this->writeStdObject($var, true);
|
||||
}
|
||||
elseif (($var instanceof HproseDate) || ($var instanceof HproseDateTime)) {
|
||||
$this->writeDate($var, true);
|
||||
}
|
||||
elseif ($var instanceof HproseTime) {
|
||||
$this->writeTime($var, true);
|
||||
}
|
||||
else {
|
||||
$this->writeObject($var, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new HproseException('Not support to serialize this data');
|
||||
}
|
||||
}
|
||||
public function writeInteger($integer) {
|
||||
if ($integer >= 0 && $integer <= 9) {
|
||||
$this->stream->write((string)$integer);
|
||||
}
|
||||
else {
|
||||
$this->stream->write(HproseTags::TagInteger . $integer . HproseTags::TagSemicolon);
|
||||
}
|
||||
}
|
||||
public function writeLong($long) {
|
||||
if ($long >= '0' && $long <= '9') {
|
||||
$this->stream->write($long);
|
||||
}
|
||||
else {
|
||||
$this->stream->write(HproseTags::TagLong . $long . HproseTags::TagSemicolon);
|
||||
}
|
||||
}
|
||||
public function writeDouble($double) {
|
||||
if (is_nan($double)) {
|
||||
$this->writeNaN();
|
||||
}
|
||||
elseif (is_infinite($double)) {
|
||||
$this->writeInfinity($double > 0);
|
||||
}
|
||||
else {
|
||||
$this->stream->write(HproseTags::TagDouble . $double . HproseTags::TagSemicolon);
|
||||
}
|
||||
}
|
||||
public function writeNaN() {
|
||||
$this->stream->write(HproseTags::TagNaN);
|
||||
}
|
||||
public function writeInfinity($positive = true) {
|
||||
$this->stream->write(HproseTags::TagInfinity . ($positive ? HproseTags::TagPos : HproseTags::TagNeg));
|
||||
}
|
||||
public function writeNull() {
|
||||
$this->stream->write(HproseTags::TagNull);
|
||||
}
|
||||
public function writeEmpty() {
|
||||
$this->stream->write(HproseTags::TagEmpty);
|
||||
}
|
||||
public function writeBoolean($bool) {
|
||||
$this->stream->write($bool ? HproseTags::TagTrue : HproseTags::TagFalse);
|
||||
}
|
||||
public function writeDate($date, $checkRef = false) {
|
||||
if ($date->utc) {
|
||||
$this->stream->write(HproseTags::TagDate . $date->toString(false));
|
||||
}
|
||||
else {
|
||||
$this->stream->write(HproseTags::TagDate . $date->toString(false) . HproseTags::TagSemicolon);
|
||||
}
|
||||
}
|
||||
public function writeTime($time, $checkRef = false) {
|
||||
if ($time->utc) {
|
||||
$this->stream->write(HproseTags::TagTime . $time->toString(false));
|
||||
}
|
||||
else {
|
||||
$this->stream->write(HproseTags::TagTime . $time->toString(false) . HproseTags::TagSemicolon);
|
||||
}
|
||||
}
|
||||
public function writeBytes($bytes, $checkRef = false) {
|
||||
$len = strlen($bytes);
|
||||
$this->stream->write(HproseTags::TagBytes);
|
||||
if ($len > 0) $this->stream->write((string)$len);
|
||||
$this->stream->write(HproseTags::TagQuote . $bytes . HproseTags::TagQuote);
|
||||
}
|
||||
public function writeUTF8Char($char) {
|
||||
$this->stream->write(HproseTags::TagUTF8Char . $char);
|
||||
}
|
||||
public function writeString($str, $checkRef = false) {
|
||||
$len = ustrlen($str);
|
||||
$this->stream->write(HproseTags::TagString);
|
||||
if ($len > 0) $this->stream->write((string)$len);
|
||||
$this->stream->write(HproseTags::TagQuote . $str . HproseTags::TagQuote);
|
||||
}
|
||||
public function writeList(&$list, $checkRef = false) {
|
||||
$count = count($list);
|
||||
$this->stream->write(HproseTags::TagList);
|
||||
if ($count > 0) $this->stream->write((string)$count);
|
||||
$this->stream->write(HproseTags::TagOpenbrace);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$this->serialize($list[$i]);
|
||||
}
|
||||
$this->stream->write(HproseTags::TagClosebrace);
|
||||
}
|
||||
public function writeMap(&$map, $checkRef = false) {
|
||||
$count = count($map);
|
||||
$this->stream->write(HproseTags::TagMap);
|
||||
if ($count > 0) $this->stream->write((string)$count);
|
||||
$this->stream->write(HproseTags::TagOpenbrace);
|
||||
foreach ($map as $key => &$value) {
|
||||
$this->serialize($key);
|
||||
$this->serialize($value);
|
||||
}
|
||||
$this->stream->write(HproseTags::TagClosebrace);
|
||||
}
|
||||
public function writeStdObject($obj, $checkRef = false) {
|
||||
$map = (array)$obj;
|
||||
self::writeMap($map);
|
||||
}
|
||||
protected function writeObjectBegin($obj) {
|
||||
$class = get_class($obj);
|
||||
$alias = HproseClassManager::getClassAlias($class);
|
||||
$fields = array_keys((array)$obj);
|
||||
if (array_key_exists($alias, $this->classref)) {
|
||||
$index = $this->classref[$alias];
|
||||
}
|
||||
else {
|
||||
$index = $this->writeClass($alias, $fields);
|
||||
}
|
||||
return $index;
|
||||
}
|
||||
protected function writeObjectEnd($obj, $index) {
|
||||
$fields = $this->fieldsref[$index];
|
||||
$count = count($fields);
|
||||
$this->stream->write(HproseTags::TagObject . $index . HproseTags::TagOpenbrace);
|
||||
$array = (array)$obj;
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$this->serialize($array[$fields[$i]]);
|
||||
}
|
||||
$this->stream->write(HproseTags::TagClosebrace);
|
||||
}
|
||||
public function writeObject($obj, $checkRef = false) {
|
||||
$this->writeObjectEnd($obj, $this->writeObjectBegin($obj));
|
||||
}
|
||||
protected function writeClass($alias, $fields) {
|
||||
$len = ustrlen($alias);
|
||||
$this->stream->write(HproseTags::TagClass . $len .
|
||||
HproseTags::TagQuote . $alias . HproseTags::TagQuote);
|
||||
$count = count($fields);
|
||||
if ($count > 0) $this->stream->write((string)$count);
|
||||
$this->stream->write(HproseTags::TagOpenbrace);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$field = $fields[$i];
|
||||
if ($field{0} === "\0") {
|
||||
$field = substr($field, strpos($field, "\0", 1) + 1);
|
||||
}
|
||||
$this->writeString($field);
|
||||
}
|
||||
$this->stream->write(HproseTags::TagClosebrace);
|
||||
$index = count($this->fieldsref);
|
||||
$this->classref[$alias] = $index;
|
||||
$this->fieldsref[$index] = $fields;
|
||||
return $index;
|
||||
}
|
||||
public function reset() {
|
||||
$this->classref = array();
|
||||
$this->fieldsref = array();
|
||||
}
|
||||
}
|
||||
class HproseWriter extends HproseSimpleWriter {
|
||||
private $ref;
|
||||
private $arrayref;
|
||||
function __construct(&$stream) {
|
||||
parent::__construct($stream);
|
||||
$this->ref = array();
|
||||
$this->arrayref = array();
|
||||
}
|
||||
private function writeRef(&$obj, $checkRef, $writeBegin, $writeEnd) {
|
||||
if (is_string($obj)) {
|
||||
$key = 's_' . $obj;
|
||||
}
|
||||
elseif (is_array($obj)) {
|
||||
if (($i = array_ref_search($obj, $this->arrayref)) === false) {
|
||||
$i = count($this->arrayref);
|
||||
$this->arrayref[$i] = &$obj;
|
||||
}
|
||||
$key = 'a_' . $i;
|
||||
}
|
||||
else {
|
||||
$key = 'o_' . spl_object_hash($obj);
|
||||
}
|
||||
if ($checkRef && array_key_exists($key, $this->ref)) {
|
||||
$this->stream->write(HproseTags::TagRef . $this->ref[$key] . HproseTags::TagSemicolon);
|
||||
}
|
||||
else {
|
||||
$result = $writeBegin ? call_user_func_array($writeBegin, array(&$obj)) : false;
|
||||
$index = count($this->ref);
|
||||
$this->ref[$key] = $index;
|
||||
call_user_func_array($writeEnd, array(&$obj, $result));
|
||||
}
|
||||
}
|
||||
public function writeDate($date, $checkRef = false) {
|
||||
$this->writeRef($date, $checkRef, NULL, array(&$this, 'parent::writeDate'));
|
||||
}
|
||||
public function writeTime($time, $checkRef = false) {
|
||||
$this->writeRef($time, $checkRef, NULL, array(&$this, 'parent::writeTime'));
|
||||
}
|
||||
public function writeBytes($bytes, $checkRef = false) {
|
||||
$this->writeRef($bytes, $checkRef, NULL, array(&$this, 'parent::writeBytes'));
|
||||
}
|
||||
public function writeString($str, $checkRef = false) {
|
||||
$this->writeRef($str, $checkRef, NULL, array(&$this, 'parent::writeString'));
|
||||
}
|
||||
public function writeList(&$list, $checkRef = false) {
|
||||
$this->writeRef($list, $checkRef, NULL, array(&$this, 'parent::writeList'));
|
||||
}
|
||||
public function writeMap(&$map, $checkRef = false) {
|
||||
$this->writeRef($map, $checkRef, NULL, array(&$this, 'parent::writeMap'));
|
||||
}
|
||||
public function writeStdObject($obj, $checkRef = false) {
|
||||
$this->writeRef($obj, $checkRef, NULL, array(&$this, 'parent::writeStdObject'));
|
||||
}
|
||||
public function writeObject($obj, $checkRef = false) {
|
||||
$this->writeRef($obj, $checkRef, array(&$this, 'writeObjectBegin'), array(&$this, 'writeObjectEnd'));
|
||||
}
|
||||
public function reset() {
|
||||
parent::reset();
|
||||
$this->ref = array();
|
||||
$this->arrayref = array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user