本文整理汇总了PHP中Zend_Amf_Request::getAmfBodies方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Amf_Request::getAmfBodies方法的具体用法?PHP Zend_Amf_Request::getAmfBodies怎么用?PHP Zend_Amf_Request::getAmfBodies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Amf_Request
的用法示例。
在下文中一共展示了Zend_Amf_Request::getAmfBodies方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processResponseBodies
/**
* Builds a composite AMF response based on the response bodies inside the
* original AMF request.
*
* @return Zend_Amf_Response_Http
*/
public function processResponseBodies()
{
$responseBodies = $this->request->getAmfBodies();
foreach ($responseBodies as $body) {
//Extract params from request body
$return = $this->extractUriAndParams($body);
//Create fake request object
$liRequest = new Request(array('data' => $return['params']));
//Assign URL to request based on details
if (isset($return['source'])) {
$liRequest->url = '/' . $return['source'] . '/' . $return['method'];
} elseif (isset($return['targetURI'])) {
$liRequest->url = '/' . $return['targetURI'];
}
//Assign request params
$liRequest->params += $return['params'];
//Dispatch the request normally, and get the controller data
$controllerResponse = Dispatcher::run($liRequest);
//Add on the response data (or error) to the current response
if (isset($controllerResponse->body['error'])) {
$netStatusEvent = new StdClass();
$netStatusEvent->_explicitType = 'flex.messaging.messages.ErrorMessage';
$netStatusEvent->faultString = $controllerResponse->body['error'];
$newBody = new \Zend_Amf_Value_MessageBody($body->getResponseURI() . \Zend_AMF_Constants::STATUS_METHOD, null, $netStatusEvent);
$this->response->addAmfBody($newBody);
} else {
$newBody = new \Zend_Amf_Value_MessageBody($body->getResponseURI() . \Zend_AMF_Constants::STATUS_METHOD, null, $controllerResponse->body);
$this->response->addAmfBody($newBody);
}
}
return $this->response;
}
示例2: testAmf0TypedObjecDeserializedToNativePHPObjectUnknownType
public function testAmf0TypedObjecDeserializedToNativePHPObjectUnknownType()
{
$myRequest = file_get_contents(dirname(__FILE__) . '/Request/mock/bogusTypedObjectAmf0Request.bin');
// send the mock object request to be deserialized
$this->_request->initialize($myRequest);
$requestBodies = $this->_request->getAmfBodies();
$messageBody = reset($requestBodies);
$data = $messageBody->getData();
$dataObject = reset($data);
$this->assertEquals('stdClass', get_class($dataObject));
}
示例3: _handle
/**
* Takes the deserialized AMF request and performs any operations.
*
* @todo should implement and SPL observer pattern for custom AMF headers
* @todo DescribeService support
* @param Zend_Amf_Request $request
* @return Zend_Amf_Response
* @throws Zend_Amf_server_Exception|Exception
*/
protected function _handle(Zend_Amf_Request $request)
{
// Get the object encoding of the request.
$objectEncoding = $request->getObjectEncoding();
// create a response object to place the output from the services.
$response = $this->getResponse();
// set response encoding
$response->setObjectEncoding($objectEncoding);
$responseBody = $request->getAmfBodies();
$handleAuth = false;
if ($this->_auth) {
$headers = $request->getAmfHeaders();
if (isset($headers[Zend_Amf_Constants::CREDENTIALS_HEADER]) && isset($headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->userid)) {
$handleAuth = true;
}
}
// Iterate through each of the service calls in the AMF request
foreach ($responseBody as $body) {
try {
if ($handleAuth) {
if ($this->_handleAuth($headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->userid, $headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->password)) {
// use RequestPersistentHeader to clear credentials
$response->addAmfHeader(new Zend_Amf_Value_MessageHeader(Zend_Amf_Constants::PERSISTENT_HEADER, false, new Zend_Amf_Value_MessageHeader(Zend_Amf_Constants::CREDENTIALS_HEADER, false, null)));
$handleAuth = false;
}
}
if ($objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) {
// AMF0 Object Encoding
$targetURI = $body->getTargetURI();
$message = '';
// Split the target string into its values.
$source = substr($targetURI, 0, strrpos($targetURI, '.'));
if ($source) {
// Break off method name from namespace into source
$method = substr(strrchr($targetURI, '.'), 1);
$return = $this->_dispatch($method, $body->getData(), $source);
} else {
// Just have a method name.
$return = $this->_dispatch($targetURI, $body->getData());
}
} else {
// AMF3 read message type
$message = $body->getData();
if ($message instanceof Zend_Amf_Value_Messaging_CommandMessage) {
// async call with command message
$return = $this->_loadCommandMessage($message);
} elseif ($message instanceof Zend_Amf_Value_Messaging_RemotingMessage) {
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
$return = new Zend_Amf_Value_Messaging_AcknowledgeMessage($message);
$return->body = $this->_dispatch($message->operation, $message->body, $message->source);
} else {
// Amf3 message sent with netConnection
$targetURI = $body->getTargetURI();
// Split the target string into its values.
$source = substr($targetURI, 0, strrpos($targetURI, '.'));
if ($source) {
// Break off method name from namespace into source
$method = substr(strrchr($targetURI, '.'), 1);
$return = $this->_dispatch($method, $body->getData(), $source);
} else {
// Just have a method name.
$return = $this->_dispatch($targetURI, $body->getData());
}
}
}
$responseType = Zend_AMF_Constants::RESULT_METHOD;
} catch (Exception $e) {
$return = $this->_errorMessage($objectEncoding, $message, $e->getMessage(), $e->getTraceAsString(), $e->getCode(), $e->getLine());
$responseType = Zend_AMF_Constants::STATUS_METHOD;
}
$responseURI = $body->getResponseURI() . $responseType;
$newBody = new Zend_Amf_Value_MessageBody($responseURI, null, $return);
$response->addAmfBody($newBody);
}
// Add a session header to the body if session is requested.
if ($this->isSession()) {
$currentID = session_id();
$joint = "?";
if (isset($_SERVER['QUERY_STRING'])) {
if (!strpos($_SERVER['QUERY_STRING'], $currentID) !== FALSE) {
if (strrpos($_SERVER['QUERY_STRING'], "?") !== FALSE) {
$joint = "&";
}
}
}
// create a new AMF message header with the session id as a variable.
$sessionValue = $joint . $this->_sessionName . "=" . $currentID;
$sessionHeader = new Zend_Amf_Value_MessageHeader(Zend_Amf_Constants::URL_APPEND_HEADER, false, $sessionValue);
$response->addAmfHeader($sessionHeader);
}
// serialize the response and return serialized body.
//.........这里部分代码省略.........
示例4: _handle
/**
* Takes the deserialized AMF request and performs any operations.
*
* @todo should implement and SPL observer pattern for custom AMF headers
* @todo implement AMF header authentication
* @param Zend_Amf_Request $request
* @return Zend_Amf_Response
* @throws Zend_Amf_server_Exception|Exception
*/
protected function _handle(Zend_Amf_Request $request)
{
// Get the object encoding of the request.
$objectEncoding = $request->getObjectEncoding();
// create a response object to place the output from the services.
$response = $this->getResponse();
// set reponse encoding
$response->setObjectEncoding($objectEncoding);
$responseBody = $request->getAmfBodies();
// Iterate through each of the service calls in the AMF request
foreach ($responseBody as $body) {
try {
if ($objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) {
// AMF0 Object Encoding
$targetURI = $body->getTargetURI();
// Split the target string into its values.
$source = substr($targetURI, 0, strrpos($targetURI, '.'));
if ($source) {
// Break off method name from namespace into source
$method = substr(strrchr($targetURI, '.'), 1);
$return = $this->_dispatch($method, $body->getData(), $source);
} else {
// Just have a method name.
$return = $this->_dispatch($targetURI, $body->getData());
}
} else {
// AMF3 read message type
$message = $body->getData();
if ($message instanceof Zend_Amf_Value_Messaging_CommandMessage) {
// async call with command message
$return = $this->_loadCommandMessage($message);
} elseif ($message instanceof Zend_Amf_Value_Messaging_RemotingMessage) {
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
$return = new Zend_Amf_Value_Messaging_AcknowledgeMessage($message);
$return->body = $this->_dispatch($message->operation, $message->body, $message->source);
} else {
// Amf3 message sent with netConnection
$targetURI = $body->getTargetURI();
// Split the target string into its values.
$source = substr($targetURI, 0, strrpos($targetURI, '.'));
if ($source) {
// Break off method name from namespace into source
$method = substr(strrchr($targetURI, '.'), 1);
$return = $this->_dispatch($method, array($body->getData()), $source);
} else {
// Just have a method name.
$return = $this->_dispatch($targetURI, $body->getData());
}
}
}
$responseType = Zend_AMF_Constants::RESULT_METHOD;
} catch (Exception $e) {
switch ($objectEncoding) {
case Zend_Amf_Constants::AMF0_OBJECT_ENCODING:
$return = array('description' => $this->isProduction() ? '' : $e->getMessage(), 'detail' => $this->isProduction() ? '' : $e->getTraceAsString(), 'line' => $this->isProduction() ? 0 : $e->getLine(), 'code' => $e->getCode());
break;
case Zend_Amf_Constants::AMF3_OBJECT_ENCODING:
require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
$return = new Zend_Amf_Value_Messaging_ErrorMessage($message);
$return->faultString = $this->isProduction() ? '' : $e->getMessage();
$return->faultCode = $e->getCode();
$return->faultDetail = $this->isProduction() ? '' : $e->getTraceAsString();
break;
}
$responseType = Zend_AMF_Constants::STATUS_METHOD;
}
$responseURI = $body->getResponseURI() . $responseType;
$newBody = new Zend_Amf_Value_MessageBody($responseURI, null, $return);
$response->addAmfBody($newBody);
}
// serialize the response and return serialized body.
$response->finalize();
}