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


PHP ServerRequestInterface::getMethod方法代码示例

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


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

示例1: routeRequest

 /**
  * @param Request $request
  * @return Executable
  */
 public function routeRequest(Request $request, $fn404ErrorPage = null, $fn405ErrorPage = null)
 {
     $path = $request->getUri()->getPath();
     $routeInfo = $this->dispatcher->dispatch($request->getMethod(), $path);
     $dispatcherResult = $routeInfo[0];
     if ($dispatcherResult === Dispatcher::FOUND) {
         $handler = $routeInfo[1];
         $vars = $routeInfo[2];
         // Share the params once as parameters so they can
         // be injected by name
         $injectionParams = InjectionParams::fromParams($vars);
         // and then share them as a type
         $injectionParams->share(new RouteParams($vars));
         $executable = new Executable($handler, $injectionParams, null);
         return $executable;
     } else {
         if ($dispatcherResult === Dispatcher::METHOD_NOT_ALLOWED) {
             if ($fn405ErrorPage === null) {
                 $message = sprintf("Method '%s' not allowed for path '%s'", $request->getMethod(), $path);
                 throw new MethodNotAllowedException($message);
             }
             $executable = new Executable($fn405ErrorPage);
             return $executable;
         }
     }
     if ($fn404ErrorPage === null) {
         throw new RouteNotMatchedException("Route not matched for path {$path}");
     }
     $executable = new Executable($fn404ErrorPage);
     return $executable;
 }
开发者ID:danack,项目名称:tier,代码行数:35,代码来源:FastRouter.php

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

示例3: isValidVerifyTokenRequest

 /**
  * Check if the token match with the given verify token.
  * This is useful in the webhook setup process.
  *
  * @return bool
  */
 public function isValidVerifyTokenRequest()
 {
     if ($this->request->getMethod() !== 'GET') {
         return false;
     }
     $params = $this->request->getQueryParams();
     if (!isset($params['hub_verify_token'])) {
         return false;
     }
     return $params['hub_verify_token'] === $this->verifyToken;
 }
开发者ID:tgallice,项目名称:fb-messenger-sdk,代码行数:17,代码来源:WebhookRequestHandler.php

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

示例5: routeRequest

 /**
  * @param Request $request
  * @return Executable
  */
 public function routeRequest(Request $request)
 {
     $path = $request->getUri()->getPath();
     $routeInfo = $this->dispatcher->dispatch($request->getMethod(), $path);
     $dispatcherResult = $routeInfo[0];
     if ($dispatcherResult === \FastRoute\Dispatcher::FOUND) {
         $handler = $routeInfo[1];
         $vars = $routeInfo[2];
         $injectionParams = InjectionParams::fromParams($vars);
         $injectionParams->share(new \Tier\JigBridge\RouteInfo($vars));
         $executable = new Executable($handler, $injectionParams, null);
         $executable->setTierNumber(TierHTTPApp::TIER_GENERATE_BODY);
         return $executable;
     } else {
         if ($dispatcherResult === \FastRoute\Dispatcher::METHOD_NOT_ALLOWED) {
             //TODO - need to embed allowedMethods....theoretically.
             $executable = new Executable([$this, 'serve405ErrorPage']);
             $executable->setTierNumber(TierHTTPApp::TIER_GENERATE_BODY);
             return $executable;
         }
     }
     $executable = new Executable([$this, 'serve404ErrorPage']);
     $executable->setTierNumber(TierHTTPApp::TIER_GENERATE_BODY);
     return $executable;
 }
开发者ID:atawsports2,项目名称:Tier,代码行数:29,代码来源:Router.php

示例6: __invoke

 /**
  * Process an incoming request and/or response.
  *
  * Accepts a server-side request and a response instance, and does
  * something with them.
  *
  * If the response is not complete and/or further processing would not
  * interfere with the work done in the middleware, or if the middleware
  * wants to delegate to another process, it can use the `$out` callable
  * if present.
  *
  * If the middleware does not return a value, execution of the current
  * request is considered complete, and the response instance provided will
  * be considered the response to return.
  *
  * Alternately, the middleware may return a response instance.
  *
  * Often, middleware will `return $out();`, with the assumption that a
  * later middleware will return a response.
  *
  * @param Request $request
  * @param Response $response
  * @param null|callable $out
  * @return null|Response
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     if ($request->getMethod() === 'OPTIONS') {
         return $response;
     }
     return $this->dispatch($request, $response, $out);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:32,代码来源:AbstractRestAction.php

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

示例8: dispatch

 protected function dispatch(Request $request)
 {
     $method = $request->getMethod();
     if (!is_string($method)) {
         throw new ApiException(405, 'Unsupported HTTP method; must be a string, received ' . (is_object($method) ? get_class($method) : gettype($method)));
     }
     $method = strtoupper($method);
     /** @var Resource $resource */
     $resource = $this->getResource();
     if ('GET' === $method) {
         if ($id = $request->getAttribute(static::PK)) {
             $result = $resource->fetch($id, $request->getQueryParams());
         } else {
             $result = $resource->fetchAll($request->getQueryParams());
         }
     } elseif ('POST' === $method) {
         $result = $resource->create($request->getParsedBody());
     } elseif ('PUT' === $method) {
         $result = $resource->update($request->getAttribute(static::PK), $request->getParsedBody());
     } elseif ('PATCH' === $method) {
         $result = $resource->patch($request->getAttribute(static::PK), $request->getParsedBody());
     } elseif ('DELETE' === $method) {
         $result = $resource->delete($request->getAttribute(static::PK));
     } else {
         throw new ApiException(405, 'The ' . $method . ' method has not been defined');
     }
     return $result;
 }
