Yar_Server::handle

(PECL yar >= 1.0.0)

Yar_Server::handleStart the RPC server

Description

public function Yar_Server::handle(): bool

Starts handling the incoming RPC request.

Note:

Usual RPC calls are issued as HTTP POST requests. If an HTTP GET request is issued instead, the service information page, generated from the public methods and their doc comments of the executor object, is printed. This behaviour can be disabled with the yar.expose_info directive, in which case a GET request throws a Yar_Server_Exception.

Note:

As of Yar 2.3.0, the executor object may define the protected magic methods __info and __auth to customize the service information page and to authenticate requests; see Yar_Server::__construct() for details.

Parameters

This function has no parameters.

Return Values

Returns true.

Errors/Exceptions

Yar_Server::handle() errors
Condition Exception
The remote method threw an exception. Yar_Server_Exception (with the original class name in its _type property).
The remote method was not found or is not public. Yar_Server_Request_Exception.
The request body could not be unpacked. Yar_Server_Packager_Exception.
The request is malformed on the protocol level. Yar_Server_Protocol_Exception.
The server output could not be captured. Yar_Server_Output_Exception.
Authentication failed, or the info page was requested while yar.expose_info is off. Yar_Server_Exception with code YAR_ERR_FORBIDDEN.

Examples

Example #1 Yar_Server::handle() 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();
?>

Example #2 Customizing the service information page with __info (as of Yar 2.3.0)

<?php
class API {
    public function some_method($parameter, $option = "foo") {
        return "some_method";
    }

    /*
     * Must be protected. It is called on GET requests with the markup of
     * the page Yar would otherwise render, and its string return value is
     * sent to the client instead.
     */
    protected function __info($markup) {
        return "Hello world";
    }
}

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

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top