Ejemplo n.º 1
0
 private function renderResponse(MMapResponse $response)
 {
     if (!$response->isValid()) {
         if (self::$Logger->isInfoEnabled()) {
             self::$Logger->info('Skipping invalid response: ' . $response);
         }
         return;
     }
     try {
         // headers
         foreach ($response->getHeaders() as $headerField) {
             self::$Logger->info($headerField);
             if (is_array($headerField)) {
                 if (isset($headerField[1])) {
                     if (isset($headerField[2])) {
                         header($headerField[0], $headerField[1], $headerField[2]);
                     } else {
                         header($headerField[0], $headerField[1]);
                     }
                 } else {
                     header($headerField[0]);
                 }
             } else {
                 //if ( !ob_get_status() ) {
                 header($headerField);
                 //}
             }
         }
         // body
         $bodyRenderer = $response->getBodyRenderer();
         if ($bodyRenderer !== null) {
             self::$Logger->info('Using BodyRenderer: ' . $bodyRenderer);
             $bodyRenderer->doRender();
         } else {
             self::$Logger->info('Using raw body');
             echo $response->getBody();
         }
     } catch (Exception $e) {
         self::$Logger->error('Exception caught while rendering response!');
         self::$Logger->error('Exception message: ' . $e->getMessage());
         if (self::$Logger->isDebugEnabled()) {
             self::$Logger->debug(ExceptionStackUtil::getStackTrace($e, false));
             self::$Logger->debug((string) $response);
         }
         // the exception will be finally caught by the general try/catch block in index.php
         throw $e;
     }
 }