blob: 36130c9d6e8fed4a138efe7c78e6e7fbdcaa377a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<?php
/**
* @author Robin J. Rogge <rrogge@bigpoint.net>
* @link http://www.pradosoft.com/
* @copyright 2010 Bigpoint GmbH
* @license http://www.pradosoft.com/license/
* @since 3.2
* @package Prado\Web\Services
*/
namespace Prado\Web\Services;
/**
* TRpcServer class
*
* TRpcServer is a class
*
* TRpcServer is the base class used to creare a server to be used in conjunction with
* {@link TRpcService}.
* The role of TRpcServer is to be an intermediate, moving data between the service and
* the provider. This base 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.
*
* @author Robin J. Rogge <rrogge@bigpoint.net>
* @package Prado\Web\Services
* @since 3.2
**/
class TRpcServer extends TModule
{
/**
* @var TRpcProtocol instance
*/
protected $handler;
/**
* Constructor
* @param TRpcProtocol $protocolHandler instance
*/
public function __construct(TRpcProtocol $protocolHandler)
{
$this->handler = $protocolHandler;
}
/**
* Registers the method in the protocol handler
* @param string $methodName
* @param array $methodDetails
*/
public function addRpcMethod($methodName, $methodDetails)
{
$this->handler->addMethod($methodName, $methodDetails);
}
/**
* Retrieves the request payload
* @return string request payload
*/
public function getPayload()
{
return file_get_contents('php://input');
}
/**
* Passes the request payload to the protocol handler and returns the result
* @return string rpc response
*/
public function processRequest()
{
try
{
return $this->handler->callMethod($this->getPayload());
}
catch(TRpcException $e)
{
return $this->handler->createErrorResponse($e);
}
}
}
|