/** * This methods will be called at application startup * @param $appInstance * @return void */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->post('/ajax', function () use(&$appInstance) { $exceptionContentType = 'text/plain'; $appInstance->response->headers->set('Cache-Control', 'no-store'); try { $contentType = EmaRpcApi::slimCallback($appInstance); $appInstance->response->headers->set('Content-Type', $contentType); } catch (SecurityException $e) { $appInstance->response->setStatus(401); $appInstance->response->headers->set('Content-Type', $exceptionContentType); print "Unauthorized.\n" . $e->getMessage(); } catch (\RuntimeException $e) { $appInstance->response->setStatus(400); $appInstance->response->headers->set('Content-Type', $exceptionContentType); print $e->getMessage(); $logger = new DbLogger(); $logger->writeException($e); } catch (\Exception $e) { $logger = new DbLogger(); $logger->writeException($e); $appInstance->response->setStatus(500); $appInstance->response->headers->set('Content-Type', $exceptionContentType); $msg = "Server Error Occurred. Please contact us. Error code is: " . $e->getCode(); if (EMA_DEBUG === true) { $msg = $e->getMessage() . ";\n Code: " . $e->getCode() . "\n\n\n" . $e->getTraceAsString(); } print $msg; } }); if (EMA_REST_API) { $appInstance->map('/rest/:path+', function ($path) use($appInstance) { $appInstance->response->headers->set('Cache-Control', 'no-store'); $appInstance->response->headers->set('Content-Type', 'application/json'); $printoutError = function (\Exception $e, $status = 500) use($appInstance) { $appInstance->response->setStatus($status); print EmaRestApi::getErrorOutput($e); }; try { $rpc = EmaRestApi::rpcFactory($path, $appInstance->request->getMethod(), $appInstance); $result = EmaRestApi::rpcCheckAndRun($rpc, $appInstance); if (EmaRestApi::$isAddition) { $appInstance->response->setStatus(201); $appInstance->response->headers->set('Location', EmaRestApi::$additionRouteBase); } print json_encode($result); } catch (InputError $e) { $printoutError($e, 400); } catch (SecurityException $e) { $printoutError($e, 403); } catch (NotFound $e) { $printoutError($e, 404); } catch (Unsupported $e) { $printoutError($e, 415); } catch (\Exception $e) { $printoutError($e, 500); } })->via('GET', 'POST', 'DELETE'); } }
protected function defineRoutes(\Slim\Slim $app) { // named routes first; should an event pick the same name then at least our actions take precedence $app->get('/event', array($this, 'index'))->name("events-index"); $app->get('/event/pending', array($this, 'pending'))->name("events-pending"); $app->map('/event/submit', array($this, 'submit'))->via('GET', 'POST')->name('event-submit'); $app->get('/event/callforpapers', array($this, 'callForPapers'))->name('event-call-for-papers'); $app->get('/event/:friendly_name', array($this, 'eventDefault'))->name("event-default"); $app->get('/event/:friendly_name/details', array($this, 'details'))->name("event-detail"); $app->get('/event/:friendly_name/comments', array($this, 'comments'))->name("event-comments"); $app->get('/event/:friendly_name/comments/:comment_hash/report', array($this, 'reportComment'))->name("event-comments-reported"); $app->get('/event/:friendly_name/schedule', array($this, 'schedule'))->name("event-schedule"); $app->get('/event/:friendly_name/schedule/list', array($this, 'scheduleList'))->name("event-schedule-list"); $app->get('/event/:friendly_name/schedule/grid', array($this, 'scheduleGrid'))->name("event-schedule-grid"); $app->get('/event/:friendly_name/talk-comments', array($this, 'talkComments'))->name("event-talk-comments"); $app->post('/event/:friendly_name/add-comment', array($this, 'addComment'))->name('event-add-comment'); $app->map('/event/:friendly_name/edit', array($this, 'edit'))->via('GET', 'POST')->name('event-edit'); $app->get('/e/:stub', array($this, 'quicklink'))->name("event-quicklink"); $app->get('/event/xhr-attend/:friendly_name', array($this, 'xhrAttend')); $app->get('/event/xhr-unattend/:friendly_name', array($this, 'xhrUnattend')); $app->get('/event/attend/:friendly_name', array($this, 'attend'))->name("event-attend"); $app->get('/event/unattend/:friendly_name', array($this, 'unattend'))->name("event-unattend"); $app->post('/event/action-pending-event/:friendly_name', array($this, 'actionPendingEvent'))->name("event-action-pending"); $app->get('/event/view/:eventId(/:extra+)', array($this, 'redirectFromId'))->name('event-redirect-from-id')->conditions(array('eventId' => '\\d+')); }
protected function defineRoutes(\Slim\Slim $app) { $app->get('/event/:eventSlug/:talkSlug', array($this, 'index'))->name('talk'); $app->post('/event/:eventSlug/:talkSlug/star', array($this, 'star'))->name('talk-star'); $app->get('/talk/:talkStub', array($this, 'quick'))->name('talk-quicklink'); $app->post('/event/:eventSlug/:talkSlug/add-comment', array($this, 'addComment'))->name('talk-add-comment'); }
protected function defineRoutes(\Slim\Slim $app) { $app->get('/event/:eventSlug/:talkSlug', array($this, 'index'))->name('talk'); $app->post('/event/:eventSlug/:talkSlug/star', array($this, 'star'))->name('talk-star'); $app->get('/talk/:talkStub', array($this, 'quick'))->name('talk-quicklink'); $app->get('/event/:eventSlug/:talkSlug/comments/:commentHash/report', array($this, 'reportComment'))->name('talk-report-comment'); $app->post('/event/:eventSlug/:talkSlug/add-comment', array($this, 'addComment'))->name('talk-add-comment'); $app->get('/:talkId', array($this, 'quickById'))->name('talk-quick-by-id')->conditions(array('talkId' => '\\d+')); $app->get('/talk/view/:talkId', array($this, 'quickById'))->name('talk-by-id-web1')->conditions(array('talkId' => '\\d+')); }
public function generateRoutes() { foreach ($this->schema->table as $table) { $tableName = $this->_urlFriendly($table['name']); $this->slimApp->post($this->apiBasePath . "add-" . $tableName, $this->_addRecord($table)); $this->slimApp->get($this->apiBasePath . "fetch-" . $tableName . "s", $this->_fetchRecords($table)); $this->slimApp->get($this->apiBasePath . "get-" . $tableName . "/:id", $this->_getRecord($table)); $this->slimApp->get($this->apiBasePath . "get-" . $tableName . "-by/:key/:value", $this->_getRecordBy($table)); } }
private function addRoutesFromMeta(Slim $application, ClassMetadata $meta, Controller $controller) { $entitiesRoute = $this->getEntitiesRoute($meta); // Fetch entities route $application->get($entitiesRoute, function () use($meta, $controller) { $controller->getEntities($meta); }); // Create entity $application->post($entitiesRoute, function () use($meta, $controller) { $controller->createEntity($meta); }); $entityRoute = $this->getEntityRoute($meta, $entitiesRoute); // Get entity $application->get($entityRoute, function () use($meta, $controller) { $controller->getEntity($meta, func_get_args()); }); // Update entity $application->put($entityRoute, function () use($meta, $controller) { $controller->updateEntity($meta, func_get_args()); }); // Patch entity $application->patch($entityRoute, function () use($meta, $controller) { $controller->patchEntity($meta, func_get_args()); }); // Delete entity $application->delete($entityRoute, function () use($meta, $controller) { $controller->deleteEntity($meta, func_get_args()); }); // Handling associated entities foreach ($meta->getAssociationMappings() as $aName => $aData) { $aTargetClass = $meta->getAssociationTargetClass($aName); $aMeta = $this->getEntityMeta($aTargetClass); $aEntitiesRoute = $entityRoute . '/' . $aName; // Create associated entity // allow to create entity and link source together // POST /articles/1/tags will fetch article 1, create tag entity and // associate it to article 1 $application->post($aEntitiesRoute, function () use($meta, $aMeta, $controller, $aData) { $controller->createEntity($aMeta, $aData['fieldName'], $meta, func_get_args()); }); // List associated entities $application->get($aEntitiesRoute, function () use($meta, $controller, $aData) { $controller->getAssociatedEntities($aData['fieldName'], $meta, func_get_args()); }); // Associate two entities // POST /articles/1/tags/2 will associate article 1 to tag 2 $aEntityRoute = $this->getEntityRoute($aMeta, $aEntitiesRoute); $application->post($aEntityRoute, function () use($meta, $aMeta, $controller, $aData) { $controller->associateEntities($aMeta, $aData['fieldName'], $meta, func_get_args()); }); } return $application; }
public function enable(Slim $app) { $this->app = $app; $this->config = $this->app->config('api'); $this->factory = new Factory($this->config['resources']); // Middleware $this->app->add(new Database()); $this->app->add(new ApiMiddleware($this->config)); // Routes $this->app->get($this->config['prefix'] . '/:resource/:id', [$this, 'getAction'])->conditions(['id' => '\\d+'])->name('resource_get'); $this->app->get($this->config['prefix'] . '/:resource', [$this, 'listAction'])->name('resource_get_list'); $this->app->put($this->config['prefix'] . '/:resource/:id', [$this, 'putAction'])->conditions(['id' => '\\d+'])->name('resource_put'); $this->app->post($this->config['prefix'] . '/:resource', [$this, 'postAction'])->name('resource_post'); $this->app->delete($this->config['prefix'] . '/:resource/:id', [$this, 'deleteAction'])->conditions(['id' => '\\d+'])->name('resource_delete'); }
public static function slimSetup(\Slim\Slim &$slim, One_Scheme $scheme) { //TODO: read specs from behaviour options or from a file $opt = $scheme->get('behaviorOptions.restable'); $route = $opt['route']; // retrieve $slim->get("/{$route}", function () use($scheme) { One_Controller_Rest::restGetAll($scheme); }); // retrieve one $slim->get("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) { One_Controller_Rest::restGet($scheme, $idOrAlias); }); // create new $slim->post("/{$route}", function () use($scheme) { One_Controller_Rest::restPost($scheme); }); // update existing $slim->put("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) { One_Controller_Rest::restPut($scheme, $idOrAlias); }); // delete existing $slim->delete("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) { One_Controller_Rest::restDelete($scheme, $idOrAlias); }); }
public static function registrationRoute(\Slim\Slim $app) { $app->get('/', function () use($app) { $app->render('index.php'); }); $app->post('/form/', function () use($app) { $app->render('index.php', ['nickname' => $_POST['nickname']]); }); }
function routes(\Slim\Slim $app) { $base = $this->getBasePath(); $app->post($base . '/posts/search', function () use($app) { $app->Posts->search(); }); $app->post($base . '/posts/:id', function ($id) use($app) { $app->Posts->getById($id); }); $app->get($base . '/posts/:id', function ($id) use($app) { $app->Posts->getById($id); }); $app->post($base . '/posts', function () use($app) { $app->Posts->save(); }); $app->delete($base . '/posts/:id', function ($id) use($app) { $app->Posts->delete($id); }); }
public static function registration(\Slim\Slim $app) { // Slim縺ョCSRF蟇セ遲悶��繝ゥ繧ー繧、繝ウ繧呈怏蜉ケ蛹� $app->add(new \Slim\Extras\Middleware\CsrfGuard()); // 繝医ャ繝励��繝シ繧ク $app->get('/', '\\Tinitter\\Controller\\TimeLine:show'); // 謚慕ィソ荳�隕ァ $app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show'); // 譁ー隕乗兜遞ソ邉サ縲∽ソ晏ュ� $app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit'); }
/** * Adds a backend routes * @param $appInstance * @return void */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->group('/admin', function () use($appInstance) { $appInstance->get('/', function () { print '<h1>A Simple Backend</h1>'; }); $appInstance->map("/chpass", function () use($appInstance) { if (EMA_ADMIN_CHPASS) { AdminPasswordChange_controller::process(); } else { $appInstance->pass(); } })->via('GET', 'POST'); $appInstance->map("/update", function () use($appInstance) { ClassAndMethodsDispatcher::updateGPMethods(); })->via('GET', 'POST'); $appInstance->post("/login", function () use($appInstance) { $appInstance->response->headers->set('Cache-Control', 'no-store'); if (isset($_POST['username']) && is_string($_POST['username']) && (isset($_POST['password']) && is_string($_POST['password']))) { try { try { $user = new UserAuth(); } catch (SessionExpired $e) { $user = new UserAuth(); } $user->userLogin($_POST['username'], $_POST['password']); if (!$user->isAdmin()) { $user->logout(); throw new LoginIncorrect('You are not allowed to login here'); } $appInstance->response->headers->set('Content-Type', 'application/json'); print json_encode($user->getSessionAuthData()); } catch (LoginIncorrect $e) { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print $e->getMessage(); } } else { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print 'Bad request'; } }); $appInstance->map('/logout', function () use($appInstance) { try { $user = new UserAuth(); if ($user->isUserLoggedInSimple()) { $user->logout(); } } catch (SessionExpired $e) { } })->via('GET', 'POST'); }); }
protected function defineRoutes(\Slim\Slim $app) { // named routes first; should an event pick the same name then at least our actions take precedence $app->get('/event', array($this, 'index'))->name("events-index"); $app->get('/event/pending', array($this, 'pending'))->name("events-pending"); $app->map('/event/submit', array($this, 'submit'))->via('GET', 'POST')->name('event-submit'); $app->get('/event/callforpapers', array($this, 'callForPapers'))->name('event-call-for-papers'); $app->get('/event/:friendly_name', array($this, 'details'))->name("event-detail"); $app->get('/event/:friendly_name/comments', array($this, 'comments'))->name("event-comments"); $app->get('/event/:friendly_name/schedule', array($this, 'schedule'))->name("event-schedule"); $app->get('/event/:friendly_name/talk-comments', array($this, 'talkComments'))->name("event-talk-comments"); $app->post('/event/:friendly_name/add-comment', array($this, 'addComment'))->name('event-add-comment'); $app->map('/event/:friendly_name/edit', array($this, 'edit'))->via('GET', 'POST')->name('event-edit'); $app->get('/e/:stub', array($this, 'quicklink'))->name("event-quicklink"); $app->get('/event/xhr-attend/:friendly_name', array($this, 'xhrAttend')); $app->get('/event/xhr-unattend/:friendly_name', array($this, 'xhrUnattend')); $app->get('/event/attend/:friendly_name', array($this, 'attend'))->name("event-attend"); $app->get('/event/unattend/:friendly_name', array($this, 'unattend'))->name("event-unattend"); $app->post('/event/action-pending-event/:friendly_name', array($this, 'actionPendingEvent'))->name("event-action-pending"); }
/** * 渡されたslimインスタンスにルートを登録 * @param \Slim\Slim $app */ public static function registration(\Slim\Slim $app) { // SlimのCSRF対策プラグインを有効化 $app->add(new \Slim\Extras\Middleware\CsrfGuard()); // トップページ $app->get('/', '\\Tinitter\\Controller\\TimeLine:show'); // 投稿一覧 $app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show'); // 新規投稿系、保存 $app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit'); }
private function _initRoutes() { $this->_slim->contentType('application/json'); $this->_slim->get('/basket/', array($this, 'getBaskets')); $this->_slim->get('/product/', array($this, 'getProducts')); $this->_slim->get('/basket/:id', array($this, 'getBasket')); $this->_slim->get('/basket/:id/item/', array($this, 'getBasketItems')); $this->_slim->get('/basket/:id/item/:prodId', array($this, 'getBasketItem')); $this->_slim->post('/basket/:id/item/', array($this, 'postBasketItem')); $this->_slim->put('/basket/:id/item/:prodId', array($this, 'putBasketItem')); $this->_slim->delete('/basket/:id/item/:prodId', array($this, 'deleteBasketItem')); }
function post($pattern, $controller, $method, $filter = null) { if (!is_callable($filter)) { $filter = function () { }; } return parent::post($pattern, $filter, function () use($controller, $method) { $instance = new $controller(); $args = func_get_args(); call_user_func_array(array($instance, $method), $args); }); }
/** * @inheritdoc */ public function getSlimInstance() { $app = new Slim(array('debug' => false)); $app->add(new JsonRequestMiddleware(['json_as_object' => true])); $app->post('/messages', function () use($app) { $json = $app->json_body; if (empty($json)) { $app->response->setBody('empty json'); } else { $app->response->setBody('message:' . $json->message); } }); $app->error(function (InvalidJsonFormatException $e) use($app) { $app->response->setBody('error:' . $e->getMessage()); }); return $app; }
private function loadMethodAnnotations(Slim $app, \ReflectionMethod $method, $newInstanceClass, $uri) { $methodAnnotations = $this->getMethodAnnotations($method); $uriMethod = ''; if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\Path'])) { $uriMethod = $methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\Path']->uri; } $uri = $this->normalizeURI($uri, $uriMethod); if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\POST'])) { $app->post($uri, $method->invoke($newInstanceClass)); } if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\GET'])) { $app->get($uri, $method->invoke($newInstanceClass)); } if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\DELETE'])) { $app->delete($uri, $method->invoke($newInstanceClass)); } if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\PUT'])) { $app->put($uri, $method->invoke($newInstanceClass)); } }
/** * This methods will be called at application startup * @param $appInstance * @return void */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->get('/', function () { print '<h1>A simple frontend</h1>'; }); $appInstance->post("/login", function () use($appInstance) { $appInstance->response->headers->set('Cache-Control', 'no-store'); if (isset($_POST['username']) && is_string($_POST['username']) && (isset($_POST['password']) && is_string($_POST['password']))) { try { try { $user = new MembersAuth(); } catch (SessionExpired $e) { $user = new MembersAuth(); } $user->userLogin($_POST['username'], $_POST['password']); $appInstance->response->headers->set('Content-Type', 'application/json'); print json_encode($user->getSessionAuthData()); } catch (LoginIncorrect $e) { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print $e->getMessage(); } } else { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print 'Bad request'; } }); $appInstance->map('/logout', function () use($appInstance) { try { $user = new MembersAuth(); if ($user->isUserLoggedInSimple()) { $user->logout(); } } catch (SessionExpired $e) { } })->via('GET', 'POST'); }
public static function registration(\Slim\Slim $app) { $app->add(new \Slim\Extras\Middleware\CsrfGuard()); //top $app->get('/', '\\Quiz\\Controller\\Top:show'); //question $app->get('/questions', '\\Quiz\\Controller\\Question:show'); $app->get('/questions/new', '\\Quiz\\Controller\\Question:createShow'); $app->post('/questions/new', '\\Quiz\\Controller\\Question:createQuestion'); $app->get('/questions/update', '\\Quiz\\Controller\\Question:updateShow'); $app->post('/questions/update', '\\Quiz\\Controller\\Question:updateQuestion'); //quiz $app->get('/quizzes', '\\Quiz\\Controller\\Quiz:show'); $app->get('/quizzes/new', '\\Quiz\\Controller\\Quiz:createShow'); $app->post('/quizzes/new', '\\Quiz\\Controller\\Quiz:createQuiz'); //answer $app->post('/answer/start', '\\Quiz\\Controller\\Answer:answerStart'); $app->post('/answer/end', '\\Quiz\\Controller\\Answer:answerEnd'); //comment $app->post('/comment/create', '\\Quiz\\Controller\\Comment:createComment'); }
// // Response: (JSON encoded) // * `token`: A token that can be used to connect to the presence session, which also identifies // the user to all other users who connect to it. // // NOTE: This request allows anonymous access, but if user authentication is required then the // identity of the request should be verified (often times with session cookies) before a valid // response is given. // NOTE: Uniqueness of names is not enforced. $app->post('/users', function () use($app, $opentok, $config) { $rawBody = $app->request->getBody(); $params = json_decode($rawBody); // Parameter validation $name = $params->name; if (empty($name) || strlen($name) > intval(NAME_MAX_LENGTH)) { $app->response->setStatus(400); return; } $token = $opentok->generateToken($config->opentok('presenceSession'), array('data' => json_encode(array('name' => $name)), 'role' => Role::SUBSCRIBER)); $responseData = array('token' => $token); $app->response->headers->set('Content-Type', 'application/json'); $app->response->setBody(json_encode($responseData)); }); // Create a chat // // Request: (JSON encoded) // * `invitee`: the name of the other user who is being invited to the chat // // Response: (JSON encoded) // * `apiKey`: an OpenTok API key that owns the session ID // * `sessionId`: an OpenTok session ID to conduct the chat within // * `token`: a token that the creator of the chat (or inviter) can use to connect to the chat
/** * @param string $routeName * @param string $tableName * @param callable $customCRUDFunction * @param string $displayName */ public function add($routeName, $customCRUDFunction = null, $tableName = null, $displayName = null) { if ($tableName == null) { $tableName = $routeName; } $this->tableList[$routeName] = $tableName; $this->tableDisplayName[$routeName] = $displayName; $this->routeNameList[] = $routeName; /* * Page Group (ListView, CreateView, EditView) */ $this->slim->group("/" . $this->groupName . "/" . $routeName, function () use($routeName, $customCRUDFunction, $tableName) { $this->slim->get("/", function () use($routeName) { $this->slim->redirectTo("_louisCRUD_" . $routeName); }); /* * ListView */ $this->slim->get("/list(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->listviewFunction != null) { $listviewFunction = $this->listviewFunction; $result = $listviewFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->isEnabledListView()) { $this->renderListView(); } })->name("_louisCRUD_" . $routeName); /* * Create */ $this->slim->get("/create(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->createFunction != null) { $createFunction = $this->createFunction; $result = $createFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // Force Hide ID field $this->field("id")->hide(); if ($this->isEnabledCreate()) { $this->renderCreateView(); } }); /* * Edit */ $this->slim->get("/edit/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); // Load Bean first $this->loadBean($id); // ID must be hidden $this->field("id")->hide(); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->editFunction != null) { $editFunction = $this->editFunction; $result = $editFunction($id, $p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // If user show the ID field, force set it to readonly $this->field("id")->setReadOnly(true); if ($this->isEnabledEdit()) { $this->renderEditView(); } }); /* * Export Excel */ $this->slim->map("/export(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->listviewFunction != null) { $listviewFunction = $this->listviewFunction; $result = $listviewFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->exportFunction != null) { $exportFunction = $this->exportFunction; $result = $exportFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // TODO: isEnabledExport(); $this->renderExcel(); })->via('GET', 'POST'); }); /* * API Group, RESTful style. */ $this->slim->group("/" . $this->apiGroupName . "/" . $routeName, function () use($routeName, $customCRUDFunction, $tableName) { /* * JSON for Listview */ $this->slim->map("/list(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { $this->enableJSONResponse(); // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->listviewFunction != null) { $listviewFunction = $this->listviewFunction; $result = $listviewFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->isEnabledListView()) { $this->getJSONList(); } return; })->via('GET', 'POST'); /* * For Datatables */ $this->slim->map("/datatables(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { $this->enableJSONResponse(); // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->listviewFunction != null) { $listviewFunction = $this->listviewFunction; $result = $listviewFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->isEnabledListView()) { $this->getListViewJSONString(); } return; })->via('GET', 'POST'); /* * View a bean * PUT /api/{tableName}/{id} */ $this->slim->get("/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); // Load Bean $this->loadBean($id); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } // Custom Global Function if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // Custom Edit Function if ($this->editFunction != null) { $editFunction = $this->editFunction; $result = $editFunction($id, $p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // Force hide ID $this->field("id")->hide(); // Insert into database if ($this->isEnabledEdit()) { $json = $this->getJSON(false); $this->enableJSONResponse(); echo $json; } }); /* * Insert a bean * POST /api/{tableName} */ $this->slim->post("(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // Custom Global Function $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } // Custom Create Function if ($this->createFunction != null) { $createFunction = $this->createFunction; $result = $createFunction($p1, $p2, $p3, $p4, $p5); } if ($result === false) { return; } // Force hide ID $this->field("id")->hide(); // Insert into database if ($this->isEnabledCreate()) { $jsonObject = $this->insertBean($_POST); $this->enableJSONResponse(); echo json_encode($jsonObject); } else { // TODO: Should be json object echo "No permission"; } }); /* * Update a bean * PUT /crud/{tableName}/{id} */ $this->slim->put("/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); // Load Bean $this->loadBean($id); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } // Custom Global Function if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // Custom Create Function if ($this->editFunction != null) { $editFunction = $this->editFunction; $result = $editFunction($id, $p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // Force hide ID $this->field("id")->hide(); // Insert into database if ($this->isEnabledEdit()) { $jsonObject = $this->updateBean($this->slim->request()->params()); $this->enableJSONResponse(); echo json_encode($jsonObject); } }); /* * Delete a bean * DELETE /crud/{tableName}/{id} */ $this->slim->delete("/:id(/:p1(/:p2(/:p3(/:p4(/:p5)))))", function ($id, $p1 = null, $p2 = null, $p3 = null, $p4 = null, $p5 = null) use($routeName, $customCRUDFunction, $tableName) { // MUST INIT FIRST $this->init($tableName, $routeName, $p1, $p2, $p3, $p4, $p5); $this->enableJSONResponse(); $this->loadBean($id); if ($this->configFunction != null) { $function = $this->configFunction; $result = $function(); if ($result === false) { return; } } // Custom Global Function if ($customCRUDFunction != null) { $result = $customCRUDFunction($p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } // Custom Delete Function if ($this->deleteFunction != null) { $deleteFunction = $this->deleteFunction; $result = $deleteFunction($id, $p1, $p2, $p3, $p4, $p5); if ($result === false) { return; } } if ($this->isEnabledDelete()) { $this->deleteBean(); $result = new \stdClass(); $result->status = "succ"; echo json_encode($result); } }); }); }
// create new Slim instance $app = new Slim(); $app->get("/f2", function () { echo "<h1>f2 lms service alisha</h1>"; }); $app->get('/f3/:name', function ($name) { echo "Hello, {$name}"; }); $app->post('/logout', function () use($app) { try { $request = $app->request(); $userIdObj = json_decode($request->getBody()); $userId = $userIdObj->userId; try { unset($_SESSION['SESSION_KEY']); } catch (PDOException $e) { //error_log($e->getMessage(), 3, '/var/tmp/php.log'); echo '{"error":{"text":' . $e->getMessage() . '}}'; } } catch (PDOException $e) { //error_log($e->getMessage(), 3, '/var/tmp/php.log'); echo '{"error":{"text":' . $e->getMessage() . '}}'; } }); $app->post('/myordersnew', function () use($app) { try { $request = $app->request(); $userIdObj = json_decode($request->getBody()); $userId = $userIdObj->userId; $emailId = $userIdObj->emailId; $sessionKey = $userIdObj->sessionKey; session_start();
$app->post('/contactus', function () use($app) { try { $request = $app->request(); $queryDetails = json_decode($request->getBody()); $uname = $queryDetails->name; $email = $queryDetails->email; $phone = $queryDetails->phone; $timeToContact = $queryDetails->timeToContact; $contactWay = $queryDetails->contactWay; $query = $queryDetails->query; $message = "<div style='border:2px dotted red'><b>Name :</b> " . $uname . " <br><b>Phone : </b>" . $phone . " <br><b>Email : </b>" . $email . "\n <br><b>Best way to contact : </b>" . $contactWay . "<br><b>Best time to contact : </b>" . $timeToContact . " \n <br><b>Message : </b>" . $query . "</div>"; //echo $message; try { $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; //$mail->SMTPDebug = 1; $mail->Host = 'smtp.gmail.com'; $mail->Port = 465; $mail->Username = '******'; $mail->Password = '******'; // $mail->Username = '******'; // $mail->Password = '******'; $mail->SetFrom($email, $uname); $mail->AddReplyTo($email, 'Reply to '); //$mail->AddAddress('*****@*****.**', 'Danesh'); //$mail->AddAddress('*****@*****.**', 'Digamber'); $mail->AddAddress('*****@*****.**', 'Alisha'); $mail->AddAddress('*****@*****.**', 'Ranjan'); $mail->Subject = 'Message from Arizona Systems raised by : ' . $uname; $mail->Body = $message; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if (!$mail->Send()) { // echo 'Message could not be sent. <p>'; // echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } //echo 'Message has been sent'; echo true; } catch (PDOException $e) { //error_log($e->getMessage(), 3, '/var/tmp/php.log'); echo '{"error":{"text":' . $e->getMessage() . '}}'; } } catch (PDOException $e) { //error_log($e->getMessage(), 3, '/var/tmp/php.log'); echo '{"error":{"text":' . $e->getMessage() . '}}'; } });
} catch (PDOException $e) { echo $e->getMessage(); exit; } // Wire together dependencies $app->hash = new Hash(); $app->userRepository = new UserRepository($app->db); $app->movieRepository = new MovieRepository($app->db); $app->movieReviewRepository = new MovieReviewRepository($app->db); $app->auth = new Auth($app->userRepository, $app->hash); $ns = 'tdt4237\\webapp\\controllers\\'; // Home page at http://localhost:8080/ $app->get('/', $ns . 'IndexController:index'); // Login form $app->get('/login', $ns . 'LoginController:index'); $app->post('/login', $ns . 'LoginController:login'); // New user $app->get('/user/new', $ns . 'UserController:index')->name('newuser'); $app->post('/user/new', $ns . 'UserController:create'); // Edit logged in user $app->get('/user/edit', $ns . 'UserController:showUserEditForm')->name('editprofile'); $app->post('/user/edit', $ns . 'UserController:receiveUserEditForm'); // Show a user by name $app->get('/user/:username', $ns . 'UserController:show')->name('showuser'); // Show all users $app->get('/users', $ns . 'UserController:all'); // Log out $app->get('/logout', $ns . 'UserController:logout')->name('logout'); // Admin restricted area $app->get('/admin', $ns . 'AdminController:index')->name('admin'); $app->get('/admin/delete/:username', $ns . 'AdminController:delete');
allow_cross_domain_calls(); echo json_encode($pageitemcollection); }); $app->get('/deleteitem/:itemtype/:itemid/', function ($itemtype, $itemid) { require_once 'dataobjectserver/application.php'; $application = Application::getinstance(); $item = $application->GetObjectById($itemtype, $itemid); $item->Delete(); allow_cross_domain_calls(); echo json_encode($item); }); $app->post('/saveitem/:itemtype/', function ($itemtype) use($app) { require_once 'dataobjectserver/application.php'; $application = Application::getinstance(); //cast the json object to a well formed php object based on the data object model $itemdetails = $application->GetObjectForJSON(json_decode($app->request->post('itemObject')), $itemtype); $itemdetails->Save(); allow_cross_domain_calls(); echo json_encode($itemdetails); }); $app->get('/testsave/', function () { $saveitemdetails = '{"ServerErr":"","ServerErrNo":0,"ServerErrType":"","id":null,"title":"style","position":2}'; $itemtype = 'menu'; require_once 'dataobjectserver/application.php'; $application = Application::getinstance(); $itemdetails = $application->GetObjectForJSON(json_decode($saveitemdetails), $itemtype); $itemdetails->Save(); }); $app->post('/insertafter/:itemtype/:insertafterposition/', function ($itemtype, $insertafterposition) use($app) { require_once 'dataobjectserver/application.php'; $application = Application::getinstance();
} $dataArray = array('time' => time(), 'message' => "Run finish"); header("Content-Type: application/json"); echo json_encode($dataArray); exit; }); // add new repeater to list $app->post('/add', function () use($app) { $app->log->info("Echolink CRON System - '/add' route"); $req = $app->request(); if (masterPassword == $req->post('masterpassword')) { $echolinksys = new System("mysql:host=" . host . ";dbname=" . database, username, password); $status = $echolinksys->addRepeater($req->post('callname'), $req->post('email')); if ($status == true) { $app->log->info("Echolink CRON System - add new Repeater to DB"); $app->flashNow('info', 'Add repeater!'); } else { $app->log->info("Echolink CRON System - is exist Repeater to DB"); $app->flashNow('info', 'Fail adding repeater!'); } } $url = $app->urlFor('list', array()); $app->redirect($url); })->name('add'); // delete repeater $app->post('/delete', function () use($app) { $app->log->info("Echolink CRON System - '/delete' route"); $req = $app->request(); if (masterPassword == $req->post('masterpassword')) { $echolinksys = new System("mysql:host=" . host . ";dbname=" . database, username, password); $status = $echolinksys->removeRepeater($req->post('callname'));
$app = new Slim(); $app->get('/test', function () { echo "It is running!!!"; }); $app->get('/restaurant', function () { outputJSON(Restaurant::getAll()); }); $app->get('/restaurant/:id', function ($id) { outputJSON(Restaurant::getById($id)); }); $app->post('/restaurant', function () use($app) { $body = json_decode($app->request->getBody()); $restaurant = new Restaurant(); $restaurant->setName($body->name); $restaurant->setSpeisekartenUrl($body->speisekarten_url); print_r($body); if (property_exists($body, 'image_url')) { $restaurant->setImageUrl($body->image_url); } $restaurant->save(); }); $app->get('/participation', function () { outputJSON(Participation::getAll()); }); $app->get('/participation/:id', function ($id) { outputJSON(Participation::getById($id)); }); $app->post('/participation', function () use($app) { $body = json_decode($app->request->getBody()); $participation = new Participation(); $participation->setOffer($body->offer);
public function post($route, $action) { $action = $this->resolveAction($action); parent::post($route, $action); }
/** * @SWG\Api( * path="/gas-stations", * @SWG\Operation( * method="POST", * summary="Register a new gas station", * type="GasStation", * nickname="newGasStation", * @SWG\Parameters( * @SWG\Parameter( * name="Accept", * description="The type of response that the web service client expects", * paramType="header", * required=true, * type="string", * enum="['application/json', 'application/xml']" * ), * @SWG\Parameter( * name="name", * description="The name of the new gas station", * paramType="form", * required=true, * type="string" * ), * @SWG\Parameter( * name="social_reason", * description="The legal name of the new gas station", * paramType="form", * required=true, * type="string" * ), * @SWG\Parameter( * name="address_line_1", * description="Street name and number of the gas station", * paramType="form", * required=true, * type="string" * ), * @SWG\Parameter( * name="address_line_2", * description="Name of the gas station neighborhood", * paramType="form", * required=true, * type="string" * ), * @SWG\Parameter( * name="location", * description="State and city name where the gas station is located", * paramType="form", * required=true, * type="string" * ), * @SWG\Parameter( * name="latitude", * description="Latitude coordinate", * paramType="form", * required=true, * type="double" * ), * @SWG\Parameter( * name="longitude", * description="Longitude coordinate", * paramType="form", * required=true, * type="double" * ) * ), * @SWG\ResponseMessage( * code=400, * message="Gas station data did not pass validation" * ) * ) * ) */ protected function newStation() { $this->app->post('/gas-stations', function () { $this->app->stationController->post(); }); }