當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Application::abort方法代碼示例

本文整理匯總了PHP中Silex\Application::abort方法的典型用法代碼示例。如果您正苦於以下問題:PHP Application::abort方法的具體用法?PHP Application::abort怎麽用?PHP Application::abort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Silex\Application的用法示例。


在下文中一共展示了Application::abort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loginAction

 public function loginAction(Request $request, Application $app)
 {
     $username = $app->escape($request->get('username'));
     $password = $app->escape($request->get('password'));
     $rememberMe = $app->escape($request->get('rememberMe'));
     if (!$username || !$password) {
         $app->abort(Response::HTTP_BAD_REQUEST, 'Missing parameters');
     }
     $user = $app['repository.user']->findByUsername($username);
     if (!$user) {
         $app->abort(Response::HTTP_NOT_FOUND, 'User not found');
     }
     if (password_verify($password, $user->getPassword())) {
         $user->setLastSeen(new \DateTime('now'));
         $user->setLastIP($request->headers->get('referer'));
         $user->setFailedLogins(0);
         $app['repository.user']->save($user);
         //$access_query = 'SELECT user_level FROM users_access WHERE user_id = ' . $account['id'];
         //$access       = $app['db']->fetchAssoc($access_query);
         $permissions = [];
         //foreach ($access as $accessLevel) {
         //    array_push($permissions, $app['api.accessLevels'][$accessLevel]);
         //}
         $exp = $rememberMe ? time() + 60 * 60 * 24 * 30 : time() + 60 * 60 * 24;
         // expire in 30 days or 24h
         $user = ['id' => $user->getId(), 'username' => $user->getUsername(), 'permissions' => $permissions, 'rememberMe' => $rememberMe];
         $token = $app['jwt']->createToken($request, $exp, $user);
     } else {
         $user->setFailedLogins($user->getFailedLogins() + 1);
         $app['repository.user']->save($user);
         $app->abort(Response::HTTP_FORBIDDEN, 'Wrong password');
     }
     return json_encode(['token' => $token], JSON_NUMERIC_CHECK);
 }
開發者ID:Arkhana,項目名稱:cheesecake,代碼行數:34,代碼來源:UserController.php

示例2: view

 public function view(Application $app, $folder = '', $scriptName = '', $runType = 'test')
 {
     if (!file_exists("Api/Library/Shared/Script/{$folder}/{$scriptName}.php")) {
         $app->abort(404, $this->website->base);
         // this terminates PHP
     } else {
         $userId = (string) $app['session']->get('user_id');
         if (!RightsHelper::hasSiteRight($userId, Domain::PROJECTS + Operation::DELETE)) {
             $app->abort(403, 'You have insufficient privileges to run scripts');
             // this terminates PHP
         } else {
             try {
                 $className = "Api\\Library\\Shared\\Script\\{$folder}\\{$scriptName}";
                 $script = new $className();
                 $this->data['scriptname'] = $className . '->run()';
                 $this->data['insert'] = '';
                 $this->data['output'] = '';
                 if (strtolower($folder) == 'control' and strtolower($scriptName) == 'panel') {
                     $this->data['insert'] .= $script->run($userId, $runType);
                 } else {
                     if ($runType != 'run') {
                         $this->data['output'] .= "--------------- THIS IS A TEST RUN - The database should not be modified ----------------\n\n";
                     }
                     $this->data['output'] .= $script->run($userId, $runType);
                 }
                 return $this->renderPage($app, 'textoutput');
             } catch (\Exception $e) {
                 $app->abort(500, "Looks like there was a problem with the script {$className}");
                 // this terminates PHP
             }
         }
     }
 }
開發者ID:bbriggs,項目名稱:web-languageforge,代碼行數:33,代碼來源:Script.php

