public function postLoginUser(Router $r) { $r->post('/ajax/ControleUsuario/login/*/*', function ($email, $senha) { $em = Container::gerEntityManager(); $c = new ControleUsuario($em); $json_str = file_get_contents("/var/www/minichat3des/public/js/srp.json"); $jsrc = json_decode($json_str, true); extract($jsrc); $login = array("email" => mcrypt_decrypt(MCRYPT_3DES, $k, hexToString($email), MCRYPT_MODE_CBC, hexToString($iv)), "senha" => $senha); $rsp = $c->login($login); if ($rsp) { header("/chat"); } }); }
public function postLoguot(Router $r) { $r->post("/ajax/ControleUsuario/logout", function () { $sessao = Container::getSession(); $sessao->unsetKey("usuario"); echo "Loged out"; }); }
<?php require "database.php"; error_reporting(E_ALL); ini_set('display_errors', 'on'); set_time_limit(0); use Respect\Rest\Router; $router = new Router(); $router->get('/', function () { require "views/default.php"; }); $router->any('/devs/*', '\\Beeblebrox3\\DevShop\\Controllers\\Devs'); $router->any('/cart', '\\Beeblebrox3\\DevShop\\Controllers\\Cart'); $router->post('/cart/apply-cupom', function () { $controller = new \Beeblebrox3\DevShop\Controllers\Cart(); $controller->applyCupom(); }); $router->post('/cart/buy/', function () { $controller = new Beeblebrox3\DevShop\Controllers\Cart(); $controller->buy(); }); $router->delete('/cart/*', '\\Beeblebrox3\\DevShop\\Controllers\\Cart'); $router->post('/config', function () { $controller = new Beeblebrox3\DevShop\Controllers\Config(); $controller->import(); }); $router->exceptionRoute('InvalidArgumentException', function (InvalidArgumentException $e) { return 'Sorry, this error happened: ' . $e->getMessage(); }); $router->errorRoute(function ($a = null) { print_r($a);
/** * @covers Respect\Rest\Router::dispatchRequest * @covers Respect\Rest\Router::isRoutelessDispatch * @covers Respect\Rest\Router::hasDispatchedOverridenMethod */ public function testDeveloperCanOverridePostMethodWithQueryStringParameter() { $_REQUEST['_method'] = 'PUT'; $router = new Router(); $router->methodOverriding = true; $router->put('/bulbs', 'Some Bulbs Put Response'); $router->post('/bulbs', 'Some Bulbs Post Response'); $result = (string) $router->dispatch('POST', '/bulbs')->response(); $this->assertSame('Some Bulbs Put Response', $result, 'Router should dispatch to PUT (overriden) instead of POST'); $this->assertNotSame('Some Bulbs Post Response', $result, 'Router NOT dispatch to POST when method is overriden'); return $router; }
/** * @covers Respect\Rest\Router::handleOptionsRequest * @runInSeparateProcess */ public function testOptionsRequestShouldBeDispatchedToCorrectOptionsHandler() { // arrange $router = new Router(); $router->get('/asian', 'GET: Asian Food!'); $router->options('/asian', 'OPTIONS: Asian Food!'); $router->post('/asian', 'POST: Asian Food!'); // act $response = (string) $router->dispatch('OPTIONS', '/asian')->response(); // assert $this->assertContains('Allow: GET, OPTIONS, POST', xdebug_get_headers(), 'There should be a sent Allow header with all methods for the handler that match this request.'); $this->assertEquals('OPTIONS: Asian Food!', $response, 'OPTIONS request should call the correct custom OPTIONS handler.'); }
foreach ($db->books() as $book) { $books[] = array('id' => $book['id'], 'title' => $book['title'], 'author' => $book['author'], 'summary' => $book['summary']); } return $books; })->accept(array('application/json' => 'json_encode')); $r3->get('/book/*', function ($id) use($db) { $book = $db->books()->where('id', $id); if ($data = $book->fetch()) { return array('id' => $data['id'], 'title' => $data['title'], 'author' => $data['author'], 'summary' => $data['summary']); } else { return array('status' => false, 'message' => sprintf('Book ID %s does not exist', $id)); } })->accept(array('application/json' => 'json_encode')); $r3->post('/book', function () use($db) { $book = array('title' => $_POST['title'], 'author' => $_POST['author'], 'summary' => $_POST['summary']); $result = $db->books->insert($book); return array('id' => $result['id']); })->accept(array('application/json' => 'json_encode')); $r3->put('/book/*', function ($id) use($db) { $book = $db->books()->where('id', $id); if ($book->fetch()) { parse_str(file_get_contents('php://input'), $put); $result = $book->update($put); return array('status' => (bool) $result, 'message' => 'Book updated successfully'); } else { return array('status' => false, 'message' => sprintf('Book id %s does not exist', $id)); } })->accept(array('application/json' => 'json_encode')); $r3->delete('/book/*', function ($id) use($db) { $book = $db->books()->where('id', $id); if ($book->fetch()) {