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


PHP Request::getPathInfo方法代码示例

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


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

示例1: handle

 /**
  * Handles a Request to convert it to a Response.
  *
  * When $catch is true, the implementation must catch all exceptions
  * and do its best to convert them to a Response instance.
  *
  * @param Request $request A Request instance
  * @param int     $type    The type of the request
  *                         (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
  * @param bool    $catch   Whether to catch exceptions or not
  *
  * @return Response A Response instance
  *
  * @throws \Exception When an Exception occurs during processing
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     try {
         $match = $this->routeMatch;
         if (!$match) {
             $match = $this->router->match($request->getPathInfo());
         }
         if ($match) {
             list($module, $controller, $action) = $this->processRoute($match);
             $request->attributes->add(['_module' => $module, '_controller' => $controller, '_action' => $action]);
             $response = $this->dispatcher->dispatch($match['target'], $match['params']);
         } else {
             $response = $this->dispatcher->dispatch('Home#error', ['message' => 'Halaman tidak ditemukan: ' . $request->getPathInfo()]);
             $response->setStatusCode(Response::HTTP_NOT_FOUND);
         }
     } catch (HttpException $e) {
         if (!$catch) {
             throw $e;
         }
         $response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage()]);
         $response->setStatusCode($e->getStatusCode());
     } catch (Exception $e) {
         if (!$catch) {
             throw $e;
         }
         $response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage()]);
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     //$response->setMaxAge(300);
     return $response;
 }
开发者ID:raisoblast,项目名称:rakitan,代码行数:46,代码来源:Application.php

示例2: generateUrlCanonical

 /**
  * @param CanonicalUrlEvent $event
  */
 public function generateUrlCanonical(CanonicalUrlEvent $event)
 {
     if ($event->getUrl() !== null) {
         return;
     }
     $parseUrlByCurrentLocale = $this->getParsedUrlByCurrentLocale();
     if (empty($parseUrlByCurrentLocale['host'])) {
         return;
     }
     // Be sure to use the proper domain name
     $canonicalUrl = $parseUrlByCurrentLocale['scheme'] . '://' . $parseUrlByCurrentLocale['host'];
     // preserving a potential subdirectory, e.g. http://somehost.com/mydir/index.php/...
     $canonicalUrl .= $this->request->getBaseUrl();
     // Remove script name from path, e.g. http://somehost.com/index.php/...
     $canonicalUrl = preg_replace("!/index(_dev)?\\.php!", '', $canonicalUrl);
     $path = $this->request->getPathInfo();
     if (!empty($path) && $path != "/") {
         $canonicalUrl .= $path;
         $canonicalUrl = rtrim($canonicalUrl, '/');
     } else {
         $queryString = $this->request->getQueryString();
         if (!empty($queryString)) {
             $canonicalUrl .= '/?' . $queryString;
         }
     }
     $event->setUrl($canonicalUrl);
 }
开发者ID:thelia-modules,项目名称:CanonicalUrl,代码行数:30,代码来源:CanonicalUrlListener.php

示例3: matches

 public function matches(Request $request)
 {
     if (!$this->language) {
         throw new \LogicException('Unable to match the request as the expression language is not available.');
     }
     return $this->language->evaluate($this->expression, array('request' => $request, 'method' => $request->getMethod(), 'path' => rawurldecode($request->getPathInfo()), 'host' => $request->getHost(), 'ip' => $request->getClientIp(), 'attributes' => $request->attributes->all())) && parent::matches($request);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:7,代码来源:ExpressionRequestMatcher.php

示例4: initializeRequestAttributes

 protected function initializeRequestAttributes(Request $request, $master)
 {
     if ($master) {
         // set the context even if the parsing does not need to be done
         // to have correct link generation
         $this->router->setContext(array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'is_secure' => $request->isSecure()));
     }
     if ($request->attributes->has('_controller')) {
         // routing is already done
         return;
     }
     // add attributes based on the path info (routing)
     try {
         $parameters = $this->router->match($request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters)));
         }
         $request->attributes->add($parameters);
         if ($locale = $request->attributes->get('_locale')) {
             $request->getSession()->setLocale($locale);
         }
     } catch (NotFoundException $e) {
         $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         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())));
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
     }
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:35,代码来源:RequestListener.php