示例3: getDevFile

 public function getDevFile(Request $request, Application $app, $lang, $fileName)
 {
     global $rfExampleConfig;
     if (!isset($rfExampleConfig['devStaticPaths'][$lang])) {
         $app->abort(404, "Cannot find language files");
     }
     $filePath = $rfExampleConfig['devStaticPaths'][$lang] . $fileName;
     if (!file_exists($filePath)) {
         $app->abort(404, "Cannot find file");
     }
     $arr = explode(".", $fileName);
     $extension = array_pop($arr);
     $mime = "text/plain";
     if ($extension === "css") {
         $mime = "text/css";
     } else {
         if ($extension === "js") {
             $mime = "application/javascript";
         } else {
             if ($extension === "html") {
                 $mime = "text/html";
             }
         }
     }
     return $app->sendFile($filePath, 200, array('Content-Type' => $mime));
 }
開發者ID:sguha-work,項目名稱:examples,代碼行數:26,代碼來源:DevStaticController.php

示例4: build

 protected function build($siteid, $slug, Request $request, Application $app)
 {
     $this->parameters = array('group' => null, 'venue' => null, 'country' => null);
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $er = new EventRepository();
     $this->parameters['event'] = $er->loadBySlug($this->parameters['site'], $slug);
     $this->parameters['eventisduplicateof'] = $this->parameters['event']->getIsDuplicateOfId() ? $er->loadById($this->parameters['event']->getIsDuplicateOfId()) : null;
     if (!$this->parameters['event']) {
         $app->abort(404);
     }
     if ($this->parameters['event']->getGroupId()) {
         $gr = new GroupRepository();
         $this->parameters['group'] = $gr->loadById($this->parameters['event']->getGroupId());
     }
     if ($this->parameters['event']->getCountryID()) {
         $cr = new CountryRepository();
         $this->parameters['country'] = $cr->loadById($this->parameters['event']->getCountryID());
     }
     if ($this->parameters['event']->getVenueID()) {
         $cr = new VenueRepository();
         $this->parameters['venue'] = $cr->loadById($this->parameters['event']->getVenueID());
     }
 }
開發者ID:radical-assembly,項目名稱:OpenACalendar-Web-Core,代碼行數:27,代碼來源:EventController.php

示例5: build

 protected function build($siteid, $slug, Request $request, Application $app)
 {
     $this->parameters = array('user' => null, 'eventCreated' => null, 'eventDupe' => null);
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $repo = new NewEventDraftRepository();
     $this->parameters['draft'] = $repo->loadBySlugForSite($slug, $this->parameters['site']);
     if (!$this->parameters['draft']) {
         $app->abort(404);
     }
     if ($this->parameters['draft']->getUserAccountId()) {
         $ur = new UserAccountRepository();
         $this->parameters['user'] = $ur->loadByID($this->parameters['draft']->getUserAccountId());
     }
     if ($this->parameters['draft']->getEventId()) {
         $er = new EventRepository();
         $this->parameters['eventCreated'] = $er->loadByID($this->parameters['draft']->getEventId());
     }
     if ($this->parameters['draft']->getWasExistingEventId()) {
         $er = new EventRepository();
         $this->parameters['eventDupe'] = $er->loadByID($this->parameters['draft']->getWasExistingEventId());
     }
 }
開發者ID:radical-assembly,項目名稱:OpenACalendar-Web-Core,代碼行數:26,代碼來源:NewEventDraftController.php

