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


PHP RouterInterface::getContext方法代碼示例

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


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

示例1: onKernelRequest

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($event->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     // @todo make endpoint(s) customizable
     if ($event->getRequest()->getMethod() !== 'POST') {
         return;
     }
     if ($event->getRequest()->getPathInfo() != '/xmlrpc' && $event->getRequest()->getPathInfo() != '/xmlrpc.php') {
         return;
     }
     try {
         $request = $this->requestGenerator->generateFromRequest($event->getRequest());
         if (isset($this->logger)) {
             $this->logger->debug((string) $request);
         }
     } catch (UnexpectedValueException $e) {
         $event->setResponse(new Response("Invalid request XML\n" . $e->getMessage(), 400));
         return;
     }
     // @todo refactor to dynamically set follow-up events instead of testing (cors bundle like)
     $request->attributes->set('IsXmlRpcRequest', true);
     $requestContext = new RequestContext();
     $requestContext->fromRequest($request);
     $originalContext = $this->router->getContext();
     $this->router->setContext($requestContext);
     $response = $this->httpKernel->handle($request);
     $event->setResponse($response);
     $this->router->setContext($originalContext);
     if ($response instanceof Response) {
         $event->setResponse($response);
     }
 }
開發者ID:bdunogier,項目名稱:xmlrpcbundle,代碼行數:37,代碼來源:RequestEventListener.php

示例2: renderMenuItemTemplate

 /**
  * @param \Twig_Environment $environment
  * @param $node
  * @param array $options
  * @return string
  */
 public function renderMenuItemTemplate(\Twig_Environment $environment, $node, $options = array())
 {
     $template = isset($options['template']) ? $options['template'] : false;
     if ($template === false) {
         $template = 'KunstmaanMenuBundle::menu-item.html.twig';
     }
     $active = false;
     if ($node['type'] == MenuItem::TYPE_PAGE_LINK) {
         $url = $this->router->generate('_slug', array('url' => $node['nodeTranslation']['url']));
         if ($this->router->getContext()->getPathInfo() == $url) {
             $active = true;
         }
     } else {
         $url = $node['url'];
     }
     if ($node['type'] == MenuItem::TYPE_PAGE_LINK) {
         if ($node['title']) {
             $title = $node['title'];
         } else {
             $title = $node['nodeTranslation']['title'];
         }
     } else {
         $title = $node['title'];
     }
     return $environment->render($template, array('menuItem' => $node, 'url' => $url, 'options' => $options, 'title' => $title, 'active' => $active));
 }
開發者ID:BranchBit,項目名稱:KunstmaanBundlesCMS,代碼行數:32,代碼來源:RenderService.php

示例3: setHost

 private function setHost($host)
 {
     if (1 !== preg_match('#^(https?)://([\\w\\.-]+)#', $host, $matches)) {
         throw new \InvalidArgumentException(sprintf('The host "%s" is invalid.', $host));
     }
     $context = $this->router->getContext();
     $context->setScheme($matches[1]);
     $context->setHost($matches[2]);
 }
開發者ID:silvestra,項目名稱:sitemap,代碼行數:9,代碼來源:DumpCommand.php

示例4: generate

 public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
 {
     $baseContext = $this->router->getContext();
     try {
         $this->router->setContext(new RequestContext('', 'GET', $baseContext->getHost(), $baseContext->getScheme(), $baseContext->getHttpPort(), $baseContext->getHttpsPort()));
         return $this->router->generate($name, $parameters, $referenceType);
     } finally {
         $this->router->setContext($baseContext);
     }
 }
開發者ID:reminec,項目名稱:DunglasApiBundle,代碼行數:10,代碼來源:Router.php

示例5: getPathInfoFromMetaTagKey

 /**
  * @param $key
  *
  * @return array An array of parameters
  */
 public function getPathInfoFromMetaTagKey($key)
 {
     $info = $this->keyGenerator->generatePathInfoFromMetaTagKey($key);
     $this->router->getContext()->setMethod('GET');
     if ($this->keyGenerator->isAddQueryString()) {
         $info = substr($info, 0, strpos($info, '?'));
         $match = $this->router->match($info);
         return $match;
     } else {
         return $this->router->match($info);
     }
 }
