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


PHP Routing\RouterInterface類代碼示例

本文整理匯總了PHP中Symfony\Component\Routing\RouterInterface的典型用法代碼示例。如果您正苦於以下問題:PHP RouterInterface類的具體用法?PHP RouterInterface怎麽用?PHP RouterInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: buildPageTree

 /**
  * Builds the pagetree
  *
  * @param RouterInterface $router
  *
  * @throws PageTree\InvalidPageTreeException
  */
 private function buildPageTree(RouterInterface $router)
 {
     $this->pageTree = [];
     $this->directAccess = [];
     // collect all routes, which are configured to be in the page tree
     foreach ($router->getRouteCollection() as $routeName => $route) {
         /** @var Route $route */
         $node = $this->transformRouteToNode($routeName, $route);
         if (!is_null($node)) {
             $this->directAccess[$routeName] = $node;
         }
     }
     // apply correct nesting of routes
     foreach ($this->directAccess as $node) {
         if ($node->isRootNode()) {
             $this->pageTree[] = $node;
         } else {
             if (array_key_exists($node->getParent(), $this->directAccess)) {
                 $this->directAccess[$node->getParent()]->addChild($node);
             } else {
                 throw new InvalidPageTreeException("Invalid pagetree at route „{$node->getRoute()}“: parent '{$node->getParent()}' requested, but route was not found. Did you forget to define the route „{$node->getRoute()}“ as root?");
             }
         }
     }
 }
開發者ID:Gemineye,項目名稱:BecklynPageTreeBundle,代碼行數:32,代碼來源:PageTreeModel.php

示例2: onSiteAccessMatch

 public function onSiteAccessMatch(PostSiteAccessMatchEvent $event)
 {
     $rootLocationId = $this->configResolver->getParameter('content.tree_root.location_id');
     $this->urlAliasRouter->setRootLocationId($rootLocationId);
     $this->urlAliasGenerator->setRootLocationId($rootLocationId);
     $this->urlAliasGenerator->setExcludedUriPrefixes($this->configResolver->getParameter('content.tree_root.excluded_uri_prefixes'));
 }
開發者ID:CG77,項目名稱:ezpublish-kernel,代碼行數:7,代碼來源:RoutingListener.php

示例3: redirectToRoute

 /**
  * @param string $route
  * @param array  $data
  *
  * @return RedirectResponse
  */
 public function redirectToRoute($route, array $data = array())
 {
     if ('referer' === $route) {
         return $this->redirectToReferer();
     }
     return $this->redirect($this->router->generate($route, $data));
 }
開發者ID:aleherse,項目名稱:Sylius,代碼行數:13,代碼來源:RedirectHandler.php

示例4: sendResettingEmailMessage

 /**
  * {@inheritDoc}
  */
 public function sendResettingEmailMessage(UserInterface $user)
 {
     $template = $this->parameters['resetting_password.template'];
     $url = $this->router->generate('fos_user_resetting_reset', array('token' => $user->getConfirmationToken()), true);
     $rendered = $this->templating->render($template, array('confirmationUrl' => $url, 'user' => $user));
     $this->sendEmailMessage($rendered, $user->getEmail());
 }
開發者ID:mattvick,項目名稱:FOSUserBundleMandrillMailer,代碼行數:10,代碼來源:FOSUserBundleMailer.php

示例5: serializeRouteArrayToJson

 public function serializeRouteArrayToJson(JsonSerializationVisitor $visitor, array $route, array $type, Context $context)
 {
     if (is_array($route)) {
         list($routeName, $routeParameters) = $route;
         return $this->router->generate($routeName, $routeParameters);
     }
 }
開發者ID:gravity-cms,項目名稱:menu-bundle,代碼行數:7,代碼來源:RouteArrayHandler.php

示例6: warmUp

 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $processedRoutes = array();
     $routeCollection = $this->router->getRouteCollection();
     foreach ($routeCollection->all() as $name => $route) {
         if (!isset($processedRoutes[$route->getPattern()])) {
             $processedRoutes[$route->getPattern()] = array('methods' => array(), 'names' => array());
         }
         $processedRoutes[$route->getPattern()]['names'][] = $name;
         $requirements = $route->getRequirements();
         if (isset($requirements['_method'])) {
             $methods = explode('|', $requirements['_method']);
             $processedRoutes[$route->getPattern()]['methods'] = array_merge($processedRoutes[$route->getPattern()]['methods'], $methods);
         }
     }
     $allowedMethods = array();
     foreach ($processedRoutes as $processedRoute) {
         if (count($processedRoute['methods']) > 0) {
             foreach ($processedRoute['names'] as $name) {
                 $allowedMethods[$name] = array_unique($processedRoute['methods']);
             }
         }
     }
     $this->cache->write(sprintf('<?php return %s;', var_export($allowedMethods, true)), $routeCollection->getResources());
 }