示例6: listing

 function listing(Silex\Application $app, $contenttypeslug)
 {
     $contenttype = $app['storage']->getContentType($contenttypeslug);
     // First, get some content
     $page = !empty($_GET['page']) ? $_GET['page'] : 1;
     $amount = !empty($contenttype['listing_records']) ? $contenttype['listing_records'] : $app['config']['general']['listing_records'];
     $content = $app['storage']->getContent($contenttype['slug'], array('limit' => $amount, 'order' => 'datepublish desc', 'page' => $page));
     if (!$content) {
         $app->abort(404, "Content for '{$contenttypeslug}' not found.");
     }
     // Then, select which template to use, based on our 'cascading templates rules'
     if (!empty($contenttype['listing_template'])) {
         $template = $contenttype['listing_template'];
     } else {
         $filename = $app['paths']['themepath'] . "/" . $contenttype['slug'] . ".twig";
         if (file_exists($filename) && is_readable($filename)) {
             $template = $contenttype['slug'] . ".twig";
         } else {
             $template = $app['config']['general']['listing_template'];
         }
     }
     // Fallback: If file is not OK, show an error page
     $filename = $app['paths']['themepath'] . "/" . $template;
     if (!file_exists($filename) || !is_readable($filename)) {
         $app->abort(404, "No template for '{$contenttypeslug}' defined. Tried to use '{$template}'.");
     }
     // $app['editlink'] = path('editcontent', array('contenttypeslug' => $contenttypeslug, 'id' => $content->id));
     $body = $app['twig']->render($template, array('records' => $content, $contenttype['slug'] => $content));
     return new Response($body, 200, array('Cache-Control' => 's-maxage=3600, public'));
 }
開發者ID:robertkraig,項目名稱:bolt,代碼行數:30,代碼來源:Frontend.php

示例7: getRecord

 /**
  * Get record detailed view
  *
  * @param Application $app
  * @param Request     $request
  *
  * @return JsonResponse
  */
 public function getRecord(Application $app, Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         $app->abort(400);
     }
     $searchEngine = $options = null;
     $train = '';
     if ('' === ($env = strtoupper($request->get('env', '')))) {
         $app->abort(400, '`env` parameter is missing');
     }
     // Use $request->get as HTTP method can be POST or GET
     if ('RESULT' == ($env = strtoupper($request->get('env', '')))) {
         try {
             $options = SearchEngineOptions::hydrate($app, $request->get('options_serial'));
             $searchEngine = $app['phraseanet.SE'];
         } catch (\Exception $e) {
             $app->abort(400, 'Search-engine options are not valid or missing');
         }
     }
     $pos = (int) $request->get('pos', 0);
     $query = $request->get('query', '');
     $reloadTrain = !!$request->get('roll', false);
     $record = new \record_preview($app, $env, $pos < 0 ? 0 : $pos, $request->get('cont', ''), $searchEngine, $query, $options);
     if ($record->is_from_reg()) {
         $train = $app['twig']->render('prod/preview/reg_train.html.twig', ['record' => $record]);
     }
     if ($record->is_from_basket() && $reloadTrain) {
         $train = $app['twig']->render('prod/preview/basket_train.html.twig', ['record' => $record]);
     }
     if ($record->is_from_feed()) {
         $train = $app['twig']->render('prod/preview/feed_train.html.twig', ['record' => $record]);
     }
     return $app->json(["desc" => $app['twig']->render('prod/preview/caption.html.twig', ['record' => $record, 'highlight' => $query, 'searchEngine' => $searchEngine, 'searchOptions' => $options]), "html_preview" => $app['twig']->render('common/preview.html.twig', ['record' => $record]), "others" => $app['twig']->render('prod/preview/appears_in.html.twig', ['parents' => $record->get_grouping_parents(), 'baskets' => $record->get_container_baskets($app['EM'], $app['authentication']->getUser())]), "current" => $train, "history" => $app['twig']->render('prod/preview/short_history.html.twig', ['record' => $record]), "popularity" => $app['twig']->render('prod/preview/popularity.html.twig', ['record' => $record]), "tools" => $app['twig']->render('prod/preview/tools.html.twig', ['record' => $record]), "pos" => $record->get_number(), "title" => str_replace(['[[em]]', '[[/em]]'], ['<em>', '</em>'], $record->get_title($query, $searchEngine))]);
 }
開發者ID:nlegoff,項目名稱:Phraseanet,代碼行數:42,代碼來源:Records.php

