Skip to content

Instantly share code, notes, and snippets.

@stacyhorton
Last active October 11, 2015 20:38
Show Gist options
  • Save stacyhorton/3916418 to your computer and use it in GitHub Desktop.
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
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