Skip to content

Commit

Permalink
[TASK] Unify Backend Request Handlers
Browse files Browse the repository at this point in the history
Due to the middleware PSR-15 concept, the AjaxRequestHandler can
be migrated easily into the generic Backend RequestHandler.

Thus, the AjaxRequestHandler is marked as deprecated.

Resolves: #83853
Releases: master
Change-Id: If7823e2bc30bdea5839a0f07e943971eeeec00c3
Reviewed-on: https://review.typo3.org/55662
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
  • Loading branch information
bmack authored and susannemoog committed Feb 12, 2018
1 parent 07e566f commit 1ea84aa
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
6 changes: 6 additions & 0 deletions typo3/sysext/backend/Classes/Http/AjaxRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* Main entry point for AJAX calls in the TYPO3 Backend. Based on ?route=/ajax/* of the outside application.
*
* AJAX Requests are typically registered within EXT:myext/Configuration/Backend/AjaxRoutes.php
*
* @deprecated since TYPO3 v9.2, will be removed in TYPO3 v10
*/
class AjaxRequestHandler implements RequestHandlerInterface, PsrRequestHandlerInterface
{
Expand All @@ -41,6 +43,7 @@ class AjaxRequestHandler implements RequestHandlerInterface, PsrRequestHandlerIn
*/
public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
trigger_error(self::class . ' will be removed in TYPO3 v10. Use the regular application dispatcher instead.', E_USER_DEPRECATED);
return $this->handle($request);
}

Expand All @@ -56,6 +59,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
trigger_error(self::class . ' will be removed in TYPO3 v10. Use the regular application dispatcher instead.', E_USER_DEPRECATED);
/** @var Response $response */
$response = GeneralUtility::makeInstance(Response::class, 'php://temp', 200, [
'Content-Type' => 'application/json; charset=utf-8',
Expand All @@ -76,6 +80,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
*/
public function canHandleRequest(ServerRequestInterface $request): bool
{
trigger_error(self::class . ' will be removed in TYPO3 v10. Use the regular application dispatcher instead.', E_USER_DEPRECATED);
$routePath = $request->getParsedBody()['route'] ?? $request->getQueryParams()['route'] ?? '';
return strpos($routePath, '/ajax/') === 0;
}
Expand All @@ -87,6 +92,7 @@ public function canHandleRequest(ServerRequestInterface $request): bool
*/
public function getPriority(): int
{
trigger_error(self::class . ' will be removed in TYPO3 v10. Use the regular application dispatcher instead.', E_USER_DEPRECATED);
return 80;
}
}
3 changes: 1 addition & 2 deletions typo3/sysext/backend/Classes/Http/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Application implements ApplicationInterface
* @var array
*/
protected $availableRequestHandlers = [
\TYPO3\CMS\Backend\Http\RequestHandler::class,
\TYPO3\CMS\Backend\Http\AjaxRequestHandler::class
\TYPO3\CMS\Backend\Http\RequestHandler::class
];

/**
Expand Down
12 changes: 10 additions & 2 deletions typo3/sysext/backend/Classes/Http/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
// Check if the router has the available route and dispatch.
// Use a custom pre-created response for AJAX calls
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
$response = new Response('php://temp', 200, [
'Content-Type' => 'application/json; charset=utf-8',
'X-JSON' => 'true'
]);
} else {
$response = new Response();
}
try {
$response = GeneralUtility::makeInstance(Response::class);
// Check if the router has the available route and dispatch.
$dispatcher = GeneralUtility::makeInstance(RouteDispatcher::class);
return $dispatcher->dispatch($request, $response);
} catch (InvalidRequestTokenException $e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. include:: ../../Includes.txt

================================================
Deprecation: #83853 - Backend AjaxRequestHandler
================================================

See :issue:`83853`

Description
===========

The class :php:`\TYPO3\CMS\Backend\Http\AjaxRequestHandler` has been marked as deprecated and will be removed in TYPO3 v10.
This functionality has been moved into the backends' generic Request Handler functionality.

The AJAX functionality itself is not deprecated and can be used as before.


Impact
======

Installations that use :php:`\TYPO3\CMS\Backend\Http\AjaxRequestHandler` will trigger a deprecation log entry.


Affected Installations
======================

All installations that use custom extensions that add classes derived from :php:`\TYPO3\CMS\Backend\Http\AjaxRequestHandler`.


Migration
=========

Use a PSR-15 middleware for the Backend Middleware Stack or extend from the generic
:php:`\TYPO3\CMS\Backend\Http\RequestHandler` instead.

.. index:: Backend, PHP-API, FullyScanned
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
'Deprecation-83803-DeprecateEidRequestHandler.rst',
],
],
'TYPO3\CMS\Backend\Http\AjaxRequestHandler' => [
'restFiles' => [
'Deprecation-83853-BackendAjaxRequestHandler.rst',
],
],
'TYPO3\CMS\Frontend\Page\FramesetRenderer' => [
'restFiles' => [
'Breaking-80700-DeprecatedFunctionalityRemoved.rst',
Expand Down

0 comments on commit 1ea84aa

Please sign in to comment.