public function testMicroClass() { $this->specify("MVC Micro doesn't work as expected", function () { $handler = new \RestHandler(); $app = new Micro(); $app->get("/api/site", [$handler, "find"]); $app->post("/api/site/save", [$handler, "save"]); $app->delete("/api/site/delete/1", [$handler, "delete"]); //Getting the url from _url using GET $_SERVER["REQUEST_METHOD"] = "GET"; $_GET["_url"] = "/api/site"; $app->handle(); expect($handler->getNumberAccess())->equals(1); expect($handler->getTrace())->equals(["find"]); //Getting the url from _url using POST $_SERVER["REQUEST_METHOD"] = "POST"; $_GET["_url"] = "/api/site/save"; $app->handle(); expect($handler->getNumberAccess())->equals(2); expect($handler->getTrace())->equals(["find", "save"]); //Passing directly a URI $_SERVER["REQUEST_METHOD"] = "DELETE"; $_GET["_url"] = null; $app->handle("/api/site/delete/1"); expect($handler->getNumberAccess())->equals(3); expect($handler->getTrace())->equals(["find", "save", "delete"]); }); }
public function testMicroClass() { $handler = new RestHandler($this); $app = new Phalcon\Mvc\Micro(); $app->get('/api/site', array($handler, 'find')); $app->post('/api/site/save', array($handler, 'save')); $app->delete('/api/site/delete/1', array($handler, 'delete')); //Getting the url from _url using GET $_SERVER['REQUEST_METHOD'] = 'GET'; $_GET['_url'] = '/api/site'; $app->handle(); $this->assertEquals($handler->getNumberAccess(), 1); $this->assertEquals($handler->getTrace(), array('find')); //Getting the url from _url using POST $_SERVER['REQUEST_METHOD'] = 'POST'; $_GET['_url'] = '/api/site/save'; $app->handle(); $this->assertEquals($handler->getNumberAccess(), 2); $this->assertEquals($handler->getTrace(), array('find', 'save')); //Passing directly a URI $_SERVER['REQUEST_METHOD'] = 'DELETE'; $_GET['_url'] = null; $app->handle('/api/site/delete/1'); $this->assertEquals($handler->getNumberAccess(), 3); $this->assertEquals($handler->getTrace(), array('find', 'save', 'delete')); }
public function index() { $restaction = "default"; // POST Control if (isset($_POST["restaction"])) { $restaction = $_POST["restaction"]; } /** * Controls the RESTful Services * URL Mapping */ switch ($restaction) { case "listAll": // to handle REST Url /rest/entradas $RestHandler = new RestHandler(); $RestHandler->getAllEnties(); break; case "show": // to handle REST Url /rest/entradas + POST variable $RestHandler = new RestHandler(); $RestHandler->getEntry($_POST["idEntry"]); break; case "delete": // to handle REST Url /rest/entradas + POST variable $RestHandler = new RestHandler(); $RestHandler->delEntry($_POST["idEntry"]); break; case "update": // to handle REST Url /rest/entradas + POST variable $RestHandler = new RestHandler(); $RestHandler->upEntry($_POST["idEntry"], $_POST["field"], $_POST["newValue"]); break; case "default": // to handle REST Url /rest/entradas + POST variable $RestHandler = new RestHandler(); $RestHandler->default(); break; } }
/** * This function handle the "delete" http request * * @param string|null correspond to the URL after /Lan * * @throws RestException */ public function delete($padId = null) { if (isset($padId)) { $data = RestHandler::getData(); $pad = NotesFactory::build(PadComponent::getClass(), array('id' => $padId)); if (!$pad) { throw new RestException("Pad not found", 404); } else { if ($pad->mail_owner != Auth::user()->email) { throw new RestException("Access denied", 403); } else { // Export datas if asked if (isset($data->exportContent) && $data->exportContent === true) { $padContent = $this->exportPadContent($pad); // Setting informations $infos = array(array('pad' => array('pad_name' => $pad->pad_name))); // Send by mail to pad owner $attachment = new MailAttachment(str_ireplace(' ', '', $pad->pad_name) . '_' . date('YmdHis') . '.html'); $attachment->content = $padContent; $attachment->build(); $this->sendPadInformationsByMail($pad, Auth::user()->email, 'delete_pad', $infos, $attachment); } $cdatas = array('padID' => $pad->pad_name, 'apikey' => $this->etherpadApiKey); $result = RestUtilities::callAPI($this->etherpadURLApi . 'deletePad', RestMethods::GET, $cdatas); // $result = json_encode(array('code' => 0)); if ($result) { if (isset($result->error)) { throw new RestException($result->error); } else { if ($result->code == 0) { $pad->delete(); return array('status' => "success", 'content' => $pad); } else { throw new RestException("Pad not found", 404); } } } } } } else { throw new RestException("Invalid pad ID", 500); } }
/** * Initializes a new instance of the SyncRestHandler class. * * @param ServiceContext $context The context */ public function SyncRestHandler($context) { parent::__construct($context); $this->context = $context; return $this; }
/** * Initializes a new instance of the SyncRestHandler class. * * @param ServiceContext $context The context */ public function RestServiceHandler($context) { parent::__construct($context); $this->context = $context; return $this; }
/** * This function allows to set the current user * * @param string $user The user */ public static function setUser($user) { self::$user = $user; }
<?php /* * This file is part of the Notes project. * 2013 - 2015 / RENATER */ require_once '../includes/init.php'; error_reporting(E_ALL & ~E_WARNING); // Handles request if (Auth::user()) { RestHandler::setUser(Auth::user()->email); } RestHandler::handle();