function testParameter() { $r = new Rest\Server(); $r->setParameter("foo", "bar"); $this->assertEqual($r->getParameter("foo"), "bar"); }
// The handler can be a closure receiving the server instance // Or your own Controller that implements RestController $server->addMap("GET", "/", function ($server) { // This class will redirect to index.html return new Rest\Controller\Redirect("index.html"); }, array("*", "text/html")); // The last parameter on the mapping can override server accepted mimes $server->addMap("GET", "/index", function ($server) { // For the root access we will present the user interface // For this we have a dummy view that just loads up a php file return new Rest\View\Generic("ui.php"); }, array("text/html")); // Here we map POST /users to user creation function $server->addMap("POST", "/users", function ($server) { // Again we recover set global items $db = $server->getParameter("db"); $salt = $server->getParameter("salt"); // The full request of the user, including headers and post/put data // Is available on the RestRequest object, accesible using // The getRequest() method of the server $user = json_decode($server->getRequest()->getBody()); // This is the raw body of the request // We them test if it's unique $unique = $db->prepare("select count(*) from users where login = ?"); $unique->execute(array($user->login)); // If not we foward the server to the BadRequest handler if ($unique->fetchColumn(0) != 0) { new \Rest\Controller\BadRequest(); } // Them we really insert it $insert = $db->prepare("insert into users (login, password, name) values (?,?,?)");