Пример #1
0
 function dispatch()
 {
     $tpl = $this->template->create('404');
     $response = new k_HtmlResponse($tpl->render($this));
     $response->setStatus(404);
     return $response;
 }
Пример #2
0
 function renderHtml()
 {
     $this->document->setTitle('Login');
     $response = new k_HtmlResponse("<form method='post' action='" . htmlspecialchars($this->url()) . "'>\n  <p>\n    <label>\n      Brugernavn\n      <input type='text' name='username' />\n    </label>\n  </p>\n  <p>\n    <label>\n      Adgangskode\n      <input type='password' name='password' />\n    </label>\n  </p>\n  <p>\n    <input type='submit' value='Login' />\n  </p>\n</form>\n");
     $response->setStatus(401);
     return $response;
 }
Пример #3
0
 function test_404_response_should_output_custom_content_if_any()
 {
     $output = new k_adapter_DummyOutputAccess();
     $response = new k_HtmlResponse("I didn't find it");
     $response->setStatus(404);
     $response->out($output);
     $this->assertEqual(404, $output->http_response_code);
     $this->assertEqual("I didn't find it", $output->body);
 }
Пример #4
0
 function decorate(k_Response $response)
 {
     if ($response->status() >= 300 && $response->status() < 400) {
         return new k_HtmlResponse($this->render($response, true));
     }
     if ($response instanceof k_HtmlResponse) {
         $html = $response->toContentType('text/html');
         if (strpos($html, '</body>') === false) {
             $body = $html . $this->render($response, false);
         } else {
             $body = str_replace('</body>', $this->render($response, false) . '</body>', $html);
         }
         $out = new k_HtmlResponse($body);
         $out->setStatus($response->status());
         $out->setCharset($response->charset());
         foreach ($response->headers() as $key => $value) {
             $out->setHeader($key, $value);
         }
         return $out;
     }
     return $response;
 }
Пример #5
0
 function renderHtml()
 {
     $response = new k_HtmlResponse("<html><head><title>Authentication required</title></head><body><form method='post' action='" . htmlspecialchars($this->url()) . "'>\n  <h1>Authentication required</h1>\n  <p>\n    <label>\n      username:\n      <input type='text' name='username' />\n    </label>\n  </p>\n  <p>\n    <label>\n      password:\n      <input type='password' name='password' />\n    </label>\n  </p>\n  <p>\n    <input type='submit' value='Login' />\n  </p>\n</form></body></html>");
     $response->setStatus(401);
     return $response;
 }
Пример #6
0
 function renderHtml()
 {
     $response = new k_HtmlResponse("<html><head><title>Authentication required</title></head><body><form method='post' action='" . htmlspecialchars($this->url()) . "'>\n  <h1>Authentication required</h1>\n  <h2>OpenID Login</h2>\n  <p>\n" . implode("<br/>", $this->errors) . "\n  </p>\n  <p>\n    <label>\n      open-id url:\n      <input type='text' name='openid_identifier' value='' />\n    </label>\n  </p>\n  <p>\n    <input type='submit' value='Login' />\n  </p>\n</form></body></html>");
     $response->setStatus(401);
     return $response;
 }
Пример #7
0
 protected function dispatchRoot($root_class_name)
 {
     try {
         $class_name = $root_class_name;
         while (true) {
             try {
                 $root = $this->components()->create($class_name, $this->context());
                 $response = $root->dispatch();
                 if (!$response instanceof k_Response) {
                     $response = new k_HtmlResponse($response);
                 }
                 $response->setCharset($this->charsetStrategy()->responseCharset());
                 return $response;
             } catch (k_MetaResponse $ex) {
                 $class_name = $ex->componentName();
             }
         }
     } catch (k_Response $ex) {
         return $ex;
     }
 }
Пример #8
0
 function test_html_response_can_be_constructed_from_a_text_response()
 {
     $t1 = new k_TextResponse("Foo & Bar");
     $h = new k_HtmlResponse($t1);
     $this->assertEqual($h->toContentType('text/html'), "Foo &amp; Bar");
 }