当前位置: 首页>>代码示例>>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;未经允许,请勿转载。