Skip to content

Instantly share code, notes, and snippets.

@hewerthomn
Created May 8, 2012 10:34
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 hewerthomn/2634137 to your computer and use it in GitHub Desktop.
Save hewerthomn/2634137 to your computer and use it in GitHub Desktop.
Arquivo de exemplo de classe abstrata Resource
<?php
abstract class Resource
{
protected static $httpMethods = array("GET", "POST", "HEAD",
"PUT", "OPTIONS", "DELETE", "TRACE", "CONNECT");
protected $params;
public function __construct(array $params) {
$this->params = $params;
}
protected function allowedHttpMethods() {
$myMethods = array();
$r = new \ReflectionClass($this);
foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $rm) {
$myMethods[] = strtoupper($rm->name);
}
return array_intersect(self::$httpMethods, $myMethods);
}
public function __call($method, $arguments) {
header("HTTP/1.1 405 Method Not Allowed", true, 405);
header("Allow: " . join($this->allowedHttpMethods(), ", "));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment