<?php use Hprose\Future; $logHandler = function ($name, array &$args, stdClass $context, Closure $next) { error_log("before invoke:"); error_log($name); error_log(var_export($args, true)); $result = $next($name, $args, $context); error_log("after invoke:"); if (Future\isFuture($result)) { $result->then(function ($result) { error_log(var_export($result, true)); }); } else { error_log(var_export($result, true)); } return $result; };
<?php require_once "../vendor/autoload.php"; use Hprose\Future; var_dump(Future\isFuture(123)); var_dump(Future\isFuture(Future\value(123)));
public function handle($request = null, $response = null) { $context = $this->createContext($request, $response); $self = $this; $this->userFatalErrorHandler = function ($error) use($self, $context) { $self->writeResponse($self->endError($error, $context), $context); }; $this->sendHeader($context); $result = ''; if ($this->isGet($context)) { if ($this->get) { $result = $this->doFunctionList(); } } elseif ($this->isPost($context)) { $result = $this->defaultHandle($this->readRequest($context), $context); } else { $result = $this->doFunctionList(); } if (Future\isFuture($result)) { $result->then(function ($result) use($self, $context) { $self->header('Content-Length', strlen($result), $context); $self->writeResponse($result, $context); }); } else { $this->header('Content-Length', strlen($result), $context); $this->writeResponse($result, $context); } return $context->response; }