当前位置: 首页>>代码示例>>PHP>>正文


PHP RouterInterface::setContext方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\RouterInterface::setContext方法的典型用法代码示例。如果您正苦于以下问题:PHP RouterInterface::setContext方法的具体用法?PHP RouterInterface::setContext怎么用?PHP RouterInterface::setContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\RouterInterface的用法示例。


在下文中一共展示了RouterInterface::setContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: __construct

 public function __construct(Registry $doctrine, \Swift_Mailer $mailer, EngineInterface $templateEngine, RouterInterface $router, BatchLimiterInterface $limiter)
 {
     $this->em = $doctrine->getManager();
     $this->mailer = $mailer;
     $this->templateEngine = $templateEngine;
     $this->router = $router;
     $this->limiter = $limiter;
     $this->debugOut = new NullOutput();
     $this->router->setContext(new RequestContext('', 'GET', 'www.gotchosen.com', 'https'));
 }
开发者ID:scottstuff,项目名称:GCProtractorJS,代码行数:10,代码来源:Processor.php

示例4: 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

示例5: 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

示例6: 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:emodric,项目名称:LegacyBridge,代码行数:22,代码来源:SetupListener.php

示例7: add

 /**
  * Add a Router to the index
  *
  * @param RouterInterface $router
  * @param integer         $priority
  */
 public function add(RouterInterface $router, $priority = 0)
 {
     if (empty($this->routers[$priority])) {
         $this->routers[$priority] = array();
     }
     if ($router instanceof RequestContextAwareInterface) {
         $context = $this->getContext();
         if (null !== $context) {
             $router->setContext($context);
         }
     }
     $this->routers[$priority][] = $router;
     $this->sortedRouters = array();
 }
开发者ID:cwplus,项目名称:RaindropRoutingBundle,代码行数:20,代码来源:ChainRouter.php

示例8: setContext

 /**
  * {@inheritdoc}
  */
 public function setContext(RequestContext $context)
 {
     $this->router->setContext($context);
 }
开发者ID:code-ph0y,项目名称:framework,代码行数:7,代码来源:SymfonyRouterWrapper.php


注:本文中的Symfony\Component\Routing\RouterInterface::setContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。