開發者ID:vstm,項目名稱:IbrowsSimpleSeoBundle,代碼行數:17,代碼來源:AliasHandler.php

示例6: initFilterEmbed

 /**
  * @param Request $request
  * @param         $id
  * @param         $embed
  *
  * @return ResourceInterface
  */
 public function initFilterEmbed(Request $request, $id, $embed)
 {
     $embedShortname = ucwords(Inflector::singularize($embed));
     /** @var $resourceEmbed ResourceInterface */
     $resourceEmbed = $this->resourceResolver->getResourceForShortName($embedShortname, $this->router->getContext()->getApiVersion());
     $filter = new EmbedFilter($this->managerRegistry, $this->propertyAccessor);
     $params = !$request->request->has('embedParams') ? ['embed' => $embed, 'id' => $id] : $request->request->get('embedParams');
     $filter->setParameters($params);
     $filter->setRouteName($request->get('_route'));
     $resourceEmbed->addFilter($filter);
     return $resourceEmbed;
 }
開發者ID:eliberty,項目名稱:api-bundle,代碼行數:19,代碼來源:InitFilterEmbed.php

示例7: onRequest

 /**
  * {@inheritdoc}
  */
 public function onRequest(GetResponseEvent $event)
 {
     $context = $this->router->getContext();
     $portalInformation = $this->requestAnalyzer->getPortalInformation();
     if ($portalInformation) {
         if (!$context->hasParameter('prefix')) {
             $context->setParameter('prefix', $portalInformation->getPrefix());
         }
         if (!$context->hasParameter('host')) {
             $context->setParameter('host', $portalInformation->getHost());
         }
     }
 }
開發者ID:sulu,項目名稱:sulu,代碼行數:16,代碼來源:RequestListener.php

示例8: match

 public function match($pathInfo)
 {
     $baseContext = $this->router->getContext();
     $pathInfo = str_replace($baseContext->getBaseUrl(), '', $pathInfo);
     $request = Request::create($pathInfo);
     $context = (new RequestContext())->fromRequest($request);
     $context->setPathInfo($pathInfo);
     try {
         $this->router->setContext($context);
         return $this->router->match($request->getPathInfo());
     } finally {
         $this->router->setContext($baseContext);
     }
 }
開發者ID:rolebi,項目名稱:DunglasApiBundle,代碼行數:14,代碼來源:Router.php

