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


PHP RequestContext::fromRequest方法代码示例

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


在下文中一共展示了RequestContext::fromRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: match

 /**
  * @param Request $request
  */
 public function match(Request $request)
 {
     // Initialize the context that is also used by the generator (assuming matcher and generator share the same
     // context instance).
     $this->context->fromRequest($request);
     if ($request->attributes->has('_controller')) {
         // Routing is already done.
         return;
     }
     // Add attributes based on the request (routing).
     try {
         // Matching a request is more powerful than matching a URL path + context, so try that first.
         if ($this->matcher instanceof RequestMatcherInterface) {
             $parameters = $this->matcher->matchRequest($request);
         } else {
             $parameters = $this->matcher->match($request->getPathInfo());
         }
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
         }
         $request->attributes->add($parameters);
         unset($parameters['_route']);
         unset($parameters['_controller']);
         $request->attributes->set('_route_params', $parameters);
     } catch (ResourceNotFoundException $e) {
         $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
         throw new NotFoundHttpException($message, $e);
     } catch (MethodNotAllowedException $e) {
         $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
         throw new MethodNotAllowedException($e->getAllowedMethods(), $message);
     }
 }
开发者ID:code-ph0y,项目名称:framework,代码行数:35,代码来源:RouterListener.php

示例2: getContext

 /**
  * {@inheritdoc}
  */
 public function getContext()
 {
     if (!isset($this->context)) {
         $this->context = new RequestContext();
         $this->context->fromRequest($this->request);
     }
     return $this->context;
 }
开发者ID:Opifer,项目名称:Cms,代码行数:11,代码来源:RedirectRouter.php

