Breaking: #110286 - Text extractor registration and interface changed
See forge#110286
Description
Text extractors are now registered as tagged services via dependency injection (see Feature: #110286 - Register text extractors as tagged services). This comes with the following breaking changes:
\TYPO3\is now a no-op. Calling the method has no effect anymore. The method will be removed in TYPO3 v16.0.CMS\ Core\ Resource\ Text Extraction\ Text Extractor Registry->register Text Extractor () - Extractors registered with the same priority are no longer
guaranteed to be asked in the order they were added: previously,
extractors kept the order in which
Textwas called fromExtractor Registry->register Text Extractor () ext_. The order of same-priority tagged services is now an implementation detail of the dependency injection container and must not be relied upon. Extensions that depend on a specific evaluation order between extractors should assign distinct priorities instead.localconf. php - The methods of
\TYPO3\are now strictly typed:CMS\ Core\ Resource\ Text Extraction\ Text Extractor Interface canandExtract Text (File Interface $file): bool extract.Text (File Interface $file): string - The method
createhas been removed fromText Extractor Instance () Text, the methodExtractor Registry gethas been changed from public to protected visibility, and the remaining methods are now strictly typed. The public API of the registry isText Extractor Instances () get, which returns the first matching extractor for a given file.Text Extractor ()
Impact
Text extractors registered via
Text in
ext_ are no longer evaluated: no text is extracted
by the custom extractor until it is registered as a tagged service.
Custom extractor classes implementing
Text
without the adapted method signatures will cause a fatal PHP error.
Affected installations
All installations with custom extensions registering text extractors
via
Text, or providing
custom implementations of
Text. The extension
scanner reports usages of
register as weak match.
Migration
Remove the
Text call
from ext_ and add the
#
attribute to the extractor class instead. Add the native type
declarations to
can and
extract:
use TYPO3\CMS\Core\Attribute\AsTextExtractor;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface;
#[AsTextExtractor(priority: 10)]
final class PdfTextExtractor implements TextExtractorInterface
{
public function canExtractText(FileInterface $file): bool
{
// ...
}
public function extractText(FileInterface $file): string
{
// ...
}
}
In case the extension supports both TYPO3 v14 and v15, register the
extractor in both ways: the ext_ registration is
evaluated in v14, the attribute in v15. The
bool
and
string
return type declarations are compatible with both
versions.
Code that called
Text
to inspect all registered extractors should inject
Text and use
get to
retrieve the matching extractor for a given file instead.