Skip to content

Commit

Permalink
Removed generator check
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Mar 7, 2017
1 parent c2f8541 commit 3a47705
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
5 changes: 4 additions & 1 deletion src/Hprose/Future/CallableWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
* Future CallableWrapper for php 5.3+ *
* *
* LastModified: Jul 11, 2016 *
* LastModified: Mar 7, 2017 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand All @@ -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);
});
}
Expand Down
7 changes: 2 additions & 5 deletions src/Hprose/Future/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
* Future Wrapper for php 5.3+ *
* *
* LastModified: Dec 9, 2016 *
* LastModified: Mar 7, 2017 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand All @@ -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);
});
Expand Down
33 changes: 11 additions & 22 deletions src/Hprose/Future/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
* some helper functions for php 5.3+ *
* *
* LastModified: Dec 22, 2016 *
* LastModified: Mar 7, 2017 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/Hprose/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
* hprose service class for php 5.3+ *
* *
* LastModified: Feb 16, 2017 *
* LastModified: Mar 7, 2017 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3a47705

Please sign in to comment.