[Zend_Amf + Symfony + Flex] Server with Logger

July 18th, 2010 by damian Leave a reply »

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;
}
Advertisement

1 comment

  1. Hi, very nice post. Very usefull

Leave a Reply

Flexmaniaks on Facebook