ZF-4149: Tweak Zend_Controller_Action_Helper_Redirector::setCode()/_checkCode() method signature and accepted values
Description
The current method definition:
/**
* Validate HTTP status redirect code
*
* @param int $code
* @throws Zend_Controller_Action_Exception on invalid HTTP status code
* @return true
*/
protected function _checkCode($code)
{
$code = (int)$code;
if ((300 > $code) || (307 < $code)) {
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid redirect HTTP status code (' . $code . ')');
}
return true;
}
Propose 1: Change the method to accept string, a HTTP code is not an integer, string is the correct type to use. Propose 2: Be more correct about the accepted codes: Currently the method accepts invalid redirect codes.
From the HTTP/1.1 RFC (http://w3.org/Protocols/rfc2616/…): - 307 Temporary Redirect - Valid - 306 (Unused) - Invalid - 305 Use Proxy - Valid - 304 Not Modified - Invalid (not a redirect) - 303 See Other - Valid - 302 Found - Valid - 301 Moved Permanently - Valid - 300 Multiple Choices - Valid
Improved class proposal:
/**
* HTTP status code for redirects
* @var string
*/
protected $_code = '302';
...
/**
* Validate HTTP status redirect code
*
* @param string $code
* @throws Zend_Controller_Action_Exception on invalid HTTP status code
* @return true
*/
protected function _checkCode($code)
{
$code = (string)$code;
if (false === in_array($code, array('300', '301', '302', '303', '305', '307'))) {
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
throw new Zend_Controller_Action_Exception('Invalid redirect HTTP status code (' . $code . ')');
}
return true;
}
/**
* Retrieve HTTP status code for {@link _redirect()} behaviour
*
* @param string $code
* @return Zend_Controller_Action_Helper_Redirector Provides a fluent interface
*/
public function setCode($code)
{
$this->_checkCode($code);
$this->_code = $code;
return $this;
}
Comments
Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2008-09-01T06:30:25.000+0000
Doc may be influenced.
Posted by Matthew Weier O'Phinney (matthew) on 2008-09-10T12:09:16.000+0000
Fixed in trunk and 1.6 release branch