示例8: boot

 /**
  * Bootstraps the application.
  *
  * This method is called after all services are registered
  * and should be used for "dynamic" configuration (whenever
  * a service must be requested).
  */
 public function boot(Application $app)
 {
     $this->app = $app;
     $app->get($app["documentation.url"] . '/', function () use($app) {
         $subRequest = Request::create($app["documentation.url"], 'GET');
         return $app->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     });
     $app->get($app["documentation.url"], function () use($app) {
         $home = $app["documentation.dir"] . '/' . $app["documentation.home"] . '.' . $app["documentation.extension"];
         if (is_file($home)) {
             if (is_readable($home)) {
                 $content = file_get_contents($home);
                 return $app["DocumentationRenderer"]->render($content);
             } else {
                 $app->abort("403", "Forbidden");
             }
         } else {
             $app->abort("404", "Documentation Page not Found ");
         }
     });
     $app->get($app["documentation.url"] . "/{pagename}", function (Request $request) use($app) {
         $page = $app["documentation.dir"] . '/' . $request->get('pagename') . '.' . $app["documentation.extension"];
         if (is_file($page)) {
             if (is_readable($page)) {
                 $content = file_get_contents($page);
                 return $app["DocumentationRenderer"]->render($content);
             } else {
                 $app->abort("403", "Forbidden");
             }
         } else {
             $app->abort("404", "Documentation Page not Found ");
         }
     })->assert('pagename', '[a-zA-Z0-9-/]*')->value("pagename", "index");
 }
開發者ID:mimiz,項目名稱:silex-documentation-provider,代碼行數:41,代碼來源:DocumentationProvider.php

示例9: getClass

 /**
  * Get entity class
  * 
  * @param string $modelName
  * @return string
  */
 public function getClass($modelName)
 {
     // Returns a string with the first character of str capitalized
     $modelName = ucfirst($modelName);
     $class = "\\{$this->app['config']['parameters']['db.models.namespace']}\\{$modelName}";
     if (!class_exists($class)) {
         $this->app->abort(404, "Not declared class \"{$class}\"");
     }
     return $class;
 }
開發者ID:bsa-git,項目名稱:silex-mvc,代碼行數:16,代碼來源:Db.php

示例10: invalidate

 /**
  * Invalidate our database check by removing the timestamp file from cache.
  *
  * @return void
  */
 public function invalidate()
 {
     $fileName = $this->getValidityTimestampFilename();
     // delete the cached dbcheck-ts
     if (is_writable($fileName)) {
         unlink($fileName);
     } elseif (file_exists($fileName)) {
         $message = sprintf("The file '%s' exists, but couldn't be removed. Please remove this file manually, and try again.", $fileName);
         $this->app->abort(Response::HTTP_UNAUTHORIZED, $message);
     }
 }
開發者ID:nuffer,項目名稱:bolt,代碼行數:16,代碼來源:Manager.php

示例11: categoryAction

 /**
  * Действие для страницы категории
  *
  * @param string $url URL категории
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  *
  * @return string
  */
 public function categoryAction($url)
 {
     $category = $this->catalogModel->getCategory($url);
     if (!$category) {
         $this->app->abort(404, "Категория c URL '{$url}' не найдена");
     }
     $products = $this->catalogModel->getProductsByCategoryId($category['id']);
     foreach ($products as &$product) {
         $product['price'] = $this->catalogModel->convertPrice($product['price']);
     }
     return $this->view->render('catalog/category.phtml', array('category' => $category, 'products' => $products));
 }
開發者ID:Nakedspirit,項目名稱:iShop,代碼行數:21,代碼來源:CatalogController.php

示例12: get

 /**
  * Get service for ZF
  * 
  * @param mixed $service
  * @return mixed
  */
 public function get($service)
 {
     $method = 'get';
     $service = strtolower($service);
     $arService = explode('_', $service);
     foreach ($arService as $item) {
         $method .= ucfirst($item);
     }
     if (method_exists($this, $method)) {
         return $this->{$method}();
     } else {
         $this->app->abort(404, "Service {$service} not Found");
     }
 }
