本文整理汇总了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);
}
}
示例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));
}
示例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]);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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());
}
}
}
示例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);
}
}
示例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);
}
}
示例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));
}
}
示例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;
}
示例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);
}
示例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());
}
示例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;
}
示例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()));
}