(PECL yar >= 1.0.0)
Yar_Server::__construct — Create an RPC server
Creates a Yar HTTP RPC server. All public methods of
executor are registered as RPC services.
executorAny 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();
?>