From 3a4770599a878e6140e3f4981de36943d3611619 Mon Sep 17 00:00:00 2001 From: Ma Bingyao Date: Tue, 7 Mar 2017 13:48:00 +0800 Subject: [PATCH] Removed generator check --- src/Hprose/Future/CallableWrapper.php | 5 +++- src/Hprose/Future/Wrapper.php | 7 ++---- src/Hprose/Future/functions.php | 33 +++++++++------------------ src/Hprose/Service.php | 4 ++-- 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/Hprose/Future/CallableWrapper.php b/src/Hprose/Future/CallableWrapper.php index 18f0e568..0fcfa48c 100644 --- a/src/Hprose/Future/CallableWrapper.php +++ b/src/Hprose/Future/CallableWrapper.php @@ -14,7 +14,7 @@ * * * Future CallableWrapper for php 5.3+ * * * - * LastModified: Jul 11, 2016 * + * LastModified: Mar 7, 2017 * * Author: Ma Bingyao * * * \**********************************************************/ @@ -25,6 +25,9 @@ class CallableWrapper extends Wrapper { public function __invoke() { $obj = $this->obj; return all(func_get_args())->then(function($args) use ($obj) { + if (class_exists("\\Generator")) { + return co(call_user_func_array($obj, $args)); + } return call_user_func_array($obj, $args); }); } diff --git a/src/Hprose/Future/Wrapper.php b/src/Hprose/Future/Wrapper.php index 618b1359..51059d24 100644 --- a/src/Hprose/Future/Wrapper.php +++ b/src/Hprose/Future/Wrapper.php @@ -14,7 +14,7 @@ * * * Future Wrapper for php 5.3+ * * * - * LastModified: Dec 9, 2016 * + * LastModified: Mar 7, 2017 * * Author: Ma Bingyao * * * \**********************************************************/ @@ -32,10 +32,7 @@ public function __call($name, array $arguments) { $method = array($this->obj, $name); return all($arguments)->then(function($args) use ($method, $name) { if (class_exists("\\Generator")) { - $m = new ReflectionMethod($this->obj, $name); - if ($m->isGenerator()) { - return co(call_user_func_array($method, $args)); - } + return co(call_user_func_array($method, $args)); } return call_user_func_array($method, $args); }); diff --git a/src/Hprose/Future/functions.php b/src/Hprose/Future/functions.php index 05afa119..8df67150 100644 --- a/src/Hprose/Future/functions.php +++ b/src/Hprose/Future/functions.php @@ -14,7 +14,7 @@ * * * some helper functions for php 5.3+ * * * - * LastModified: Dec 22, 2016 * + * LastModified: Mar 7, 2017 * * Author: Ma Bingyao * * * \**********************************************************/ @@ -210,21 +210,18 @@ function($args) use ($handler) { ); } -function wrap($handler, $check_gen = true) { - if (class_exists("\\Generator") && is_callable($handler)) { - if( $check_gen ) - { - if (is_array($handler)) { - $m = new ReflectionMethod($handler[0], $handler[1]); - } - else { - $m = new ReflectionFunction($handler); - } - if ($m->isGenerator()) { - $check_gen = false; +function wrap($handler) { + if (is_object($handler)) { + if (is_callable($handler)) { + if (class_exists("\\Generator") && ($handler instanceof \Generator)) { + return co($handler); } + return new CallableWrapper($handler); } - if(!$check_gen) { + return new Wrapper($handler); + } + if (is_callable($handler)) { + if (class_exists("\\Generator")) { return function() use ($handler) { return all(func_get_args())->then( function($args) use ($handler) { @@ -233,14 +230,6 @@ function($args) use ($handler) { ); }; } - } - if (is_object($handler)) { - if (is_callable($handler)) { - return new CallableWrapper($handler); - } - return new Wrapper($handler); - } - if (is_callable($handler)) { return function() use ($handler) { return all(func_get_args())->then( function($args) use ($handler) { diff --git a/src/Hprose/Service.php b/src/Hprose/Service.php index 05094409..384201a2 100644 --- a/src/Hprose/Service.php +++ b/src/Hprose/Service.php @@ -14,7 +14,7 @@ * * * hprose service class for php 5.3+ * * * - * LastModified: Feb 16, 2017 * + * LastModified: Mar 7, 2017 * * Author: Ma Bingyao * * * \**********************************************************/ @@ -608,7 +608,7 @@ public function addFunction($func, $alias = '', array $options = array()) { $this->names[] = $alias; } if (class_exists("\\Generator")) { - $func = Future\wrap($func, false); + $func = Future\wrap($func); } $call = new stdClass(); $call->method = $func;