protected function appendRoute($routes, $prefix = '') { $bootstrap = $this; foreach ($routes as $item) { if (is_object($item)) { /* @var $item MvcContext */ $context = $item; $context->app = $this; $context->rewriteBase = $this->rewriteBase; if (!is_array($item->path)) { $item->path = array($item->path); } foreach ($item->path as $path) { $map = $this->slim->map($prefix . $path, function () use($bootstrap, $context) { $bootstrap->executeAction($context, func_get_args()); }); //via method $methods = array(); if ($context->method == '*') { $methods = array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'); } else { $methods = explode(',', strtoupper($context->method)); } call_user_func_array(array($map, 'via'), $methods); } } else { if (!is_array($item->path)) { $item->path = array($item->path); } foreach ($item->path as $path) { $this->appendRoute($item, $prefix . $path); } } } }
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+')); }
/** * 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'); }); }
/** * @param string $name * @param array $extraRoutes */ public function addRoutes($name, array $extraRoutes = []) { $cb = [$this, $name]; $this->app->map("/{$name}", $cb)->via('GET', 'POST'); $this->app->map("/{$name}/:action", $cb)->via('GET', 'POST'); $this->app->map("/{$name}/:action/:params+", $cb)->via('GET', 'POST'); if (!empty($extraRoutes)) { foreach ($extraRoutes as $route) { $this->app->map($route, $cb)->via('GET', 'POST'); } } }
protected function defineRoutes(\Slim\Slim $app) { $app->get('/', array($this, 'index')); $app->get('/apps', array($this, 'apps'))->name('apps'); $app->get('/about', array($this, 'about'))->name('about'); $app->map('/contact', array($this, 'contact'))->via('GET', 'POST')->name('contact'); $app->get('/not-allowed', array($this, 'notAllowed'))->name('not-allowed'); }
protected function defineRoutes(\Slim\Slim $app) { $app->get('/event/:eventSlug/:talkSlug', array($this, 'index'))->name('talk'); $app->map('/event/:eventSlug/:talkSlug/edit', array($this, 'editTalk'))->via('GET', 'POST')->name('talk-edit'); $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+')); }
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"); }
/** * This methods will be called at application startup * @param $appInstance * @return void */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->group('/nats', function () use($appInstance) { $appInstance->map('/users', function () use($appInstance) { try { $inst = new cNatsMembersPostback(); print 'OK|' . $inst->run(); } catch (InputError $e) { print 'NOTOK|' . $e->getMessage(); } catch (FatalError $e) { print 'ERROR|' . $e->getMessage(); } })->via('GET', 'POST'); }); }
/** * * @return Routes */ public function install(\Slim\Slim $app) { foreach ($this->routes as $route) { $slimRoute = $app->map($route->route(), function () use($route) { // parametry akcji/metody $params = array_merge($route->defaults(), func_get_args()); // kontroler $controller = false !== strpos('\\', $route->controller()) ? $route->controller() : '\\ZPP\\Application\\Controller\\' . $route->controller(); // jeśli istnieje if (class_exists($controller)) { $controllerObject = new $controller(); return call_user_func_array([$controllerObject, $route->action()], $params); } else { throw new \Exception('Cannot find controller ' . $controller); } })->name($route->name()); call_user_func_array([$slimRoute, 'via'], $route->methods()); } }
/** * Routes implemented by this class * * @param \Slim $app Slim application instance * * @return void */ protected function defineRoutes(\Slim\Slim $app) { $app->get('/user/logout', array($this, 'logout'))->name('user-logout'); $app->map('/user/login', array($this, 'login'))->via('GET', 'POST')->name('user-login'); $app->map('/user/register', array($this, 'register'))->via('GET', 'POST')->name('user-register'); $app->get('/user/verification', array($this, 'verification'))->name('user-verification'); $app->map('/user/resend-verification', array($this, 'resendVerification'))->via('GET', 'POST')->name('user-resend-verification'); $app->map('/user/username-reminder', array($this, 'remindUsername'))->via('GET', 'POST')->name('user-username-reminder'); $app->map('/user/password-reset', array($this, 'resetPassword'))->via('GET', 'POST')->name('user-password-reset'); $app->map('/user/new-password', array($this, 'newPassword'))->via('GET', 'POST')->name('user-new-password'); $app->get('/user/twitter-login', array($this, 'loginWithTwitter'))->name('twitter-login'); $app->get('/user/twitter-access', array($this, 'accessTokenFromTwitter'))->name('twitter-callback'); $app->get('/user/:username', array($this, 'profile'))->name('user-profile'); $app->get('/user/:username/talks', array($this, 'profileTalks'))->name('user-profile-talks'); $app->get('/user/:username/events', array($this, 'profileEvents'))->name('user-profile-events'); $app->get('/user/:username/hosted', array($this, 'profileHosted'))->name('user-profile-hosted'); $app->get('/user/:username/comments', array($this, 'profileComments'))->name('user-profile-comments'); $app->map('/user/:username/edit', array($this, 'profileEdit'))->via('GET', 'POST')->name('user-profile-edit'); }
public function load_slim() { $slim = new Slim($this->slim_settings); foreach ($this->routes as $old_route) { $name = isset($old_route[self::SLIM_NAME]) && is_string($old_route[self::SLIM_NAME]) ? $old_route[self::SLIM_NAME] : null; $pattern = isset($old_route[self::SLIM_PATTERN]) && is_string($old_route[self::SLIM_PATTERN]) ? $old_route[self::SLIM_PATTERN] : null; $methods = isset($old_route[self::SLIM_METHODS]) && is_array($old_route[self::SLIM_METHODS]) ? $old_route[self::SLIM_METHODS] : null; $resolver = isset($old_route[self::SLIM_RESOLVER]) && is_callable($old_route[self::SLIM_RESOLVER]) ? $old_route[self::SLIM_RESOLVER] : null; $auth = isset($old_route[self::SLIM_AUTH]) && is_string(self::SLIM_AUTH) ? $old_route[self::SLIM_AUTH] : null; $conditions = isset($old_route[self::SLIM_CONDS]) && is_array($old_route[self::SLIM_CONDS]) ? $old_route[self::SLIM_CONDS] : null; if ($name == null || $pattern == null || $methods == null || $resolver == null || $auth == null) { continue; } $route = $slim->map($pattern, Authorization::hook($auth), $resolver); $route->via($methods); $route->name($name); if ($conditions != null) { $route->conditions($conditions); } } $slim->run(); }
/** * This methods will be called at application startup * @param $appInstance * @return void * @throws \Exception */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->map('/protected-storage/:inst/:id/:accessMethod/:path+', function ($inst, $id, $accessMethod, $path) use($appInstance) { if (!in_array($accessMethod, cProtectedStorage::$allowedAccessMethods, true)) { $appInstance->halt(400, 'Invalid request'); } $fileName = array_pop($path); $rel = ''; foreach ($path as $value) { $rel .= $value . '/'; } $rel .= $fileName; $user = null; if ($accessMethod === 'private') { try { $user = new MembersAuth(); $user->isUserLoggedIn(); } catch (LoginExceptions $e) { $appInstance->halt(401, 'Unauthorized'); } } $fullPath = $inst . '/' . $id . '/' . $accessMethod . '/' . $rel; $controller = new cProtectedStorage($inst, $id, $accessMethod, $rel); if ($controller->isCorrectPath($fullPath)) { $appInstance->etag(md5($fullPath)); $appInstance->expires('+1 week'); $headers = $controller->outputFile(); if (array_key_exists('download', $_REQUEST)) { $headers['Content-Type'] = 'application/octet-stream'; } foreach ($headers as $key => $value) { $appInstance->response->headers->set($key, $value); } } else { $appInstance->notFound(); } })->via('GET', 'POST'); }
/** * 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'); }
/** * @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); } }); }); }
/** * Register this route with the given Slim application and OAuth2 server * * @param Slim $slim The slim framework application instance. * @param string $template The template for /receive-code * * @return void */ public static function register(Slim $slim, $template = 'receive-code.phtml') { $slim->map(self::ROUTE, new self($slim, $template))->via('GET', 'POST')->name('receive-code'); }
protected function mapRoute(\Slim\Slim $slim, $path, $methodName, $httpMethod, &$cachedRoutes = NULL) { $slim->map($path, array($this, 'preMiddleware'), array($this, '_runControllerMiddlewares'), array($this, 'preCallable'), array($this, $methodName))->via($httpMethod); if (is_array($cachedRoutes)) { $cachedRoutes[] = new CachedRoute($path, $methodName, $httpMethod); } }
/** * Register this route with the given Slim application and OAuth2 server * * @param Slim $slim The slim framework application instance. * @param OAuth2\Server $server The oauth2 server imstance. * @param string $template The template for /authorize * * @return void */ public static function register(Slim $slim, OAuth2\Server $server, $template = 'authorize.phtml') { $slim->map(self::ROUTE, new self($slim, $server, $template))->via('GET', 'POST')->name('authorize'); }
$app->flash('addPhotoError', "Error trying to add a photo. Try again?"); $app->log->error(sprintf('Error adding a photo with data: %s: %s', $data, $e->getMessage())); } $app->redirect('/admin'); }); $app->post('/admin/delete-photo', function () use($app, $container) { $day = $app->request()->post('day'); $container['imageService']->delete($day); $container['cache']->flush(); $app->redirect('/admin'); }); $app->map('/login', function () use($app, $container) { $email = null; if ($app->request()->isPost()) { $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); $result = $container['userService']->authenticate($email, $_POST['password']); if ($result->isValid()) { $app->redirect('/admin'); } else { $messages = $result->getMessages(); $app->flashNow('error', $messages[0]); } } $app->render('login.html', array('email' => $email)); })->via('GET', 'POST'); $app->get('/logout', function () use($app, $container) { $container['userService']->clearIdentity(); $app->redirect('/'); }); // Run app $app->run();