The cardinal issue with constant 'TYPO3_MODE' is that it's
value is NOT constant: It is defined early during bootstrap and
derived from information that is hand over from entry point
index.php's. Depending on this, value is either 'FE' or 'BE'.
Using that constant or the related constant 'TYPO3_REQUESTTYPE'
makes it impossible to change scope from backend to frontend
in one PHP call. This actively blocks executing sub requests,
use cases are for instance executing a frontend request within
a running backend call (eg. view module), or executing frontend
requests from cli (eg. some indexer).
Dropping 'TYPO3_MODE' and its friends is thus a requirement to
finally allow such scenarios. We can't get rid of the distinction
between 'frontend' and 'backend' altogether since some legit use
cases like different paths or security settings depend on it.
Looking at TYPO3 bootstrap, the only class that 'knows' if it's
frontend or backend are the Application classes of ext:frontend
and ext:backend. They are the PSR-15 entry points, they create a
first PSR-7 request object if it has not been given, and then
call the PSR-15 middleware stack dispatcher to create a PSR-7
response, starting with this first request object.
The solution to get rid of 'TYPO3_MODE' is to add the information
'I am a frontend or backend request' as attribute to the request
object in the Application classes. To simplify things, the helper
class ApplicationType is introduced that answers isFrontend() and
isBackend() for a given request object.
Documentation changelog files with full details on the impact of
this change will be added with an upcoming patch that deprecates
the constants in master.
This patch targets master and v10: 'TYPO3_MODE' is used in
extensions quite often. Having the API in both v10 and v11 helps
extension developers to deliver deprecation free extensions that
are compatible with both v10 and v11 in one version. Codewise,
neither the 'applicationType' attribute nor the helper class
harm in v10.