开发者ID:maslennikov-yv,项目名称:rest,代码行数:28,代码来源:Action.php

示例9: __invoke

 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param array $methods
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $methods)
 {
     $this->isOptions = $request->getMethod() === 'OPTIONS';
     $this->allowed = $methods;
     $response = $response->withHeader('Allow', implode(', ', $this->allowed));
     return parent::__invoke($request, $response);
 }
开发者ID:amneale,项目名称:slim-api-handlers,代码行数:13,代码来源:NotAllowed.php

示例10: __invoke

 /**
  * Slim middleware entry point
  *
  * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
  * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
  * @param  callable                                 $next     Next middleware
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke($request, $response, $next)
 {
     $this->request = $request;
     $this->response = $response;
     $this->dispatch($request->getMethod(), $request->getUri());
     return $next($this->request, $this->response);
 }
开发者ID:juvenn,项目名称:php-sdk,代码行数:15,代码来源:SlimEngine.php

示例11: __invoke

 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable|null          $next
  *
  * @return HtmlResponse
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     /* @var \PSR7Session\Session\SessionInterface $session */
     $session = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE);
     // Generate csrf token
     if (!$session->get('csrf')) {
         $session->set('csrf', md5(uniqid(rand(), true)));
     }
     // Generate form and inject csrf token
     $form = FormFactory::fromHtml($this->template->render('app::contact-form', ['token' => $session->get('csrf')]));
     // Get request data
     $data = $request->getParsedBody() ?: [];
     if ($request->getMethod() !== 'POST') {
         // Display form
         return new HtmlResponse($this->template->render('app::contact', ['form' => $form->asString()]), 200);
     }
     // Validate form
     $validationResult = $form->validate($data);
     if (!$validationResult->isValid()) {
         // Display form and inject error messages and submitted values
         return new HtmlResponse($this->template->render('app::contact', ['form' => $form->asString($validationResult)]), 200);
     }
     // Create the message
     $message = Swift_Message::newInstance()->setFrom($this->config['from'])->setReplyTo($data['email'], $data['name'])->setTo($this->config['to'])->setSubject('[xtreamwayz-contact] ' . $data['subject'])->setBody($data['body']);
     if ($this->config['transport']['debug'] !== true) {
         $this->mailer->send($message);
     }
     // Display thank you page
     return new HtmlResponse($this->template->render('app::contact-thank-you'), 200);
 }
开发者ID:jkhaled,项目名称:xtreamwayz.com,代码行数:37,代码来源:ContactAction.php

示例12: _extractDataPSR7

 private function _extractDataPSR7(ServerRequestInterface $request = null, $name = '')
 {
     $method = $request->getMethod();
     $queryParams = $request->getQueryParams();
     if ('GET' === $method) {
         if ('' === $name) {
             return $queryParams;
         }
         // Don't submit GET requests if the form's name does not exist
         // in the request
         if (!isset($queryParams[$name])) {
             return;
         }
         return $queryParams[$name];
     }
     $serverParams = $request->getServerParams();
     $uploadedFiles = $request->getUploadedFiles();
     if ('' === $name) {
         return $this->mergeParamsAndUploadedFiles($serverParams, $uploadedFiles);
     }
     if (isset($serverParams[$name]) || isset($uploadedFiles[$name])) {
         $default = null;
         $params = isset($serverParams[$name]) ? $serverParams[$name] : null;
         $files = isset($uploadedFiles[$name]) ? $uploadedFiles[$name] : null;
         return $this->mergeParamsAndUploadedFiles($params, $files);
     }
     // Don't submit the form if it is not present in the request
     return;
 }
开发者ID:pugx,项目名称:bindto,代码行数:29,代码来源:PSR7RequestTrait.php

