After integrating Symfony with Flex through Zend_Amf, I had to debug it and I needed some logs on server side.
Below I present my LoggedAmfServer extending Zend_Amf_Server, which logs all methods called by Flex and its’ responses. You need to pass instance of sfLogger (ie. sfFileLogger) in the constructor.
private $logger = null;
public function __construct(sfLogger $l) {
logger = $l;
parent::__construct();
}
protected function _handle(Zend_Amf_Request $request) {
$responseBody = $request->getAmfBodies();
$body = current($responseBody);
if ($body !== false) {
$data = $body->getData();
if ($data instanceof Zend_Amf_Value_Messaging_RemotingMessage) {
$this->logger->log(sprintf("[Amf Request] CLIENT: [%s] OPERATION: [%s]. PARAMETERS: [%s].",
$data->clientId, $data->operation, var_export($data->body, true)));
}
}
parent::_handle($request);
}
public function handle($request = null) {
$response = parent::handle($request);
$body = current($response->getAmfBodies());
if ($body !== false) {
$data = $body->getData();
$this->logger->log(sprintf("[Amf Response] CLIENT: [%s] RESPONSE: [%s]",
$data->clientId, var_export($data->body, true)));
}
return $response;
}
public function __construct(sfLogger $l) {
logger = $l;
parent::__construct();
}
protected function _handle(Zend_Amf_Request $request) {
$responseBody = $request->getAmfBodies();
$body = current($responseBody);
if ($body !== false) {
$data = $body->getData();
if ($data instanceof Zend_Amf_Value_Messaging_RemotingMessage) {
$this->logger->log(sprintf("[Amf Request] CLIENT: [%s] OPERATION: [%s]. PARAMETERS: [%s].",
$data->clientId, $data->operation, var_export($data->body, true)));
}
}
parent::_handle($request);
}
public function handle($request = null) {
$response = parent::handle($request);
$body = current($response->getAmfBodies());
if ($body !== false) {
$data = $body->getData();
$this->logger->log(sprintf("[Amf Response] CLIENT: [%s] RESPONSE: [%s]",
$data->clientId, var_export($data->body, true)));
}
return $response;
}
Hi, very nice post. Very usefull