Last active
October 11, 2015 20:38
-
-
Save stacyhorton/3916418 to your computer and use it in GitHub Desktop.
A better way to check class constants in setters from ZF2's Zend\Http\Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Request { | |
const METHOD_OPTIONS = 'OPTIONS'; | |
const METHOD_GET = 'GET'; | |
const METHOD_HEAD = 'HEAD'; | |
const METHOD_POST = 'POST'; | |
const METHOD_PUT = 'PUT'; | |
const METHOD_DELETE = 'DELETE'; | |
const METHOD_TRACE = 'TRACE'; | |
const METHOD_CONNECT = 'CONNECT'; | |
const METHOD_PATCH = 'PATCH'; | |
protected $method = self::METHOD_GET; | |
public function setMethod ($method) { | |
$method = strtoupper($method); | |
if (!defined('static::METHOD_' . $method)) { | |
throw new Exception\InvalidArgumentException('Invalid HTTP method passed'); | |
} | |
$this->method = $method; | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment