Yar_Server::__construct
(PECL yar >= 1.0.0)
Create an RPC server
Description
Creates a Yar HTTP RPC server. All public methods of executor are registered as RPC services.
Parameters
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::handleand 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. SeeYar_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 theproviderandtokenfields of the request header, set by the client with theYAR_OPT_PROVIDERandYAR_OPT_TOKENoptions. Returning exactly false rejects the request; any other return value lets it proceed. SeeYar_Server::handle.
Both methods only take effect when they are
protected; a public or private method with the same name is ignored.
Return Values
An instance of Yar_Server.
Examples
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();
?>See Also
Yar_Server::handle