Epic #83968: PSR-11 Initiative
PackageManager caching is over complicated
The PackageManager caches all Package objects.
As a Package object currently requires a reference to the PackageManager, the PackageManager temporarily provides a reference to itself in
$GLOBALS['TYPO3_currentPackageManager'] while using
unserialize to re-create caches Package objects.
The PackageManager reference should just be dropped.
[TASK] Simplify PackageManager caching
We do not want to pollute $GLOBALS to be able to inject PackageManager
as $GLOBALS['TYPO3_currentPackageManager']. to cache-restored Package
objects (during unserialize).
Therefore this patch drops the PackageManager dependency from the Package
The global injected PackageManager was used to calculate the
package metadata on demand. Package metadata is a small array
that doesn't harm to be created during Package object construction,
(it's cached afterwards anyway).
This allows us to drop the PackageManager reference, which
simplifies serialize/unserialize logic (we can drop __sleep and __wakeup).
We also combine the PackageManger and PackageObjects cache
into one cache file instead of two. There is no advantage
in having to read two files from the filesystem. The prior argument
(introduced with the initial PackageManager patch in 2013) "so PHP does
not have to parse the serialized string" is actually invalid:
The serialized string has to be parsed anyway.
PHP did not need to parse the var_export'd variant, true.
BUT: The var_export'd variant is theoretically php opcache'able, while
reading a file and passing the file contents to serialize() is not.
That means the previous solution actually hampered native optimizations.
Ideally we could drop the serialize/unserialize thing and just use
var_export for Package objects, but for that to work the Package class
(and all of it's properties) would need to implement the magic
_set_state() method (which is used by var_export to create objects).
That's currently not possible, because the composerManifest (which
is read from json_decode) is a stdClass and does not provide a
_set_state() method. We'd need to rewrite all that code to an array
or so. Maybe something for a later patch.
As a drive-by fix we now hash the TYPO3_version value into the
cacheEntryIdentifier like other core caches do.
Tested-by: TYPO3com <firstname.lastname@example.org>
Reviewed-by: Benni Mack <email@example.com>
Tested-by: Benni Mack <firstname.lastname@example.org>
Reviewed-by: Susanne Moog <email@example.com>
Tested-by: Susanne Moog <firstname.lastname@example.org>