示例9: generate

 public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
 {
     if (is_object($name)) {
         if ($name instanceof ResourceInterface) {
             $embedRouteName = $this->getEmbedRouteName($name, $parameters);
             $name = $embedRouteName === false ? $this->getItemRouteName($name, 'collection') : $embedRouteName;
         } else {
             $parameters = $this->getParamsByResource($name);
         }
     }
     if (isset($parameters['id']) && $parameters['id'] === 0) {
         return null;
     }
     $baseContext = $this->router->getContext();
     try {
         $this->router->setContext(new RequestContext('', 'GET', $baseContext->getHost(), $baseContext->getScheme(), $baseContext->getHttpPort(), $baseContext->getHttpsPort()));
         try {
             return $this->router->generate($name, $parameters, $referenceType);
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
     } finally {
         $this->router->setContext($baseContext);
     }
 }
開發者ID:eliberty,項目名稱:api-bundle,代碼行數:25,代碼來源:Router.php

示例10: onKernelRequestSetup

 /**
  * Checks if it's needed to redirect to setup wizard
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 public function onKernelRequestSetup(GetResponseEvent $event)
 {
     if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
         if ($this->defaultSiteAccess !== 'setup') {
             return;
         }
         $request = $event->getRequest();
         $requestContext = $this->router->getContext();
         $requestContext->fromRequest($request);
         $this->router->setContext($requestContext);
         $setupURI = $this->router->generate('ezpublishSetup');
         if ($requestContext->getBaseUrl() . $request->getPathInfo() === $setupURI) {
             return;
         }
         $event->setResponse(new RedirectResponse($setupURI));
     }
 }
開發者ID:CG77,項目名稱:ezpublish-kernel,代碼行數:22,代碼來源:RequestEventListener.php

示例11: generateUrl

 /**
  * @param string|array $routeDefinition
  * @return string
  */
 private function generateUrl($routeDefinition)
 {
     $route = is_array($routeDefinition) ? $routeDefinition['route'] : $routeDefinition;
     $parameters = is_array($routeDefinition) ? $routeDefinition['parameters'] : [];
     $context = $this->router->getContext();
     $context->fromRequest($this->requestStack->getMasterRequest());
     $url = $this->router->generate($route, $parameters, RouterInterface::ABSOLUTE_URL);
     $context->fromRequest($this->requestStack->getCurrentRequest());
     return $url;
 }
開發者ID:surfnet,項目名稱:stepup-saml-bundle,代碼行數:14,代碼來源:HostedEntities.php

示例12: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $context = $this->router->getContext();
     preg_match('/^\\/convention\\/([a-z]\\w+)/', $context->getPathInfo(), $matches);
     $code = isset($matches[1]) ? $matches[1] : $this->baseCode;
     if (!$context->hasParameter('code')) {
         $context->setParameter('code', $code);
     }
     if ($this->baseCode == $code) {
         $site = new Convention();
         $site->setDomain('ritsi');
         $this->siteManager->setCurrentSite($site);
         return;
     }
     $site = $this->em->getRepository('AppBundle:Convention')->findOneBy(array('domain' => $code));
     if (!$site) {
         throw new NotFoundHttpException(sprintf('No site for code "%s"', $code));
     }
     $this->siteManager->setCurrentSite($site);
 }
開發者ID:sergiormb,項目名稱:ritsiga,代碼行數:20,代碼來源:CurrentSiteListener.php

示例13: getBaseUrl

 /**
  * @param array $options
  *
  * @return string
  */
 protected function getBaseUrl(array $options)
 {
     if (!empty($options['index']['base_url'])) {
         if ('/' == substr($options['index']['base_url'], -1)) {
             return $options['index']['base_url'];
         }
         return sprintf('%s/', $options['index']['base_url']);
     }
     $context = $this->router->getContext();
     return sprintf('%s://%s%s', $context->getScheme(), $context->getHost(), $context->getPathInfo());
 }
開發者ID:skuola,項目名稱:SitemapBundle,代碼行數:16,代碼來源:SitemapGeneratorCommand.php

示例14: getEntityResourceUri

 /**
  * @param string $entityClass
  *
  * @return string|null
  */
 protected function getEntityResourceUri($entityClass)
 {
     $uri = null;
     if ($this->entityAliasResolver->hasAlias($entityClass)) {
         try {
             $uri = $this->router->generate('oro_rest_api_cget', ['entity' => $this->entityAliasResolver->getPluralAlias($entityClass)]);
         } catch (RoutingException $e) {
             // ignore any exceptions
         }
     }
     if ($uri) {
         $baseUrl = $this->router->getContext()->getBaseUrl();
         if ($baseUrl) {
             $uri = substr($uri, strlen($baseUrl));
         }
     }
     return $uri;
 }
開發者ID:startupz,項目名稱:platform-1,代碼行數:23,代碼來源:ExcludeNotAccessibleRelations.php

示例15: create

 /**
  * Create text form.
  *
  * @param TextNodeInterface $textNode
  *
  * @return FormInterface
  */
 public function create(TextNodeInterface $textNode)
 {
     return $this->formFactory->create('silvestra_text_node', $textNode, array('method' => 'POST', 'action' => $this->router->getContext()->getPathInfo()));
 }
開發者ID:silvestra,項目名稱:silvestra,代碼行數:11,代碼來源:TextNodeFormFactory.php


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