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


PHP Routing\RequestContext类代码示例

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


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

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

示例2: action

 public function action(RouterInterface $router, RequestContext $context)
 {
     $request = Request::createFromGlobals();
     $bPath = $context->getPathInfo();
     try {
         $parameters = $router->match($bPath);
         var_dump($parameters);
         $_controller = $parameters["_controller"];
         $_controller = explode(":", $_controller);
         $class = $_controller[0];
         $action = strtolower($_controller[1]) . "Action";
         $class = new $class();
         ob_start();
         if (method_exists($class, $action)) {
             $class->{$action}($request, new JsonResponse());
             $response = new Response(ob_get_clean());
         } else {
             $response = new Response('Not Found', 404);
         }
     } catch (ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (Exception $e) {
         $response = new Response('An error occurred', 500);
     }
     $response->send();
 }
开发者ID:mbabenko21,项目名称:likedimion-server,代码行数:26,代码来源:RoutingBootstrap.php

示例3: test

 public function test()
 {
     $coll = new RouteCollection();
     $coll->add('foo', new Route('/foo', array(), array('_method' => 'POST')));
     $coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\\d+')));
     $coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\\w+', '_method' => 'POST')));
     $coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
     $coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
     $coll->add('bar4', new Route('/foo2', array(), array(), array(), 'baz', array(), array(), 'context.getMethod() == "GET"'));
     $context = new RequestContext();
     $context->setHost('baz');
     $matcher = new TraceableUrlMatcher($coll, $context);
     $traces = $matcher->getTraces('/babar');
     $this->assertEquals(array(0, 0, 0, 0, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo');
     $this->assertEquals(array(1, 0, 0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/12');
     $this->assertEquals(array(0, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertEquals(array(0, 1, 1, 0, 0, 0), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo1');
     $this->assertEquals(array(0, 0, 0, 0, 2), $this->getLevels($traces));
     $context->setMethod('POST');
     $traces = $matcher->getTraces('/foo');
     $this->assertEquals(array(2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/bar/dd');
     $this->assertEquals(array(0, 1, 2), $this->getLevels($traces));
     $traces = $matcher->getTraces('/foo2');
     $this->assertEquals(array(0, 0, 0, 0, 0, 1), $this->getLevels($traces));
 }
开发者ID:billwaddyjr,项目名称:Favorite-This-Demo,代码行数:30,代码来源:TraceableUrlMatcherTest.php

示例4: register

 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     /**
      * Holds information about the current request
      *
      * @return RequestContext
      */
     $app['request_context'] = function () use($app) {
         $context = new RequestContext();
         // set default http & https ports if not set
         $context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
         $context->setHttpsPort(isset($app['request.https_port']) ? $app['request.https_port'] : 443);
         return $context;
     };
     /**
      * Matches URL based on a set of routes.
      *
      * @return UrlMatcher
      */
     $app['matcher'] = function () use($app) {
         return new UrlMatcher($app['router'], $app['request_context']);
     };
     /**
      * Router
      */
     $options = array('cache_dir' => true === $app['use_cache'] ? __DIR__ . '/' . self::CACHE_DIRECTORY : null, 'debug' => true);
     $app['router'] = function () use($app, $options) {
         $router = new Router($app['config.loader'], sprintf(self::CONFIG_ROUTES_FILE, $app['env']), $options);
         return $router->getRouteCollection();
     };
 }
开发者ID:nkstamina,项目名称:framework,代码行数:34,代码来源:RoutingServiceProvider.php

示例5: testRedirectWhenNoSlash

 public function testRedirectWhenNoSlash()
 {
     $coll = new RouteCollection();
     $coll->add('foo', new Route('/foo/'));
     $matcher = new RedirectableUrlMatcher($coll, $context = new RequestContext());
     $this->assertEquals(array('_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction', 'path' => '/foo/', 'permanent' => true, 'scheme' => null, 'httpPort' => $context->getHttpPort(), 'httpsPort' => $context->getHttpsPort(), '_route' => null), $matcher->match('/foo'));
 }
开发者ID:almaaro,项目名称:Ilmokilke,代码行数:7,代码来源:RedirectableUrlMatcherTest.php

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

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

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

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

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

示例13: finalMatch

 /**
  * {@inheritdoc}
  */
 public function finalMatch(RouteCollection $collection, Request $request)
 {
     $this->routes = $collection;
     $context = new RequestContext();
     $context->fromRequest($request);
     $this->setContext($context);
     return $this->match($request->getPathInfo());
 }
开发者ID:Tobion,项目名称:Routing,代码行数:11,代码来源:UrlMatcher.php

示例14: __construct

 /**
  * @param Request $request
  * @param string  $path
  */
 public function __construct(Request $request, $path = '')
 {
     $context = new RequestContext();
     $context->fromRequest($request);
     $this->request = $request;
     $this->requestContext = $context;
     $this->path = $path;
 }
开发者ID:vianneyb,项目名称:pyrite,代码行数:12,代码来源:Director.php

示例15: getInstance

 /**
  * Get an object instance of UrlGenerator class.
  * 
  * @return UrlGenerator
  */
 public static function getInstance()
 {
     $configDirectory = new YamlFileLoader(new FileLocator(array(__DIR__ . '/../../Resources/config')));
     $captchaRoutes = $configDirectory->load('routing.yml');
     $requestContext = new RequestContext();
     $requestContext->fromRequest(Request::createFromGlobals());
     return new SymfonyUrlGenerator($captchaRoutes, $requestContext);
 }
开发者ID:RubenCox,项目名称:Symfony_Web-Mobile,代码行数:13,代码来源:UrlGenerator.php


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