本文整理汇总了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);
}
}
示例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);
}
}
示例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'));
}
示例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);
}
}
示例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);
}
}
示例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));
}
}
示例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();
}
示例8: setContext
/**
* {@inheritdoc}
*/
public function setContext(RequestContext $context)
{
$this->router->setContext($context);
}