Skip to content
Snippets Groups Projects
Commit 1371b045 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[BUGFIX] Throw dedicated exception for invalid request URL on CLI

Usage of ServerRequestFactory::fromGlobals() on
CLI is discouraged as the request url, used to
create the request is invalid, except the
$_SERVER variable is adjusted beforehand.

To properly inform the developer, a dedicated
exception is now being thrown, if in CLI context.

Resolves: #102533
Releases: main, 12.4
Change-Id: Ie84fdf9c0555eeeaf5438a2ed29acabbe2755965
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81978


Tested-by: default avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarOliver Bartsch <bo@cedev.de>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 612937b2
Branches
Tags
No related merge requests found
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Http;
/**
* Exception is thrown in case an invalid request url is used in CLI context
*
* @internal
*/
class InvalidRequestUrlOnCliException extends \InvalidArgumentException {}
......@@ -21,6 +21,7 @@ use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -61,7 +62,17 @@ class ServerRequestFactory implements ServerRequestFactoryInterface
$headers = static::prepareHeaders($serverParameters);
$method = $serverParameters['REQUEST_METHOD'] ?? 'GET';
$uri = new Uri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
try {
$uri = new Uri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
} catch (\InvalidArgumentException $e) {
if (Environment::isCli()) {
throw new InvalidRequestUrlOnCliException(
'Usage of ' . __METHOD__ . ' on CLI is discouraged. In case you rely on the method, you have to fake a valid request URL using $_SERVER.',
1701105725
);
}
throw $e;
}
$request = new ServerRequest(
$uri,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment