Skip to content

Instantly share code, notes, and snippets.

@luniki
Last active December 19, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luniki/6006552 to your computer and use it in GitHub Desktop.
Save luniki/6006552 to your computer and use it in GitHub Desktop.
RouterMap.php-Methoden
<?
class RouteMap {
// [...]
// TODO (mlunzena): Implement these
// Set the Content-Type of the response body given a media type or
// file extension.
public function contentType($type, $params = array())
{
$this->error(501, "Not implemented");
}
// Halt processing and return the error status provided.
public function error($code, $body = null)
{
if (!$body) {
$body = $this->codeToString($code);
}
$this->halt($code, $body);
}
// Set the response entity tag (HTTP 'ETag' header) and halt if
// conditional GET matches. The value argument is an identifier
// that uniquely identifies the current version of the
// resource. The kind argument indicates whether the etag should
// be used as a :strong (default) or :weak cache validator. When
// the current request includes an 'If-None-Match' header with a
// matching etag, execution is immediately halted. If the request
// method is GET or HEAD, a '304 Not Modified' response is sent.
public function etag($value, $options = array())
{
$this->error(501, "Not implemented");
}
// To immediately stop a request within a filter or route use:
// $this->halt()
//
// You can also specify the status when halting:
// $this->halt(410)
//
// Or the body:
// $this->halt('this will be the body')
//
// Or both:
// $this->halt(401, 'go away!')
//
// With headers:
// $this->halt(402, array('Content-Type' => 'text/plain'), 'revenge')
//
// used in #error, #lastModified, #redirect etc.
public function halt(/* [code], [headers], [body] */)
{
# TODO
list($code, $headers, $body) = array();
throw new RouterHalt($code, $headers, $body);
}
// Set multiple response headers
public function headers($headers = array())
{
if (sizeof($headers)) {
$this->response->headers = array_merge($this->response->headers, $headers);
}
return $this->response->headers;
}
// Set the last modified time of the resource (HTTP Last-Modified
// header) and halt if conditional GET matches. The time argument
// is a Time, DateTime, or other object that responds to to_time.
// When the current request includes an 'If-Modified-Since' header
// that is equal or later than the time specified, execution is
// immediately halted with a '304 Not Modified' response.
public function lastModified($time)
{
$this->error(501, "Not implemented");
}
// Halt processing and return a 404 Not Found.
public function not_found($body = null)
{
$this->error(404, $body);
}
// Halt processing and redirect to the URI provided.
public function redirect($url)
{
$this->response->headers['Location'] = $this->url($url);
$status = $_SERVER["SERVER_PROTOCOL"] == 'HTTP/1.1' && !Request::isGet()
? 303 : 302;
$this->halt($status);
}
// Set the response status code.
public function status($code)
{
$this->response->status = $code;
}
// Generates the absolute URI for a given path
public function url($addr, $absolute = true)
{
$this->error(501, "Not implemented");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment