Breaking: #98370 - Extbase Request cleanup and hardening
See forge#98370
Description
Extbase \TYPO3\
has been turned into a decorator of the
PSR-7 Server
with Core v11:
Extbase-based extensions work with the PSR-7 Core Request, Extbase
specific Request state is attached as an attribute to the PSR-7 Request.
Most of these Extbase-specific attribute properties are now available in Core v12
by activating the according decorator methods in \TYPO3\
,
which is implemented by \TYPO3\
. The Request
now
also properly extends PSR-7 Server
and is type-hinted within
the Extbase framework.
PSR-7 interfaces rely on object immutability: A created Request object is never changed, instead
a new object is created and returned when changed. The old fashioned Extbase Request violated this with
various set
methods. These have been removed, and this is the part that is considered
breaking for consuming extensions.
Impact
Extbase-based extensions using static code analyzers like phpstan in CI should benefit from improved scanner results and can further harden their codebase.
Affected installations
Extensions that actively manipulate the given Extbase Request
using setter methods
will trigger fatal PHP "method does not exist" errors.
Instances with extensions actively creating a Request
must hand over
a \Psr\
as constructor argument, it must have
the attribute extbase
set, which must be an instance of
\TYPO3\
.
Migration
It is relatively seldom that Extbase extensions need to actively manipulate the Extbase Request since most of that is handled by the Extbase Framework internally for consuming extensions.
Extensions that use the set
methods for whatever reasons have to
change them to their with
counterparts, though: Nearly all "withers" are now
declared as part of Request
and already exist in v11, "setters" can be
migrated quite easily.
From an Extbase Framework API point of view, extension should only rely on Request
methods: The second level Extbase
attribute is considered
@internal
and extensions shouldn't work with it directly. There are just a couple
of methods used by Extbase Framework based on direct Extbase
manipulation,
most of them are related to the action argument validation and action forwarding behavior of Extbase,
which Extbase extensions in general shouldn't need to deal with themselves.
When changing from "setters" to "withers", the important key change is that calling a
with
method does not manipulate the existing request, but returns a new
instance instead. In practice, if the previous Request object has been set to some other
client object beforehand, and if a new Request is created using a with
method, those client objects may need to be updated with the new object. A typical use case
is $this->view
in a controller class, which may now need $this->view->set
to receive the new Request
to work on, and it's most likely also a good idea to update
$this->request = $my
as well.