示例5: handle

 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $match = $this->router->match($request->getPathInfo());
     $route = substr($request->getPathInfo(), strlen(rtrim($this->config['baseDir'], '/')));
     if ($match) {
         $tokenValid = false;
         $jwtCookie = $this->config['jwt']['cookieName'];
         $jwtKey = $this->config['jwt']['key'];
         // check token from cookie
         if ($request->cookies->has($jwtCookie)) {
             $jwt = $request->cookies->get($jwtCookie);
             try {
                 $decoded = JWT::decode($jwt, $jwtKey, ['HS256']);
                 if ($decoded->e > time()) {
                     $tokenValid = true;
                     $this->auth->init($decoded->uid);
                 }
             } catch (\Exception $e) {
                 $tokenValid = false;
                 if (!$catch) {
                     throw $e;
                 }
                 $response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>']);
                 $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
                 return $response;
             }
         }
         $allowed = false;
         $isPublic = false;
         foreach ($this->config['publicArea'] as $publicRoute) {
             if (preg_match('/^' . addcslashes($publicRoute, '/') . '/', $route)) {
                 $isPublic = true;
                 break;
             }
         }
         if ($match['name'] == 'home') {
             $isPublic = true;
         }
         if ($isPublic) {
             if ($route == '/login' && $tokenValid) {
                 return new RedirectResponse($this->router->generate('dashboard'));
             }
             $allowed = true;
         } else {
             $allowed = $tokenValid;
         }
         if ($allowed) {
             $this->app->setRouteMatch($match);
             return $this->app->handle($request, $type, $catch);
         } else {
             $this->flash->warning('Sesi Anda telah habis atau Anda tidak berhak mengakses halaman ini, silakan login terlebih dahulu!');
             $response = $this->dispatcher->dispatch('User#login', []);
             $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
             return $response;
         }
     }
     $response = $this->dispatcher->dispatch('Home#error', ['message' => 'Halaman tidak ditemukan: ' . $route]);
     $response->setStatusCode(Response::HTTP_NOT_FOUND);
     return $response;
 }
开发者ID:raisoblast,项目名称:rakitan,代码行数:60,代码来源:JwtAuthentication.php

示例6: getController

 /**
  * {@inheritdoc}
  *
  * This method looks for a '_controller' request attribute that represents
  * the controller name (a string like ClassName::MethodName).
  */
 public function getController(Request $request)
 {
     if (!($controller = $request->attributes->get('_controller'))) {
         if (null !== $this->logger) {
             $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.');
         }
         return false;
     }
     if (is_array($controller)) {
         return $controller;
     }
     if (is_object($controller)) {
         if (method_exists($controller, '__invoke')) {
             return $controller;
         }
         throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request->getPathInfo()));
     }
     if (false === strpos($controller, ':')) {
         if (method_exists($controller, '__invoke')) {
             return $this->instantiateController($controller);
         } elseif (function_exists($controller)) {
             return $controller;
         }
     }
     $callable = $this->createController($controller);
     if (!is_callable($callable)) {
         throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $this->getControllerError($callable)));
     }
     return $callable;
 }
开发者ID:willianmano,项目名称:minicurso_phpconference2016,代码行数:36,代码来源:ControllerResolver.php

示例7: getController

 /**
  * {@inheritdoc}
  *
  * This method looks for a '_controller' request attribute that represents
  * the controller name (a string like ClassName::MethodName).
  *
  * @api
  */
 public function getController(Request $request)
 {
     $controller = $request->attributes->get('controller');
     if ($request->attributes->has('_sub_request') && $request->attributes->get('_sub_request')) {
         $controller = $request->attributes->get('_controller');
     }
     if (!$controller) {
         if (null !== $this->logger) {
             $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing');
         }
         return false;
     }
     if (is_array($controller)) {
         return $controller;
     }
     if (is_object($controller)) {
         if (method_exists($controller, '__invoke')) {
             return $controller;
         }
         throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request->getPathInfo()));
     }
     $prepare = $this->prepare($request->attributes->all());
     $request->attributes->set('_bundle', $prepare['bundle']);
     $request->attributes->set('_controller', strtolower($prepare['parts'][1]));
     $request->attributes->set('_action', strtolower($prepare['parts'][2]));
     $callable = array($this->instantiateController($prepare['controller']), $prepare['action']);
     $request->attributes->set('_callable', $callable);
     if (!is_callable($callable)) {
         throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', $controller, $request->getPathInfo()));
     }
     return $callable;
 }
