phalconplus Documentation v1.2.0
Class PhalconPlus Rpc

Yar

    //  di = null, string formater = "json")
	{
        parent::__construct(di);
		var rawBody = this->__get("request")->getRawBody();
		if "json" == formater {
			let this->formater = formater;
			let this->encoder = "json_encode";
			let this->requestArgs = json_decode(rawBody, true);
		} else {
			let this->requestArgs = msgpack_unpack(rawBody);
		}
	}

	public function setServer( obj)
	{
		let this->serviceObj = obj;
		return this;
	}

	public function handle()
	{
		var serviceName = get_class(this->serviceObj);
		var sampleCodes;
		let  sampleCodes = "callByObject([
	\"service\" => \"\\Demo\\Services\\Dummy\",
	\"method\" => \"demo\",
	\"args\"   => [
		\"foo\" => \"bar\",
	],
]);
var_export($result);
";
		var  expectedRet = " 0,
	'errorMsg' => '',
	'logId' => 'da0abdea3483146cd8',
	'data' => array (
		'params' => array (
			'foo' => 'bar',
		),
	),
)
";
		if this->__get("request")->isGet() {
			let this->responseBody = "
			
			 
			  
			  " . serviceName . " - Phalcon+ Server
			  
			  
			 
			 
				

Phalcon+ Server: " . serviceName . "

Code Samples:

" . str_replace("<?php", "// Client", highlight_string(sampleCodes, true)) . "

-------------- Expected Result --------------

" . str_replace("<?php", "// Return", highlight_string(expectedRet, true)) . "

"; } elseif this->__get("request")->isPost() { var e = null; var ret = [ "errorCode" : 0, "errorMsg" : "", "data" : [] ]; try { if empty this->requestArgs { throw new \Exception("invalid request args"); } if empty this->serviceObj { let this->serviceObj = this->getDi()->get("backendSrv"); } let ret["data"] = this->serviceObj->callByObject(this->requestArgs); } catch \Exception, e { let ret["errorCode"] = max(e->getCode(), 1); let ret["errorMsg"] = e->getMessage(); } // Must do this after `callByObject` let ret["logId"] = this->__get("logger")->logId; string encoder = this->encoder; let this->responseBody = {encoder}(ret); } echo this->responseBody; // var response; // let response = new \Phalcon\Http\Response(); // response->setStatusCode(200, "OK"); // response->setContent(this->responseBody); // return response; } }