Yar_Server::__construct

(PECL yar >= 1.0.0)

Yar_Server::__constructCreate an RPC server

説明

final public function Yar_Server::__construct(object $executor)

Creates a Yar HTTP RPC server. All public methods of executor are registered as RPC services.

パラメータ

executor

Any object whose public methods should be exposed as RPC services. Protected and private methods, and methods whose name starts with an underscore, are not exposed.

The executor can optionally define two protected magic methods, which are recognized by Yar_Server::handle() and never exposed as RPC endpoints:

  • protected function __info(string $markup): string — as of Yar 2.3.0. Called when the service information page is requested; it receives the markup of the page Yar would otherwise render, and if it returns a string, that string is sent to the client instead. See Yar_Server::handle().

  • protected function __auth(string $provider, string $token): bool — as of Yar 2.3.0. Called at the very beginning of every request with the provider and token fields of the request header, set by the client with the YAR_OPT_PROVIDER and YAR_OPT_TOKEN options. Returning exactly false rejects the request; any other return value lets it proceed. See Yar_Server::handle().

Both methods only take effect when they are protected; a public or private method with the same name is ignored.

戻り値

An instance of Yar_Server.

例1 Yar_Server::__construct() example

<?php
class API {
    /**
     * The doc block is shown on the service info page.
     * @param string $parameter
     * @return string
     */
    public function some_method($parameter, $option = "foo") {
         return "some_method";
    }

    protected function client_can_not_see() {
    }
}

$service = new Yar_Server(new API());
$service->handle();
?>

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.