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


PHP ServerRequestInterface::getUri方法代码示例

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


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

示例1: __invoke

 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if ($request->getUri()->getScheme() != 'https' && $request->getUri()->getHost() != 'localhost') {
         throw new SecurityException('HTTPS not used');
     }
     return $next($request, $response);
 }
开发者ID:asylgrp,项目名称:workbench,代码行数:7,代码来源:HttpsEnforcer.php

示例2: __invoke

 /**
  * Invocation
  *
  * Register routes container and request attributes
  *
  * @param ServerRequestInterface $request Request
  * @param ResponseInterface $response Response
  * @param TornadoHttp $next Next Middleware - TornadoHttp container
  * @return ResponseInterface
  * @throws HttpMethodNotAllowedException
  * @throws HttpNotFoundException
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, TornadoHttp $next)
 {
     /** @var \FastRoute\Dispatcher\GroupCountBased $dispatcher */
     $dispatcher = FastRoute\simpleDispatcher(function (RouteCollector $routeCollector) {
         foreach ($this->routes as $key => $route) {
             $routeCollector->addRoute($route['methods'], $route['path'], $key);
         }
     });
     $method = $request->getMethod();
     $uri = rawurldecode(parse_url($request->getUri(), \PHP_URL_PATH));
     $route = $dispatcher->dispatch($method, $uri);
     $handler = null;
     $vars = null;
     switch ($route[0]) {
         case Dispatcher::NOT_FOUND:
             throw new HttpNotFoundException('Inexistent route for the url ' . $request->getUri());
         case Dispatcher::METHOD_NOT_ALLOWED:
             throw new HttpMethodNotAllowedException('Method not allowed');
         case Dispatcher::FOUND:
             $handler = $route[1];
             $vars = $route[2];
             break;
     }
     $request = $request->withAttribute(Router::REGISTER_KEY, $handler);
     foreach ($vars as $name => $value) {
         $request = $request->withAttribute($name, $value);
     }
     return $next($request, $response);
 }
开发者ID:danielspk,项目名称:tornadohttpskeletonapplication,代码行数:41,代码来源:Resolver.php

示例3: dispatch

 /**
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 function dispatch(Request $request, Response $response)
 {
     $path = preg_replace('{/{2,}}', '/', $request->getUri()->getPath());
     $path = $request->getUri()->getQuery();
     // TODO:TEST:DEBUG
     $path = trim($path, '/');
     $path = urldecode($path);
     // TODO: debug temporaire
     foreach ($this->collection as $route) {
         // Pattern
         if (!preg_match('{^' . $route->getPattern() . '$}i', $path, $attributes)) {
             continue;
         }
         // Options
         foreach ($route->getOptions() as $key => $value) {
             switch ($key) {
                 case 'method':
                     if (!in_array($request->getMethod(), explode('|', $value))) {
                         continue 3;
                     }
             }
         }
         // Attributes
         foreach (array_filter($attributes, 'is_string', ARRAY_FILTER_USE_KEY) as $ak => $av) {
             $request = $request->withAttribute($ak, $av);
         }
         //return call_user_func($this->callable, $request, ...array_filter($attributes, 'is_int', ARRAY_FILTER_USE_KEY)); // TODO: delete key 0
         return $this->runner($request, $response, ...$route->getCallables());
     }
     // Error 404
     return $response;
 }
开发者ID:assouan,项目名称:routing,代码行数:37,代码来源:Router.php

示例4: getRoute

 protected function getRoute($indexKey, ServerRequestInterface $request)
 {
     $validRoutes = [];
     foreach ($this->routesIndex[$indexKey] as $route) {
         $scheme = $route->getScheme();
         if (!empty($scheme) && $request->getUri()->getScheme() !== $scheme) {
             continue;
         }
         $host = $route->getHost();
         if (!empty($host) && $request->getUri()->getHost() !== $host) {
             continue;
         }
         foreach ($route->getGroup()->getConditions() as $condition) {
             if (!$condition->verify($request)) {
                 continue 2;
             }
         }
         foreach ($route->getConditions() as $condition) {
             if (!$condition->verify($request)) {
                 continue 2;
             }
         }
         $validRoutes[] = $route;
     }
     if (empty($validRoutes)) {
         throw new RouteConditionFailedException();
     } else {
         if (count($validRoutes) > 1) {
             throw new ManyRoutesFoundException();
         }
     }
     return reset($validRoutes);
 }
开发者ID:laasti,项目名称:directions,代码行数:33,代码来源:Locator.php

示例5: get

 /**
  * {@inheritdoc}
  */
 public function get(array $fileInfo, array $data = []) : string
 {
     $engine = $this->getLoader();
     if ($this->request !== null) {
         // Set uri extensions
         $engine->loadExtension(new URI($this->request->getUri()->getPath()));
     }
     // Set asset extensions
     $engine->loadExtension(new Asset($this->config['engine']['plates']['asset'] ?? null));
     // Get all extensions
     if (!empty($this->availableExtensions)) {
         foreach ($this->availableExtensions as $extension) {
             $engine->loadExtension(is_object($extension) ? $extension : new $extension());
         }
     }
     if (!$engine->exists($fileInfo['name'])) {
         throw new Exception('Template "' . $fileInfo['name'] . '" dont exist!');
     }
     // Creat a new template
     $template = new Template($engine, $fileInfo['name']);
     // We'll evaluate the contents of the view inside a try/catch block so we can
     // flush out any stray output that might get out before an error occurs or
     // an exception is thrown. This prevents any partial views from leaking.
     ob_start();
     try {
         return $template->render($data);
     } catch (Throwable $exception) {
         $this->handleViewException($exception);
     }
 }