開發者ID:kasobus,項目名稱:EDENS-Mautic,代碼行數:28,代碼來源:AllowedMethodsRouterLoader.php

示例7: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $routes = $this->router->getRouteCollection();
     $route = $routes->get($request->attributes->get('_route'));
     if (!$route->getOption('requires_license')) {
         return;
     }
     if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
         // Checking for whitelisted users
         try {
             $user = $this->tokenStorage->getToken()->getUser();
             $today = date('Y-m-d');
             if ($user instanceof UserInterface) {
                 $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
                 foreach ($whitelist as $allowed) {
                     if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
                         return;
                     }
                 }
             }
         } catch (\Exception $e) {
             // Do nothing
         }
         $url = $this->router->generate('atlassian_connect_unlicensed');
         $response = new RedirectResponse($url);
         $event->setResponse($response);
     }
 }
開發者ID:sainthardaway,項目名稱:atlassian-connect-bundle,代碼行數:32,代碼來源:LicenseListener.php

示例8: onMainTopMenuTools

 public function onMainTopMenuTools(HookRenderBlockEvent $event)
 {
     $isGranted = $this->securityContext->isGranted(["ADMIN"], [], [BoSearch::getModuleCode()], [AccessManager::VIEW]);
     if ($isGranted) {
         $event->add(['title' => $this->trans('Search product', [], BoSearch::DOMAIN_NAME), 'url' => $this->router->generate('bosearch.product.view')]);
     }
 }
開發者ID:thelia-modules,項目名稱:BoSearch,代碼行數:7,代碼來源:BoSearchHook.php

示例9: __invoke

 /**
  * @param Request $request
  * @return Response
  * @throws \Exception
  */
 public function __invoke(Request $request)
 {
     $walletId = $request->get('walletId');
     $walletDto = $this->walletServiceFacade->getWallet($walletId);
     $this->checkAuthorizationForWallet($walletDto);
     $createTransactionCommand = $this->createCreateTransactionCommand($walletId);
     $user = $this->getUser();
     $createTransactionForm = $this->transactionFormFactory->createCreateForm($createTransactionCommand, $user->getId()->getValue());
     $createTransactionForm->handleRequest($request);
     if (!$createTransactionForm->isValid()) {
         $validationMsg = $this->getAllFormErrorMessagesAsString($createTransactionForm);
         $this->addFlash('error', $this->trans('create_transaction_form.flash.invalid_form') . ' ' . $validationMsg);
     } else {
         /** @var CreateTransactionCommand $createTransactionCommand */
         $createTransactionCommand = $createTransactionForm->getData();
         try {
             $commandValidator = new CreateTransactionCommandValidator();
             $commandValidator->validate($createTransactionCommand);
             $this->commandBus->handle($createTransactionCommand);
             $this->addFlash('success', $this->trans('transaction.flash.create_successfully'));
             $url = $this->router->generate('bc_app_wallet_transaction.index', array('walletId' => $createTransactionCommand->getWalletId()));
             return new RedirectResponse($url);
         } catch (\Exception $e) {
             $this->addFlash('error', $e->getMessage());
         }
     }
     $walletDto = $this->walletServiceFacade->getWallet($walletId);
     return $this->renderTransactionShowNew($request, $createTransactionForm->createView(), $walletDto);
 }
開發者ID:qiyu2580,項目名稱:php-wallet-sample,代碼行數:34,代碼來源:Create.php

示例10: process

 /**
  * @param BreadcrumbItem $item
  * @param array          $variables
  * @return ProcessedBreadcrumbItem
  */
 public function process(BreadcrumbItem $item, $variables)
 {
     // Process the label
     if ($item->getLabel()[0] === '$') {
         $processedLabel = $this->parseValue($item->getLabel(), $variables);
     } else {
         $processedLabel = $this->translator->trans($item->getLabel());
     }
     // Process the route
     // TODO: cache parameters extracted from current request
     $params = [];
     foreach ($this->requestStack->getCurrentRequest()->attributes as $key => $value) {
         if ($key[0] !== '_') {
             $params[$key] = $value;
         }
     }
     foreach ($item->getRouteParams() ?: [] as $key => $value) {
         if ($value[0] === '$') {
             $params[$key] = $this->parseValue($value, $variables);
         } else {
             $params[$key] = $value;
         }
     }
     if ($item->getRoute() !== null) {
         $processedUrl = $this->router->generate($item->getRoute(), $params);
     } else {
         $processedUrl = null;
     }
     return new ProcessedBreadcrumbItem($processedLabel, $processedUrl);
 }
