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);
28 if (isset($params['data'])) {
29 $this->params = json_decode(stripslashes($params['data']));
31 $params = json_decode(stripslashes($raw));
32 $this->params = $params->data;
35 // grab JSON data if there...
36 $this->params = (isset($_REQUEST['data'])) ? json_decode(stripslashes($_REQUEST['data'])) : null;
38 if (isset($_REQUEST['data'])) {
39 $this->params = json_decode(stripslashes($_REQUEST['data']));
42 $httpContent = fopen('php://input', 'r');
43 while ($kb = fread($httpContent, 1024)) {
46 $params = json_decode(stripslashes($raw));
48 $this->params = $params->data;
53 // Quickndirty PATH_INFO parser
54 if (isset($_SERVER["PATH_INFO"])){
55 $cai = '/^\/([a-z]+\w)\/([a-z]+\w)\/([0-9]+)$/'; // /controller/action/id
56 $ca = '/^\/([a-z]+\w)\/([a-z]+)$/'; // /controller/action
57 $ci = '/^\/([a-z]+\w)\/([0-9]+)$/'; // /controller/id
58 $c = '/^\/([a-z]+\w)$/'; // /controller
59 $i = '/^\/([0-9]+)$/'; // /id
61 if (preg_match($cai, $_SERVER["PATH_INFO"], $matches)) {
62 $this->controller = $matches[1];
63 $this->action = $matches[2];
64 $this->id = $matches[3];
65 } else if (preg_match($ca, $_SERVER["PATH_INFO"], $matches)) {
66 $this->controller = $matches[1];
67 $this->action = $matches[2];
68 } else if (preg_match($ci, $_SERVER["PATH_INFO"], $matches)) {
69 $this->controller = $matches[1];
70 $this->id = $matches[2];
71 } else if (preg_match($c, $_SERVER["PATH_INFO"], $matches)) {
72 $this->controller = $matches[1];
73 } else if (preg_match($i, $_SERVER["PATH_INFO"], $matches)) {
74 $this->id = $matches[1];