Created
May 8, 2012 10:34
-
-
Save hewerthomn/2634137 to your computer and use it in GitHub Desktop.
Arquivo de exemplo de classe abstrata Resource
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
<?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