開發者ID:asprega,項目名稱:BreadcrumbBundle,代碼行數:35,代碼來源:BreadcrumbItemProcessor.php

示例11: getUriFromNode

 /**
  * {@inheritdoc}
  */
 protected function getUriFromNode(NodeInterface $node)
 {
     if ($node instanceof RouterNodeInterface && null !== $node->getRoute()) {
         return $this->router->generate($node->getRoute(), $node->getRouteParameters(), $node->isRouteAbsolute());
     }
     return $node->getUri();
 }
開發者ID:rogchap,項目名稱:Diakonia,代碼行數:10,代碼來源:RouterMenuFactory.php

示例12: onKernelException

 /**
  * Intercept Exceptions and send valid ajax errors
  * The idea is to NOT send HTML response when an issue(i.e.session expired) is encountered
  * in an ajax request.
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // Get the exception object from the received event
     $exception = $event->getException();
     $request = $event->getRequest();
     $isAjaxRequest = $request->isXmlHttpRequest();
     if ($isAjaxRequest) {
         $headers = [];
         // handle session expired
         if ($exception instanceof AuthenticationException) {
             $loginUrl = $this->router->generate('fos_user_security_login');
             // add custom header to redirect to login page on the client
             $headers['relogin'] = true;
             $headers['login-url'] = $loginUrl;
             $response = new Response('Authentication Required', 200, $headers);
         } elseif ($exception instanceof AccessDeniedException) {
             $headers['not-authorized'] = true;
             $response = new Response('Not authorized', 403, $headers);
         } else {
             $responseData = ['status' => false, 'msg' => 'Unknown Issue Encountered', 'data' => ['exception' => ['message' => $exception->getMessage(), 'file' => "{$exception->getFile()}:{$exception->getLine()}", 'trace' => $exception->getTraceAsString()]]];
             $response = new Response(json_encode($responseData), 500, $headers);
         }
         $event->setResponse($response);
         $event->stopPropagation();
     }
 }
開發者ID:atompulse,項目名稱:ran-bundle,代碼行數:32,代碼來源:AjaxExceptionListener.php

示例13: lostPasswordMail

 public function lostPasswordMail(User $user)
 {
     $template = 'HomefinanceBundle:mailer:lost_password.txt.twig';
     $url = $this->router->generate('reset_password_check_token', array('token' => $user->getConfirmationToken()), true);
     $context = array('user' => $user, 'confirmationUrl' => $url);
     $this->sendMessage($template, $context, $user->getEmail());
 }
開發者ID:jaapjansma,項目名稱:homefinance,代碼行數:7,代碼來源:TwigMailer.php

示例14: onKernelResponse

 /**
  * Sends the Hydra header on each response.
  *
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $event->getResponse()->headers->set('Link', sprintf('<%s>; rel="%sapiDocumentation"', $this->router->generate('api_hydra_vocab', [], UrlGeneratorInterface::ABSOLUTE_URL), ContextBuilder::HYDRA_NS));
 }
開發者ID:reminec,項目名稱:DunglasApiBundle,代碼行數:12,代碼來源:LinkHeaderResponseListener.php

示例15: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         return;
     }
     $session = $event->getRequest()->getSession();
     /** @var BaseController $ctrl */
     $ctrl = $controller[0];
     if (!is_object($ctrl) || !$ctrl instanceof BaseController) {
         return;
     }
     // no loop for you, also allow username checking
     if ($ctrl instanceof ProfileController && ($controller[1] == 'updateUsernameAction' || $controller[1] == 'checkUsernameAction')) {
         return;
     }
     /** @var User $user */
     $user = $ctrl->getUser();
     if ($user && $this->isGUID($user->getUsername())) {
         $session->getFlashBag()->add('error', "We recently changed our username restrictions. Your previous username is no longer valid. Please create a new one.");
         $url = $this->router->generate('reset_username');
         $event->setController(function () use($url) {
             return new RedirectResponse($url);
         });
     }
 }
開發者ID:scottstuff,項目名稱:GCProtractorJS,代碼行數:26,代碼來源:UnsetUsernameListener.php


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