示例13: index

 /**
  * Index action shows install tool / step installer or redirect to action to enable install tool
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @return ResponseInterface
  */
 public function index(ServerRequestInterface $request, ResponseInterface $response)
 {
     /** @var EnableFileService $enableFileService */
     $enableFileService = GeneralUtility::makeInstance(EnableFileService::class);
     /** @var AbstractFormProtection $formProtection */
     $formProtection = FormProtectionFactory::get();
     if ($enableFileService->checkInstallToolEnableFile()) {
         // Install tool is open and valid, redirect to it
         $response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
     } elseif ($request->getMethod() === 'POST' && $request->getParsedBody()['action'] === 'enableInstallTool') {
         // Request to open the install tool
         $installToolEnableToken = $request->getParsedBody()['installToolEnableToken'];
         if (!$formProtection->validateToken($installToolEnableToken, 'installTool')) {
             throw new \RuntimeException('Given form token was not valid', 1369161225);
         }
         $enableFileService->createInstallToolEnableFile();
         // Install tool is open and valid, redirect to it
         $response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
     } else {
         // Show the "create enable install tool" button
         /** @var StandaloneView $view */
         $view = GeneralUtility::makeInstance(StandaloneView::class);
         $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/Templates/BackendModule/ShowEnableInstallToolButton.html'));
         $token = $formProtection->generateToken('installTool');
         $view->assign('installToolEnableToken', $token);
         /** @var ModuleTemplate $moduleTemplate */
         $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
         $cssFile = 'EXT:install/Resources/Public/Css/BackendModule/ShowEnableInstallToolButton.css';
         $cssFile = GeneralUtility::getFileAbsFileName($cssFile);
         $moduleTemplate->getPageRenderer()->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
         $moduleTemplate->setContent($view->render());
         $response->getBody()->write($moduleTemplate->renderContent());
     }
     return $response;
 }
开发者ID:TYPO3Incubator,项目名称:TYPO3.CMS,代码行数:42,代码来源:BackendModuleController.php

示例14: match

 /**
  * {@inheritdoc}
  */
 public function match(ServerRequestInterface $request) : RoutingResult
 {
     $requestPath = $request->getUri()->getPath();
     $this->logger->debug(sprintf('Analysing request path "%s"', $requestPath));
     $candidates = [];
     /** @var array $routeDefinition */
     foreach ($this->routes as $routeDefinition) {
         $route = $routeDefinition['route'];
         $identifier = $this->getRouteIdentifier($route);
         $this->logger->debug(sprintf('Trying to match requested path to route "%s"', $identifier));
         $urlVars = [];
         if (preg_match_all($routeDefinition['pathMatcher'], $requestPath, $urlVars)) {
             $method = strtoupper(trim($request->getMethod()));
             if (!in_array($method, $route->getMethods())) {
                 $candidates[] = ['route' => $route, 'failure' => RoutingResult::FAILED_METHOD_NOT_ALLOWED];
                 continue;
             }
             // remove all elements which should not be set in the request,
             // e.g. the matching url string as well as all numeric items
             $params = $this->mapParams($urlVars);
             if (!$this->matchParams($route, $params)) {
                 $candidates[] = ['route' => $route, 'failure' => RoutingResult::FAILED_BAD_REQUEST];
                 continue;
             }
             $this->logger->debug(sprintf('Route "%s" matches. Applying its target...', $identifier));
             return RoutingResult::forSuccess($route, $params);
         }
     }
     $this->logger->debug('No matching route found.');
     if (count($candidates)) {
         $candidate = $candidates[0];
         return RoutingResult::forFailure($candidate['failure'], $candidate['route']);
     }
     return RoutingResult::forFailure(RoutingResult::FAILED_NOT_FOUND);
 }
开发者ID:bitexpert,项目名称:pathfinder,代码行数:38,代码来源:Psr7Router.php

示例15: __invoke

 /**
  * Invoke "Maintenance" Handler
  *
  * @param  ServerRequestInterface $request  The most recent Request object.
  * @param  ResponseInterface      $response The most recent Response object.
  * @param  string[]               $methods  Allowed HTTP methods.
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, array $methods)
 {
     $this->setMethods($methods);
     if ($request->getMethod() === 'OPTIONS') {
         $contentType = 'text/plain';
         $output = $this->renderPlainOutput();
     } else {
         $contentType = $this->determineContentType($request);
         switch ($contentType) {
             case 'application/json':
                 $output = $this->renderJsonOutput();
                 break;
             case 'text/xml':
             case 'application/xml':
                 $output = $this->renderXmlOutput();
                 break;
             case 'text/html':
             default:
                 $output = $this->renderHtmlOutput();
                 break;
         }
     }
     $body = new Body(fopen('php://temp', 'r+'));
     $body->write($output);
     return $response->withStatus(503)->withHeader('Content-type', $contentType)->withBody($body);
 }
开发者ID:locomotivemtl,项目名称:charcoal-app,代码行数:34,代码来源:Shutdown.php


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