Class \Prado\Web\Services\TRpcService
The TRpcService class is a generic class that can be extended and used to implement rpc services using different servers and protocols.
A server is a TModule that must subclass TRpcServer: its role is to be an intermediate, moving data between the service and the provider. The base TRpcServer class should suit the most common needs, but can be sublassed for logging and debugging purposes, or to filter and modify the request/response on the fly.
A protocol is a TModule that must subclass TRpcProtocol: its role is to implement the protocol that exposes the rpc api. Prado already implements two protocols: TXmlRpcProtocol for Xml-Rpc request and TJsonRpcProtocol for JSON-Rpc requests.
A provider is a TModule that must subclass TRpcApiProvider: its role is to implement the methods that are available through the api. Each defined api must be a sublass of the abstract class TRpcApiProvider and implement its methods.
The flow of requests and reponses is the following: Request <-> TRpcService <-> TRpcServer <-> TRpcProtocol <-> TRpcApiProvider <-> Response
To define an rpc service, add the proper application configuration:
<service id="rpc" class="Prado\Web\Services\TRpcService">
<rpcapi id="customers" class="Application.Api.CustomersApi" />
<modules>
<!-- register any module needed by the service here -->
</modules>
</service>
An api can be registered adding a proper <rpcapi ..> definition inside the service configuration. Each api definition must contain an id property and a class name expressed in namespace format. When the service receives a request for that api, the specified class will be instanciated in order to satisfy the request.
Class hierarchy
- \Prado\Web\Services\TRpcService
- \Prado\TService implements IService
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.2
public
|
createApiProvider(TRpcProtocol $protocolHandler, string $providerId) : mixed
Creates the API provider instance for the current request
|
public
|
|
public
|
|
public
|
public
mixed
|
BASE_API_PROVIDER
const string base api provider class which every API must extend
|
\Prado\Web\Services\TRpcApiProvider::class
|
public
mixed
|
BASE_RPC_SERVER
const string base RPC server implementation
|
\Prado\Web\Services\TRpcServer::class
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |