/**
  * 执行当前控制器方法
  *
  * @param string $actionName 方法名
  * @param array $params 参数列表
  * @return Response|mixed
  * @throws AppException
  */
 public function runActionWithParams($actionName, $params = array())
 {
     $server = new HproseServer();
     $server->addFilter(new ServiceFilter());
     $methods = [];
     foreach (get_class_methods($this) as $method) {
         if (substr($method, -6) == 'Action') {
             $methods[$method] = substr($method, 0, -6);
         }
     }
     $server->addMethods(array_keys($methods), $this, array_values($methods));
     if (!\App::isProduction()) {
         $server->setDebugEnabled();
     }
     $server->setCrossDomainEnabled(false);
     $server->setP3PEnabled(false);
     $server->setGetEnabled(true);
     ob_start();
     $server->start();
     $this->response->setContent(ob_get_clean());
     return $this->response;
 }
Example #2
0
<?php

require_once "../../vendor/autoload.php";
use Hprose\Http\Server;
function hello($name)
{
    return "Hello {$name}!";
}
$server = new Server();
$server->addFunction('hello');
$server->start();
Example #3
0
<?php

require_once "../../vendor/autoload.php";
use Hprose\Http\Server;
function hello($name, $callback)
{
    $callback("Hello {$name}!");
}
$server = new Server();
$server->addFunction('hello', array("async" => true));
$server->start();