示例#1
0
 function handleRequest(RequestInterface $request)
 {
     $this->request = $request;
     $response = new Response(array('headers' => array('Content-Type' => $this->getConfig('default_content_type'), 'Content-Language' => $this->getConfig('default_language'))));
     try {
         if (!$this->qualify($this->getPathComponents())) {
             throw new NotFound();
         }
         $response->setContent($this->runIfExists($request->getMethod()));
     } catch (NotFound $e) {
         $response->setStatus(404);
     } catch (MethodUndefined $e) {
         $response->setStatus(405);
         $response->setHeader('Allow', $this->getDefinedMethods());
     } catch (Redirect $e) {
         $payload = $e->getPayload();
         $response->setStatus($payload['status_code']);
         $response->setHeader('Location', $payload['location']);
         if (isset($payload['locations_list'])) {
             $response->setHeader('Asar-Internal-Locationslist', $payload['locations_list']);
         }
     } catch (ForwardRequest $e) {
         throw $e;
     } catch (\Exception $e) {
         $response->setStatus(500);
         $response->setContent($e->getMessage());
     }
     return $response;
 }
 function testStatusMessage500Sureness()
 {
     $request = new Request();
     $response = new Response(array('status' => 500));
     $response->setContent('The error message');
     $msg = $this->SM->getMessage($response, $request);
     $this->assertContains("The Server has encountered some problems.\nThe error message", $msg, "{$msg} does not contain required full message.");
 }
 function testExportOutputsContentOfResponse()
 {
     $response = new Response();
     $response->setContent('The quick brown fox.');
     ob_start();
     $this->exporter->exportResponse($response);
     $content = ob_get_clean();
     $this->assertEquals('The quick brown fox.', $content);
 }