开发者ID:narrowspark,项目名称:framework,代码行数:33,代码来源:Plates.php

示例6: addLanguage

 public function addLanguage(ServerRequestInterface $request, $language)
 {
     $path = $request->getUri()->getPath();
     if ($language !== $this->environment->getDefaultLanguage()) {
         $path = '/' . $language . ($path === '/' ? '' : $path);
     }
     return $request->withUri($request->getUri()->withPath($path));
 }
开发者ID:gobline,项目名称:environment,代码行数:8,代码来源:LanguageSubdirectoryResolver.php

示例7: __invoke

 /**
  * Invocation
  *
  * @param ServerRequestInterface $request Request
  * @param ResponseInterface $response Response
  * @param callable $next Next Middleware
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if ($this->basePath !== '/') {
         $uri = $request->getUri();
         $path = '/' . preg_replace('/^' . str_replace('/', '\\/', $this->basePath) . '/', '', $request->getUri()->getPath());
         $request = $request->withUri($uri->withPath($path));
     }
     return $next($request, $response);
 }
开发者ID:danielspk,项目名称:tornadohttpskeletonapplication,代码行数:17,代码来源:BasePath.php

示例8: toZend

 /**
  * Convert a PSR-7 ServerRequest to a Zend\Http server-side request.
  *
  * @param ServerRequestInterface $psr7Request
  * @param bool $shallow Whether or not to convert without body/file
  *     parameters; defaults to false, meaning a fully populated request
  *     is returned.
  * @return Zend\Request
  */
 public static function toZend(ServerRequestInterface $psr7Request, $shallow = false)
 {
     if ($shallow) {
         return new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), [], [], $psr7Request->getServerParams());
     }
     $zendRequest = new Zend\Request($psr7Request->getMethod(), $psr7Request->getUri(), $psr7Request->getHeaders(), $psr7Request->getCookieParams(), $psr7Request->getQueryParams(), $psr7Request->getParsedBody() ?: [], self::convertUploadedFiles($psr7Request->getUploadedFiles()), $psr7Request->getServerParams());
     $zendRequest->setContent($psr7Request->getBody());
     return $zendRequest;
 }
开发者ID:MidnightDesign,项目名称:zend-psr7bridge,代码行数:18,代码来源:Psr7ServerRequest.php

示例9: __invoke

 /**
  * Invoke middleware
  * 
  * @param ServerRequestInterface $request  request
  * @param ResponseInterface      $response response
  * @param callable               $next     callable
  * 
  * @return object ResponseInterface
  */
 public function __invoke(Request $request, Response $response, callable $next = null)
 {
     $err = null;
     if ($request->isSecure() == false) {
         $path = $request->getUri()->getPath();
         $host = $request->getUri()->getHost();
         return $response->redirect('https://' . $host . $path);
     }
     return $next($request, $response, $err);
 }
开发者ID:obullo,项目名称:http-middlewares,代码行数:19,代码来源:Https.php

示例10: set

 /**
  * Schedule new cookie. Cookie will be send while dispatching request.
  *
  * Domain, path, and secure values can be left in null state, in this case cookie manager will
  * populate them automatically.
  *
  * @link http://php.net/manual/en/function.setcookie.php
  * @param string $name     The name of the cookie.
  * @param string $value    The value of the cookie. This value is stored on the clients
  *                         computer; do not store sensitive information.
  * @param int    $lifetime Cookie lifetime. This value specified in seconds and declares period
  *                         of time in which cookie will expire relatively to current time()
  *                         value.
  * @param string $path     The path on the server in which the cookie will be available on.
  *                         If set to '/', the cookie will be available within the entire
  *                         domain.
  *                         If set to '/foo/', the cookie will only be available within the
  *                         /foo/
  *                         directory and all sub-directories such as /foo/bar/ of domain. The
  *                         default value is the current directory that the cookie is being set
  *                         in.
  * @param string $domain   The domain that the cookie is available. To make the cookie
  *                         available
  *                         on all subdomains of example.com then you'd set it to
  *                         '.example.com'.
  *                         The . is not required but makes it compatible with more browsers.
  *                         Setting it to www.example.com will make the cookie only available in
  *                         the www subdomain. Refer to tail matching in the spec for details.
  * @param bool   $secure   Indicates that the cookie should only be transmitted over a secure
  *                         HTTPS connection from the client. When set to true, the cookie will
  *                         only be set if a secure connection exists. On the server-side, it's
  *                         on the programmer to send this kind of cookie only on secure
  *                         connection (e.g. with respect to $_SERVER["HTTPS"]).
  * @param bool   $httpOnly When true the cookie will be made accessible only through the HTTP
  *                         protocol. This means that the cookie won't be accessible by
  *                         scripting
  *                         languages, such as JavaScript. This setting can effectively help to
  *                         reduce identity theft through XSS attacks (although it is not
  *                         supported by all browsers).
  * @return $this
  */
 public function set($name, $value = null, $lifetime = null, $path = null, $domain = null, $secure = null, $httpOnly = true)
 {
     if (is_null($domain)) {
         $domain = $this->httpConfig->cookiesDomain($this->request->getUri());
     }
     if (is_null($secure)) {
         $secure = $this->request->getMethod() == 'https';
     }
     return $this->schedule(new Cookie($name, $value, $lifetime, $path, $domain, $secure, $httpOnly));
 }
