peterhorne / elmer

A simple and flexible framework for PHP
4 stars 1 forks source link

Redirect method in Elmer\Response #2

Closed peterhorne closed 12 years ago

peterhorne commented 12 years ago

Something like:

<?php
$response = new Elmer\Response;
$response->redirect('/foo');

Should auto add scheme + host + script as a prefix... need to figure a way to make this information available to the response object. Ideally without having to pass in the request object as a dependency.

peterhorne commented 12 years ago

If we use pimple then we can access Elmer\Request within Elmer\Response so building up the full url for the redirect header shouldn't be a problem!

peterhorne commented 12 years ago

Closed as wontfix because relative location headers are now allowed by the spec(http://trac.tools.ietf.org/wg/httpbis/trac/ticket/185) and having a redirect method will be redundant with PHP 5.4 short array syntax:

<?php
// PHP 5.4
$route->get('/', function() {
    return [301, ['Location' => '/foundme']];
});

// PHP 5.3
$route->get('/', function() {
    return array(301, array('Location' => '/foundme'));
});

The code is no more readable if it uses a redirect method (as a $response instance has to be instantiated):

<?php
$route->get('/', function() {
    $response = new Response;
    return $response->redirect(301, '/foundme');
});