开发者ID:kodazzi,项目名称:framework,代码行数:40,代码来源:ControllerResolver.php

示例8: getController

 /**
  * This method looks for a '_controller' request attribute that represents
  * the controller name (a string like ClassName::MethodName).
  *
  * @param Symfony\Component\HttpFoundation\Request $request The request we are handeling.
  * @throws InvalidArgumentException If the controller is not callable.
  * @return Symfony\Bundle\FrameworkBundle\Controller\Controller The controller.
  */
 public function getController(Request $request)
 {
     if (!($controller = $request->attributes->get('_controller'))) {
         return false;
     }
     if (is_array($controller)) {
         return $controller;
     }
     if (is_object($controller)) {
         if (method_exists($controller, '__invoke')) {
             return $controller;
         }
         throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request->getPathInfo()));
     }
     if (false === strpos($controller, ':')) {
         if (method_exists($controller, '__invoke')) {
             return $this->instantiateController($controller);
         } elseif (function_exists($controller)) {
             return $controller;
         }
     }
     $callable = $this->createController($controller);
     if (!is_callable($callable)) {
         throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', $controller, $request->getPathInfo()));
     }
     return $callable;
 }
开发者ID:skelpo,项目名称:framework,代码行数:35,代码来源:ManagementControllerResolver.php

示例9: getController

 public function getController(Request $request)
 {
     $controller = $request->attributes->get('_controller');
     if (!$controller) {
         throw new \Exception(sprintf('No _controller attribute set on Request with URI %s', $request->getPathInfo()));
     }
     $method = $request->attributes->get('_method');
     if (!$method) {
         throw new \Exception(sprintf('No _method attribute set on Request with URI %s', $request->getPathInfo()));
     }
     $method .= 'Action';
     //check if controller is defined as a service (it begins with
     //'::')
     $prefix = '::';
     if (substr($controller, 0, 2) === $prefix) {
         $service = substr($controller, 2);
         if (!$this->neptune->offsetExists($service)) {
             throw new \Exception(sprintf('Undefined controller service %s', $service));
         }
         $controller = $this->configureController($this->neptune[$service]);
         return array($controller, $method);
     }
     //if $controller begins with a backslash, assume a class name
     if (substr($controller, 0, 1) === '\\') {
         $class = $controller;
     } else {
         $class = $this->getControllerClass($controller);
     }
     if (!class_exists($class)) {
         throw new \Exception(sprintf('Controller not found: %s', $class));
     }
     $controller = $this->configureController(new $class());
     return array($controller, $method);
 }
开发者ID:glynnforrest,项目名称:neptune,代码行数:34,代码来源:ControllerResolver.php

示例10: getCandidates

 /**
  * Gets list of candidate Route objects for request
  *
  * @return array    List of Route objects
  */
 public function getCandidates()
 {
     $candidates = array();
     foreach ($this->collection->all() as $name => $route) {
         $specs = array();
         preg_match_all('/\\{\\w+\\}/', $route->getPath(), $matches);
         if (isset($matches[0])) {
             $specs = $matches[0];
         }
         foreach ($specs as $spec) {
             $param = substr($spec, 1, -1);
             $regexSpec = '\\' . $spec . '\\';
             $requirements = $route->getRequirements();
             if (isset($requirements[$param])) {
                 $route->setRegex(str_replace($spec, $this->getRegexOperand($requirements[$param]), $route->getRegex()));
             }
         }
         // Build regeular expression to match routes
         $route->setRegex('^' . '/' . ltrim(trim($route->getRegex()), '/') . '/?$');
         $route->setRegex('/' . str_replace('/', '\\/', $route->getRegex()) . '/');
         if (preg_match($route->getRegex(), $this->request->getPathInfo())) {
             // We have a match
             $candidates[] = $route;
         }
     }
     return $candidates;
 }
开发者ID:rybakdigital,项目名称:fapi,代码行数:32,代码来源:Matcher.php