開發者ID:bsa-git,項目名稱:silex-mvc,代碼行數:20,代碼來源:MyService.php

示例13: build

 protected function build($siteid, $fieldid, Request $request, Application $app)
 {
     $this->parameters = array();
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $repo = new EventCustomFieldDefinitionRepository();
     $this->parameters['field'] = $repo->loadBySiteIDAndID($this->parameters['site']->getId(), $fieldid);
     if (!$this->parameters['field']) {
         $app->abort(404);
     }
 }
開發者ID:radical-assembly,項目名稱:OpenACalendar-Web-Core,代碼行數:14,代碼來源:EventCustomFieldDefinitionController.php

示例14: connect

 public function connect(Application $app)
 {
     $app['controller.rss-feeds'] = $this;
     $controllers = $app['controllers_factory'];
     $controllers->get('/feed/{id}/{format}/', function (Application $app, $id, $format) {
         $feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id);
         if (null === $feed) {
             $app->abort(404, 'Feed not found');
         }
         if (!$feed->isPublic()) {
             $app->abort(403, 'Forbidden');
         }
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page < 1 ? 1 : $page;
         return $app['feed.formatter-strategy']($format)->createResponse($app, $feed, $page);
     })->bind('feed_public')->assert('id', '\\d+')->assert('format', '(rss|atom)');
     $controllers->get('/userfeed/{token}/{id}/{format}/', function (Application $app, $token, $id, $format) {
         $token = $app["EM"]->find('Phraseanet:FeedToken', $id);
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page < 1 ? 1 : $page;
         return $app['feed.formatter-strategy']($format)->createResponse($app, $token->getFeed(), $page, $token->getUser());
     })->bind('feed_user')->assert('id', '\\d+')->assert('format', '(rss|atom)');
     $controllers->get('/userfeed/aggregated/{token}/{format}/', function (Application $app, $token, $format) {
         $token = $app['EM']->getRepository('Phraseanet:AggregateToken')->findOneBy(["value" => $token]);
         $user = $token->getUser();
         $feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user));
         $aggregate = new Aggregate($app['EM'], $feeds, $token);
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page < 1 ? 1 : $page;
         return $app['feed.formatter-strategy']($format)->createResponse($app, $aggregate, $page, $user);
     })->bind('feed_user_aggregated')->assert('format', '(rss|atom)');
     $controllers->get('/aggregated/{format}/', function (Application $app, $format) {
         $feed = Aggregate::getPublic($app);
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page < 1 ? 1 : $page;
         return $app['feed.formatter-strategy']($format)->createResponse($app, $feed, $page);
     })->bind('feed_public_aggregated')->assert('format', '(rss|atom)');
     $controllers->get('/cooliris/', function (Application $app) {
         $feed = Aggregate::getPublic($app);
         $request = $app['request'];
         $page = (int) $request->query->get('page');
         $page = $page < 1 ? 1 : $page;
         return $app['feed.formatter-strategy']('cooliris')->createResponse($app, $feed, $page, null, 'Phraseanet', $app);
     })->bind('feed_public_cooliris');
     return $controllers;
 }
開發者ID:romainneutron,項目名稱:Phraseanet,代碼行數:50,代碼來源:RSSFeeds.php

示例15: build

 protected function build($siteid, $id, Request $request, Application $app)
 {
     $this->parameters = array();
     $sr = new SiteRepository();
     $this->parameters['site'] = $sr->loadById($siteid);
     if (!$this->parameters['site']) {
         $app->abort(404);
     }
     $sr = new UserGroupRepository();
     $this->parameters['usergroup'] = $sr->loadByIdInSite($id, $this->parameters['site']);
     if (!$this->parameters['usergroup']) {
         $app->abort(404);
     }
 }
開發者ID:radical-assembly,項目名稱:OpenACalendar-Web-Core,代碼行數:14,代碼來源:SiteUserGroupController.php


注:本文中的Silex\Application::abort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。