7 public $restful, $method, $controller, $action, $id, $params;
9 public function __construct($params) {
10 $this->restful = (isset($params["restful"])) ? $params["restful"] : false;
11 $this->method = $_SERVER["REQUEST_METHOD"];
12 $this->parseRequest();
14 public function isRestful() {
15 return $this->restful;
17 protected function parseRequest() {
18 if ($this->method == 'PUT') { // <-- Have to jump through hoops to get PUT data
20 $httpContent = fopen('php://input', 'r');
21 while ($kb = fread($httpContent, 1024)) {
26 parse_str($raw, $params);
27 $this->id = (isset($params['id'])) ? $params['id'] : null;
28 $this->params = (isset($params['data'])) ? json_decode(stripslashes($params['data']), true) : null;
30 // grab JSON data if there...
31 $this->params = (isset($_REQUEST['data'])) ? json_decode(stripslashes($_REQUEST['data']), true) : null;
32 $this->id = (isset($_REQUEST['id'])) ? json_decode(stripslashes($_REQUEST['id']), true) : null;
34 // Quickndirty PATH_INFO parser
35 if (isset($_SERVER["PATH_INFO"])){
36 $cai = '/^\/([a-z]+\w)\/([a-z]+\w)\/([0-9]+)$/'; // /controller/action/id
37 $ca = '/^\/([a-z]+\w)\/([a-z]+)$/'; // /controller/action
38 $ci = '/^\/([a-z]+\w)\/([0-9]+)$/'; // /controller/id
39 $c = '/^\/([a-z]+\w)$/'; // /controller
40 $i = '/^\/([0-9]+)$/'; // /id
42 if (preg_match($cai, $_SERVER["PATH_INFO"], $matches)) {
43 $this->controller = $matches[1];
44 $this->action = $matches[2];
45 $this->id = $matches[3];
46 } else if (preg_match($ca, $_SERVER["PATH_INFO"], $matches)) {
47 $this->controller = $matches[1];
48 $this->action = $matches[2];
49 } else if (preg_match($ci, $_SERVER["PATH_INFO"], $matches)) {
50 $this->controller = $matches[1];
51 $this->id = $matches[2];
52 } else if (preg_match($c, $_SERVER["PATH_INFO"], $matches)) {
53 $this->controller = $matches[1];
54 } else if (preg_match($i, $_SERVER["PATH_INFO"], $matches)) {
55 $this->id = $matches[1];