/** * Instantiate a new Document object depending on content type * * @param Spizer_Request $request * @param Spizer_Response $response * @return Spizer_Document */ public static function factory(Spizer_Request $request, Spizer_Response $response) { $url = $request->getUri(); $code = $response->getStatus(); $headers = $response->getAllHeaders(); $body = $response->getBody(); // Find out the content type of the document if (isset($headers['content-type'])) { preg_match('/^[^;\\s]+/', $headers['content-type'], $m); $type = $m[0]; unset($m); } else { $type = ''; } switch ($type) { case 'text/html': case 'text/xhtml': $class = 'Spizer_Document_Html'; break; case 'text/xml': case 'application/xml': $class = 'Spizer_Document_Xml'; break; default: $class = 'Spizer_Document'; break; } Zend_Loader::loadClass($class); return new $class($url, $code, $headers, $body); }
/** * Log the response received from server * * @param Spizer_Response $response * @see Spizer_Logger_Interface::logResponse() * @return void */ public function logResponse(Spizer_Response $response) { $this->_writer->startElement('response'); $this->_writer->writeAttribute('microtime', microtime(true)); $this->_writer->writeElement('status', $response->getStatus()); $this->_writer->writeElement('message', $response->getMessage()); // Log response headers if ($this->_config['logheaders']) { foreach ($response->getHeaders() as $header => $value) { $this->_logHeader($header, $value); } } $this->_writer->endElement(); // response }
/** * Log response information * * @param Spizer_Response $response */ public function logResponse(Spizer_Response $response) { $this->_db->insert('responses', array('microtime' => microtime(true), 'request_id' => $this->_currentReqId, 'statuscode' => $response->getStatus(), 'message' => $response->getMessage())); $stmt = $this->_db->prepare("INSERT INTO response_headers (request_id, header, value) VALUES ({$this->_currentReqId}, ?, ?)"); foreach ($response->getAllHeaders() as $k => $v) { $stmt->execute(array($k, $v)); } }