本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getRequestTarget方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getRequestTarget方法的具体用法?PHP ServerRequestInterface::getRequestTarget怎么用?PHP ServerRequestInterface::getRequestTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getRequestTarget方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
{
// Use only the path for routing.
$requestTarget = parse_url($request->getRequestTarget(), PHP_URL_PATH);
$route = $this->getStaticRoute($requestTarget);
if ($route) {
return $route($request, $response, $next);
}
$route = $this->getPrefixRoute($requestTarget);
if ($route) {
return $route($request, $response, $next);
}
// Try each of the routes.
foreach ($this->patternRoutes as $route) {
if ($route->matchesRequestTarget($requestTarget)) {
$pathVariables = $route->getPathVariables();
if ($this->pathVariablesAttributeName) {
$request = $request->withAttribute($this->pathVariablesAttributeName, $pathVariables);
} else {
foreach ($pathVariables as $name => $value) {
$request = $request->withAttribute($name, $value);
}
}
return $route($request, $response, $next);
}
}
// If no route exists, set the status code of the response to 404 and
// return the response without propagating.
return $response->withStatus(404);
}
示例2: __invoke
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
$tokenHeader = $request->getHeader('X-Auth-Token');
if (count($tokenHeader) > 0) {
$tokenHeaderValue = $tokenHeader[0];
} else {
$tokenHeaderValue = null;
}
$data = array('requestMethod' => $request->getMethod(), 'requestUri' => $request->getRequestTarget(), 'queryParams' => $request->getQueryParams(), 'formParams' => $request->getParsedBody(), 'rawBody' => (string) $request->getBody(), 'headers' => $request->getHeaders(), 'X-Auth-Token' => $tokenHeaderValue);
return new JsonResponse($data);
}
示例3: __construct
/**
* Construct action request.
*
* @param \Psr\Http\Message\ServerRequestInterface $request Request to wrap.
*/
public function __construct(\Psr\Http\Message\ServerRequestInterface $request)
{
parent::__construct($request->getBody());
foreach ($request->getHeaders() as $name => $value) {
$this->setHeader($name, $value);
}
$this->protocolVersion = $request->getProtocolVersion();
$this->method = $request->getMethod();
$this->requestTarget = $request->getRequestTarget();
$this->uri = $request->getUri();
$this->attributes = $request->getAttributes();
$this->cookies = $request->getCookieParams();
$this->data = $request->getParsedBody();
$this->query = $request->getQueryParams();
$this->server = $request->getServerParams();
$this->files = $request->getUploadedFiles();
if (isset($this->server['SCRIPT_NAME'])) {
$this->attributes['basePath'] = dirname($this->server['SCRIPT_NAME']);
$this->attributes['scriptName'] = basename($this->server['SCRIPT_NAME']);
} else {
$this->attributes['basePath'] = '/';
$this->attributes['scriptName'] = 'index.php';
}
if (!isset($this->attributes['path'])) {
$this->attributes['path'] = self::findPath($this);
}
if (!isset($this->attributes['rewrite'])) {
$this->attributes['rewrite'] = false;
}
if (!isset($this->attributes['accepts'])) {
$this->attributes['accepts'] = [];
if (isset($this->server['HTTP_ACCEPT'])) {
$contentTypes = explode(',', $this->server['HTTP_ACCEPT']);
foreach ($contentTypes as $contentType) {
$contentType = explode(';', $contentType);
$this->attributes['accepts'][] = trim(strtolower($contentType[0]));
}
}
}
if (!isset($this->attributes['encodings'])) {
$this->attributes['encodings'] = [];
if (isset($this->server['HTTP_ACCEPT_ENCODING'])) {
$acceptEncodings = explode(',', $this->server['HTTP_ACCEPT_ENCODING']);
foreach ($acceptEncodings as $encoding) {
$this->attributes['encodings'][] = trim(strtolower($encoding));
}
}
}
}
示例4: match
function match($pattern, ServerRequestInterface $request, ServerRequestInterface &$modifiedRequest)
{
$modifiedRequest = $request;
$path = $request->getRequestTarget();
if ($path == '.') {
$path = '';
}
if (!preg_match(self::SYNTAX, $pattern, $m)) {
throw new ConfigException(sprintf("Invalid route pattern matching expression: '<kbd>%s</kbd>'", $pattern));
}
array_push($m, '', '');
list($all, $methods, $pathPattern) = $m;
if ($methods && !in_array($request->getMethod(), explode('|', rtrim($methods)))) {
return false;
}
// The asterisk matches any path.
if ($pathPattern == '*') {
return true;
}
// The plus matches any non-empty path.
if ($pathPattern == '+') {
return !!strlen($path);
}
// @parameters never match the empty path (which is encoded as a single dot)
$compiledPattern = preg_replace(['/(?<=[^\\*\\.])$/', '/\\*$/', '/\\.\\.\\.$/', '/\\.$/', '/@(\\w+)/', '[\\[\\]\\{\\}\\(\\)\\.\\?]'], ['(?<_next>$)', '(?<_next>.*)', '(?<_next>)', '(?<_next>$)', '(?<$1>(?=(?:$|[^\\.]))[^/]*)', '\\$0'], $pathPattern);
if (!preg_match("#^{$compiledPattern}#", $path, $m2, PREG_OFFSET_CAPTURE)) {
return false;
}
$newPath = substr($path, $m2['_next'][1] + 1);
if ($path != $newPath) {
$request = $request->withRequestTarget($newPath === false ? '' : $newPath);
}
foreach ($m2 as $k => $v) {
if (is_string($k) && $k[0] != '_') {
// exclude reserved _next key
$request = $request->withAttribute('@' . $k, urldecode($v[0]));
}
}
$modifiedRequest = $request;
return true;
}
示例5: getRequestTarget
/**
* {@inheritdoc}
*/
public function getRequestTarget()
{
return $this->wrapped->getRequestTarget();
}
示例6: getRequestTarget
/**
* {@inheritDoc}
*/
public function getRequestTarget()
{
return $this->psrRequest->getRequestTarget();
}
示例7: handleNotAllowed
/**
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param string[] $methods
*
* @return ResponseInterface
*/
public function handleNotAllowed(ServerRequestInterface $request, ResponseInterface $response, array $methods)
{
if ($level = $this->shouldLog('not-allowed')) {
$message = sprintf('%s on %s', $request->getMethod(), $request->getRequestTarget());
$this->logEvent('not-allowed', $message, $level);
}
return $this->handler->handleNotAllowed($request, $response, $methods);
}
示例8: __construct
/**
* Constructor.
*
* @param string $method Method that were not allowed.
*/
public function __construct(ServerRequestInterface $request)
{
parent::__construct("Bad request with '{$request->getMethod()}' method, at '{$request->getRequestTarget()}' location.", 400, "It seems that your request is malformed in some way." . " Try again or contact server administrator for more info.");
}
示例9: getMessage
/**
* Generate the error log message.
*
* @param \Psr\Http\Message\ServerRequestInterface $request The current request.
* @param \Exception $exception The exception to log a message for.
* @return string Error message
*/
protected function getMessage($request, $exception)
{
$message = sprintf("[%s] %s", get_class($exception), $exception->getMessage());
$debug = Configure::read('debug');
if ($debug && method_exists($exception, 'getAttributes')) {
$attributes = $exception->getAttributes();
if ($attributes) {
$message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
}
}
$message .= "\nRequest URL: " . $request->getRequestTarget();
$referer = $request->getHeaderLine('Referer');
if ($referer) {
$message .= "\nReferer URL: " . $referer;
}
if ($this->config('trace')) {
$message .= "\nStack Trace:\n" . $exception->getTraceAsString() . "\n\n";
}
return $message;
}
示例10: __construct
/**
* Constructor.
*
* @param string $path Path that were not found.
*/
public function __construct(ServerRequestInterface $request)
{
parent::__construct("Route for '{$request->getRequestTarget()}' is not found.", 404, "The requested page is not found on this server." . " Please check the URL for typos or contact server administrator for more info.");
}
示例11: logRequest
/**
* @param ServerRequestInterface $r
* @param $title
*/
private function logRequest($r, $title, $forceShow = false)
{
/** @var ServerRequestInterface $current */
$current = $this->currentRequestMutator->get();
$showAll = !$this->currentRequestMutator->get() || $forceShow;
$icon = $showAll ? '' : '<sup>*</sup>';
if ($showAll || $r->getHeaders() != $current->getHeaders()) {
$out['Headers' . $icon] = map($r->getHeaders(), function ($v) {
return implode('<br>', $v);
});
}
if ($showAll || $r->getAttributes() != $current->getAttributes()) {
$out['Attributes' . $icon] = $r->getAttributes();
}
if ($showAll || $r->getRequestTarget() != $current->getRequestTarget()) {
$out['Request target' . $icon] = $r->getRequestTarget();
}
if ($showAll || $r->getBody()->getSize() != self::$currentRequestSize) {
$out['Size' . $icon] = $r->getBody()->getSize();
}
$this->routingLogger->write("<div class='indent'>")->simpleTable($out, $title)->write('</div>');
}
示例12: __construct
/**
* Constructor.
*
* @param string $method Method that were not allowed.
*/
public function __construct(ServerRequestInterface $request)
{
parent::__construct("Method '{$request->getMethod()}' is not allowed at the '{$request->getRequestTarget()}' location.", 405, "A request method is not supported for the requested page." . " Try again or contact server administrator for more info.");
}
示例13: getRequestPlaceholders
/**
* {@inheritdoc}
*/
public function getRequestPlaceholders(ServerRequestInterface $request)
{
$placeholders = $this->getPlaceholders($request->getRequestTarget());
return $request->withAttributes($placeholders);
}