从 TYPO3 中的全局变量创建请求对象

Create request object from globals in TYPO3

在 Symfony 中你可以这样做:

use Symfony\Component\HttpFoundation\Request;

$request = Request::createFromGlobals();

我想知道TYPO3中有没有类似的东西。

谢谢。

看到这个变化https://review.typo3.org/#/c/40355/

[FEATURE] Introduce Request/Response based on PSR-7

The PSR-7 standard is adapted into the TYPO3 Bootstrap with a backwards-compatible layer.

The PSR-7 implementation brings several new classes: * Message (the base for Requests and Responses) * Request (for Requests made within PHP) * ServerRequest and a factory based on the current system environment * Response * Uri (a unified API for fetching several parts of an URI)

At any TYPO3 request a new ServerRequest object is created inside the Bootstrap and handed over to the RequestHandler which can then use this object for checking certain GET and POST variables instead of using GeneralUtility.

The proper call (usually a Controller) creates a Response object that is handed back to the RequestHandler + Bootstrap. The TYPO3 Bootstrap will output anything related in the shutdown() method.

An example is shown with the LoginController and currently hard-wired as no proper routing/dispatching is there yet.

Currently this is an internal API as the rest (Dispatch/Router and Controller API) will follow once the base is in.

Please note that the PSR-7 standard works with Value Objects meaning that it is not possible to modify any object but instead new objects will be created for Message, ServerRequest and Response if modified.

The next steps are: * Integrate proper Routing + Dispatching for Backend Routes to register new BE requests * Migrate all AJAX Calls to use the new API and request / response handling * Introduce a common Base Controller for all regular BE requests which is based on Request/Response and works as a replacement for sc_base * Then: proper documentation for the whole bootstrap / dispatch + routing / controller logic * Integrate symfony console app into the CLI Bootstrap as alternative for Request/Response * Refactor TSFE to use Response / Request objects properly * Refactor redirects logic to use Response objects

请参阅 EXT:backend/Classes/Http/ 和 EXT:frontend/Classes/Http 中的 RequestHandler 以了解核心中的用法