开发者ID:vvval,项目名称:spiral,代码行数:51,代码来源:CookieQueue.php

示例11: getRoutes

 /**
  * @inheritDoc
  */
 public function getRoutes() : array
 {
     $routes = [];
     foreach ($this->routes->getRoutes() as $route) {
         if ((!$route->getHost() || $route->getHost() === $this->request->getUri()->getHost()) && (!$route->getScheme() || $route->getScheme() === $this->request->getUri()->getScheme())) {
             $routes[] = $route;
         }
     }
     return $routes;
 }
开发者ID:abava,项目名称:routing,代码行数:13,代码来源:RequestRouteCollection.php

示例12: guess

 /**
  * Guesses the base URI of the application.
  *
  * @param  Psr\Http\Message\ServerRequestInterface $request
  * @return Psr\Http\Message\ServerRequestInterface
  */
 public static function guess(\Psr\Http\Message\ServerRequestInterface $request)
 {
     $server = $request->getServerParams();
     $basename = basename($server['SCRIPT_FILENAME']);
     $position = strpos($server['SCRIPT_NAME'], $basename) - 1;
     $rootUri = substr($server['SCRIPT_NAME'], 0, $position);
     $oldPath = $request->getUri()->getPath();
     $newPath = str_replace($rootUri, '', $oldPath);
     $uri = $request->getUri()->withPath($newPath);
     return $request->withUri($uri);
 }
开发者ID:rougin,项目名称:slytherin,代码行数:17,代码来源:BaseUriGuesser.php

示例13: resolves

 /**
  * @return bool
  */
 public function resolves()
 {
     if (preg_match($this->compileRegex(), $this->request->getUri()->getPath(), $parameters) > 0) {
         $params = [];
         foreach ($parameters as $key => $value) {
             if (!is_int($key)) {
                 $params[$key] = $value;
             }
         }
         return $params;
     }
     return false;
 }
开发者ID:fyuze,项目名称:framework,代码行数:16,代码来源:Matcher.php

示例14: __invoke

 /**
  * @throws \WoohooLabs\Harmony\Exception\MethodNotAllowed
  * @throws \WoohooLabs\Harmony\Exception\RouteNotFound
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) : ResponseInterface
 {
     $route = $this->fastRoute->dispatch($request->getMethod(), $request->getUri()->getPath());
     if ($route[0] === Dispatcher::NOT_FOUND) {
         throw new RouteNotFound($request->getUri()->getPath());
     }
     if ($route[0] === Dispatcher::METHOD_NOT_ALLOWED) {
         throw new MethodNotAllowed($request->getMethod());
     }
     foreach ($route[2] as $name => $value) {
         $request = $request->withAttribute($name, $value);
     }
     $request = $request->withAttribute($this->actionAttributeName, $route[1]);
     return $next($request, $response);
 }
开发者ID:woohoolabs,项目名称:harmony,代码行数:19,代码来源:FastRouteMiddleware.php

示例15: match

 public function match(ServerRequestInterface $request)
 {
     if (!$this->startsWith($request->getUri()->getPath(), $this->routePath)) {
         return false;
     }
     $templateFile = trim(substr($request->getUri()->getPath(), strlen($this->routePath)), '/');
     if (!$templateFile) {
         $templateFile = 'index';
     }
     $template = $this->templateDir . $templateFile . $this->templateExtension;
     if (!is_file($template)) {
         throw new NoMatchingRouteException('No matching route for request "' . $request->getUri()->getPath() . '"');
     }
     return new RouteData($this->name, array_merge(['template' => $templateFile, '_view' => ['text/html' => $template]], $this->values), $this->handler);
 }
开发者ID:gobline,项目名称:route-template,代码行数:15,代码来源:TemplateRoute.php


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