Hprose\Service::addFunction PHP Method

addFunction() public method

public addFunction ( $func, $alias = '', array $options = [] )
$options array
    public function addFunction($func, $alias = '', array $options = array())
    {
        if (!is_callable($func)) {
            throw new Exception('Argument func must be callable.');
        }
        if (is_array($alias) && empty($options)) {
            $options = $alias;
            $alias = '';
        }
        if (empty($alias)) {
            if (is_string($func)) {
                $alias = $func;
            } elseif (is_array($func)) {
                $alias = $func[1];
            } else {
                throw new Exception('Need an alias');
            }
        }
        $name = strtolower($alias);
        if (!array_key_exists($name, $this->calls)) {
            $this->names[] = $alias;
        }
        if (class_exists("\\Generator")) {
            if (is_array($func)) {
                $f = new ReflectionMethod($func[0], $func[1]);
            } else {
                $f = new ReflectionFunction($func);
            }
            if ($f->isGenerator()) {
                $func = Future\wrap($func);
            }
        }
        $call = new stdClass();
        $call->method = $func;
        $call->mode = isset($options['mode']) ? $options['mode'] : ResultMode::Normal;
        $call->simple = isset($options['simple']) ? $options['simple'] : null;
        $call->oneway = isset($options['oneway']) ? $options['oneway'] : false;
        $call->async = isset($options['async']) ? $options['async'] : false;
        $call->passContext = isset($options['passContext']) ? $options['passContext'] : null;
        $this->calls[$name] = $call;
        return $this;
    }