示例3: getContext

 /**
  * @return RequestContext
  */
 public function getContext()
 {
     if (!$this->context) {
         $this->context = new RequestContext();
         $this->context->fromRequest(\Request::getInstance());
     }
     return $this->context;
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:11,代码来源:Router.php

示例4: getContext

 /**
  * Gets the request context.
  *
  * @return RequestContext The context
  *
  * @api
  */
 public function getContext()
 {
     if (!isset($this->context)) {
         $this->context = new RequestContext();
         $this->context->fromRequest($this->container->get('request_stack')->getCurrentRequest());
     }
     return $this->context;
 }
开发者ID:VickyDeschrijver,项目名称:KunstmaanBundlesCMS,代码行数:15,代码来源:LanguageChooserRouter.php

示例5: getContext

 /**
  * Gets the request context.
  *
  * @return RequestContext The context
  */
 public function getContext()
 {
     if (!isset($this->context)) {
         $request = $this->container->get('request');
         $this->context = new RequestContext();
         $this->context->fromRequest($request);
     }
     return $this->context;
 }
开发者ID:Opifer,项目名称:CrudBundle,代码行数:14,代码来源:AbstractRouter.php

示例6: getContext

 /**
  * Gets the request context.
  *
  * @return RequestContext The context
  *
  * @api
  */
 public function getContext()
 {
     if (!isset($this->context)) {
         /** @var Request $request */
         $request = $this->getMasterRequest();
         $this->context = new RequestContext();
         $this->context->fromRequest($request);
     }
     return $this->context;
 }
开发者ID:rifer,项目名称:KunstmaanBundlesCMS,代码行数:17,代码来源:SlugRouter.php

示例7: testResolve

 /**
  * @dataProvider resolveProvider
  */
 public function testResolve($path, $filter, $requestUrl, $expected)
 {
     if ($requestUrl) {
         $this->requestContext->fromRequest(Request::create($requestUrl));
     }
     $storageDir = '/var/doctorwho/storage/images';
     $this->ioService->expects($this->once())->method('loadBinaryFile')->with($path)->will($this->returnValue(new BinaryFile(array('uri' => "{$storageDir}/{$path}"))));
     $result = $this->imageResolver->resolve($path, $filter);
     $this->assertSame($expected, $result);
 }
开发者ID:masev,项目名称:ezpublish-kernel,代码行数:13,代码来源:IORepositoryResolverTest.php

示例8: __construct

 private function __construct($routes)
 {
     $this->routeCollection = $routes;
     $this->request = Request::createFromGlobals();
     $this->requestContext = new RequestContext();
     $this->matcher = new UrlMatcher($routes, $this->requestContext->fromRequest($this->getRequest()));
     $this->dispatcher = new Dispatcher();
     $this->dispatcher->addSubscriber(new RouterListener($this->matcher, new RequestStack()));
     $this->dispatcher->addSubscriber(new KernelExceptionListener());
     $this->dispatcher->addSubscriber(new ResponseListener('UTF-8'));
 }
开发者ID:primephp,项目名称:framework,代码行数:11,代码来源:Kernel.php

示例9: handle

 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     try {
         $this->request = $request;
         $pathInfo = $request->getPathInfo();
         $this->loadRoutes($pathInfo);
         $this->loadGeneralConfig();
         $this->loadZyncroAppConfig($pathInfo);
         $this->loadDatabaseConfig($pathInfo);
         $this->loadSecurityConfig($pathInfo);
         $this->loadTwig($pathInfo);
         $this->loadUtils();
         $this->method = $request->getMethod();
         $this->dispatcher->dispatch('request', new RequestEvent($request, $this->session, $this->securityConfig, $this->routes));
         $this->loadApi();
         $context = new Routing\RequestContext();
         $matcher = new Routing\Matcher\UrlMatcher($this->routes, $context);
         $context->fromRequest($request);
         $request->attributes->add($matcher->match($request->getPathInfo()));
         $resolver = new ControllerResolver();
         $controller = $resolver->getController($request);
         $arguments = $resolver->getArguments($request, $controller);
         $arguments[0] = $this;
         $response = call_user_func_array($controller, $arguments);
     } catch (Routing\Exception\ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (\Exception $e) {
         $response = new Response('An error occurred: ' . $e->getMessage(), 500);
     }
     return $response;
 }
开发者ID:zyncro,项目名称:framework,代码行数:31,代码来源:App.php

示例10: listener

 public static function listener(RequestEvent $requestEvent)
 {
     $request = $requestEvent->getRequest();
     $pathInfo = $request->getPathInfo();
     $session = $requestEvent->getSession();
     $configSecurity = $requestEvent->getSecurityConfig();
     $routes = $requestEvent->getRoutes();
     $context = new RequestContext();
     $matcher = new UrlMatcher($routes, $context);
     $context->fromRequest($request);
     $matching = $matcher->match($pathInfo);
     $matchedRoute = $matching['_route'];
     if (isset($configSecurity['protected'])) {
         $protected = $configSecurity['protected'];
         $protectedRoutes = $protected['routes'];
         $sessionKey = $protected['session'];
         $notLoggedRoute = $protected['not_logged'];
         $loggedRoute = $protected['logged'];
         $redirectRoute = null;
         if ($session->get($sessionKey) && $matchedRoute === $notLoggedRoute) {
             $redirectRoute = $routes->get($loggedRoute);
         }
         if (!$session->get($sessionKey) && in_array($matchedRoute, $protectedRoutes)) {
             $redirectRoute = $routes->get($notLoggedRoute);
         }
         if ($redirectRoute) {
             $redirectResponse = new RedirectResponse($request->getBaseUrl() . $redirectRoute->getPath());
             $redirectResponse->send();
         }
     }
 }
开发者ID:zyncro,项目名称:framework,代码行数:31,代码来源:Security.php

示例11: getMatcherFromRequest

 private function getMatcherFromRequest($request)
 {
     $context = new Routing\RequestContext();
     $context->fromRequest($request);
     $matcher = new Routing\Matcher\UrlMatcher($this->routes, $context);
     return $matcher;
 }
开发者ID:gonzalo123,项目名称:g,代码行数:7,代码来源:ControllerResolver.php

示例12: register

 public function register(Container $container)
 {
     $container['request'] = function ($c) {
         return Request::createFromGlobals();
     };
     $container['requestStack'] = function ($c) {
         $stack = new RequestStack();
         $stack->push($c['request']);
         return $stack;
     };
     $container['requestContext'] = function ($c) {
         $rc = new RequestContext();
         $rc->fromRequest($c['request']);
         return $rc;
     };
     $container['resolver'] = function ($c) {
         return new ControllerResolver();
     };
     $container['httpKernel'] = function ($c) {
         return new HttpKernel($c['dispatcher'], $c['resolver'], $c['requestStack']);
     };
     $container['router'] = function ($c) {
         $router = new ChainRouter($c['logger']);
         $router->add($c['staticRouter']);
         $router->add($c['nodeRouter']);
         return $router;
     };
     $container['staticRouter'] = function ($c) {
         return new StaticRouter($c['routeCollection'], ['cache_dir' => (bool) $c['config']['devMode'] ? null : ROADIZ_ROOT . '/cache/routing', 'debug' => (bool) $c['config']['devMode'], 'generator_cache_class' => 'StaticUrlGenerator', 'matcher_cache_class' => 'StaticUrlMatcher'], $c['requestContext'], $c['logger']);
     };
     $container['nodeRouter'] = function ($c) {
         return new NodeRouter($c['em'], ['cache_dir' => (bool) $c['config']['devMode'] ? null : ROADIZ_ROOT . '/cache/routing', 'debug' => (bool) $c['config']['devMode'], 'generator_cache_class' => 'NodeUrlGenerator', 'matcher_cache_class' => 'NodeUrlMatcher'], $c['requestContext'], $c['logger'], $c['stopwatch']);
     };
     $container['urlGenerator'] = function ($c) {
         return $c['staticRouter']->getGenerator();
     };
     $container['httpUtils'] = function ($c) {
         return new HttpUtils($c['router'], $c['router']);
     };
     $container['routeListener'] = function ($c) {
         return new TimedRouteListener($c['router'], $c['requestContext'], null, $c['requestStack'], $c['stopwatch']);
     };
     $container['routeCollection'] = function ($c) {
         if (isset($c['config']['install']) && true === $c['config']['install']) {
             /*
              * Get Install routes
              */
             $installClassname = Kernel::INSTALL_CLASSNAME;
             $installClassname::setupDependencyInjection($c);
             return new InstallRouteCollection($installClassname);
         } else {
             /*
              * Get App routes
              */
             $rCollection = new RoadizRouteCollection($c['backendClass'], $c['frontendThemes'], SettingsBag::get('static_domain_name'), $c['stopwatch']);
             return $rCollection;
         }
     };
     return $container;
 }
开发者ID:QuangDang212,项目名称:roadiz,代码行数:60,代码来源:RoutingServiceProvider.php

示例13: route

 public function route($url)
 {
     try {
         $context = new RequestContext();
         $context->fromRequest($this->_request);
         $closure = function () {
             return $this->_container->get('routes');
         };
         $arrpar = array();
         if (!DEVELOPMENT_ENVIRONMENT) {
             $arrpar['cache_dir'] = ROUTECACHE;
         } else {
             \Debug::addRoutes($closure);
         }
         $router = new SymfonyRouter(new ClosureLoader(), $closure, $arrpar, $context);
         $parameters = $router->match($url);
         $this->_controller = $parameters["controller"];
         $this->_method = $parameters["action"];
         $this->_route = $parameters["_route"];
         unset($parameters["controller"]);
         unset($parameters["action"]);
         unset($parameters["_route"]);
         $this->_args = $parameters;
     } catch (ResourceNotFoundException $e) {
         $this->_route = "";
     } catch (\Symfony\Component\Routing\Exception\MethodNotAllowedException $ema) {
         $this->_route = "";
         throw new \GL\Core\Exception\MethodNotAllowedException();
     }
     return $this->_route != "";
 }
开发者ID:kletellier,项目名称:mvc,代码行数:31,代码来源:Router.php

示例14: resolveController

 /**
  * @return array|bool
  */
 protected function resolveController()
 {
     try {
         // doctrine mabo jambo to prepare route detection
         $context = new RequestContext();
         $context->fromRequest($this->request);
         $matcher = new UrlMatcher($this->routeCollection, $context);
         // try detecting controller & stuff
         $this->request->attributes->add($matcher->match($this->request->getPathInfo()));
         // resolve controller
         $resolver = new ControllerResolver();
         $controller = $resolver->getController($this->request);
         $controller = $this->assembleController($controller);
         // adding request and response variables to the controller
         if (!empty($controller[0]) && $controller[0] instanceof AbstractSimplexController) {
             $controller[0]->setRequest($this->request)->setResponse($this->response);
         } else {
             // or as attributes for a 'function' controller
             $req = array('request' => $this->request, 'response' => $this->response);
             $this->request->attributes->add($req);
         }
         // parsing arguments for the request and adding a last argument the request parameter itself
         $arguments = $resolver->getArguments($this->request, $controller);
         return array($controller, $arguments);
     } catch (ResourceNotFoundException $e) {
     }
     return false;
 }
开发者ID:athemcms,项目名称:netis,代码行数:31,代码来源:SymphonyBased.php

示例15: getControllerResponse

 /**
  * @param Request $request
  *
  * @return Response
  */
 public function getControllerResponse(Request $request)
 {
     // build the context from the Request that was passed
     $this->context->fromRequest($request);
     // instantiate the router with the correct settings so it can automatically perform caching
     $router = new Router($this->loader, Configuration::instance()->setting('base', 'routeFile', 'routes.php'), ['cache_dir' => Configuration::instance()->setting('base', 'routeCacheDir')], $this->context);
     // TODO make this configurable
     // default controller
     $match = ["_controller" => '\\Controllers\\HomeController', "_action" => "index"];
     try {
         $match = $router->matchRequest($request);
     } catch (\Exception $ex) {
         if ($ex instanceof ResourceNotFoundException) {
             // TODO improve this
             return new Response("404 Not Found", 404);
         } elseif ($ex instanceof MethodNotAllowedException) {
             // TODO improve this
             return new Response("Current request method is not allowed for this route", 401);
         }
     }
     // dynamically instantiate a new controller and pass it the Request object
     $controller = new $match['_controller']($request);
     $action = $match['_action'];
     // parse out all parameters (those keys that do not start with an underscore)
     $parameters = $this->getParameters($match);
     // we pass $match as last parameter because it also contains all key-value pairs for the arguments of the action
     $responseText = call_user_func_array([$controller, $action], $parameters);
     // wrap the response that was generated by the controller
     $response = new Response($responseText);
     return $response;
 }
开发者ID:rickvanbodegraven,项目名称:project-mandy,代码行数:36,代码来源:Routing.php


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