示例11: getControllerMethod

 /**
  * @throws \Exception
  * @return array:
  */
 public function getControllerMethod($uri = null)
 {
     try {
         $result = false;
         $givenRoute = $uri == null ? $this->request->getPathInfo() : $uri;
         foreach ($this->routesCollection as $route) {
             if (!$result && $route['pattern'] == $givenRoute) {
                 $controller = $route['controller'];
                 $class = explode('::', $controller)[0];
                 $method = explode('::', $controller)[1];
                 if (!class_exists($class)) {
                     throw new \Exception('The route class doesn\'t exist!');
                 } else {
                     if (!method_exists($class, $method)) {
                         throw new \Exception('The route class\'s method doesn\'t exist!');
                     }
                 }
                 $this->logger->addInfo("Route controller method found: {$class} -> {$method}");
                 $result = array('class' => $class, 'method' => $method);
             }
         }
         if (!$result) {
             throw new \Exception('Route not found');
         } else {
             return $result;
         }
     } catch (\Exception $e) {
         $this->logger->addError('Error handling route: ' . $e->getMessage());
         throw new \Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
 }
开发者ID:seraphin,项目名称:aloja,代码行数:35,代码来源:Router.php

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

示例13: indexAction

 /**
  * Base fallback action.
  * Will be basically used for every legacy module.
  *
  * @return \eZ\Bundle\EzPublishLegacyBundle\LegacyResponse
  */
 public function indexAction()
 {
     $kernelClosure = $this->kernelClosure;
     /** @var \eZ\Publish\Core\MVC\Legacy\Kernel $kernel */
     $kernel = $kernelClosure();
     $legacyMode = $this->configResolver->getParameter('legacy_mode');
     //Empêche le front d'aller dans de l'eZ legacy
     if (!$legacyMode && substr($this->request->getPathInfo(), 0, 18) != '/content/download/') {
         throw new NotFoundHttpException('Adresse non trouvée');
     }
     $kernel->setUseExceptions(false);
     // Fix up legacy URI with current request since we can be in a sub-request here.
     $this->uriHelper->updateLegacyURI($this->request);
     // If we have a layout for legacy AND we're not in legacy mode, we ask the legacy kernel not to generate layout.
     if (isset($this->legacyLayout) && !$legacyMode) {
         $kernel->setUsePagelayout(false);
     }
     $result = $kernel->run();
     $kernel->setUseExceptions(true);
     if ($result instanceof ezpKernelRedirect) {
         return $this->legacyResponseManager->generateRedirectResponse($result);
     }
     $this->legacyHelper->loadDataFromModuleResult($result->getAttribute('module_result'));
     $response = $this->legacyResponseManager->generateResponseFromModuleResult($result);
     $this->legacyResponseManager->mapHeaders(headers_list(), $response);
     return $response;
 }
开发者ID:mclone,项目名称:ez5-project-bootstrap,代码行数:33,代码来源:LegacyKernelController.php

示例14: onRequest

 public function onRequest(Request $request)
 {
     $session = $request->getSession();
     list($id, $role) = $session->get('user', array(null, 'ROLE_ANONYMOUS'));
     if (null === $id && $request->cookies->has(Remember::REMEMBER_ME)) {
         if ($this->remember->check($request->cookies->get(Remember::REMEMBER_ME))) {
             list($id, $role) = $this->remember->getIt();
             $session->set('user', array($id, $role));
         }
     }
     $this->provider->setRole($role);
     if (!$this->provider->isAllowed($request->getPathInfo())) {
         throw new Exception\AccessDeniedException("Access denied to " . $request->getPathInfo());
     }
     if (null !== $id) {
         // Ban check
         $clientIp = $request->getClientIp();
         $ban = Ban::findActive($id, $clientIp);
         if (!empty($ban)) {
             throw new BannedException($ban[0], Response::HTTP_FORBIDDEN);
         }
         // User loading.
         $user = User::find($id);
         if (null !== $user) {
             $user->ip = $clientIp;
             $user->save();
             $this->provider->setUser($user);
             $this->provider->setAuthenticated(true);
         }
     }
 }
开发者ID:elfchat,项目名称:elfchat,代码行数:31,代码来源:SecurityMiddleware.php

示例15: isNodeActive

 public function isNodeActive(NavigationNode $node)
 {
     if ($this->request === null) {
         $this->request = $this->container->get('request');
     }
     $path = $this->request->getPathInfo();
     return $path === $node->getLink();
 }
开发者ID:roomthirteen,项目名称:Room13NavigationBundle,代码行数:8,代码来源:NavigationExtension.php


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