Feature: #110286 - Register text extractors as tagged services
See forge#110286
Description
Text extractors, used to extract the textual content from files, for
example for search indexing, are now registered as tagged services via
dependency injection instead of the previous programmatic registration
through
\TYPO3\
in ext_localconf.php.
A text extractor class implementing
\TYPO3\ is
registered by adding the new PHP attribute
\TYPO3\ to the class:
use TYPO3\CMS\Core\Attribute\AsTextExtractor;
use TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface;
#[AsTextExtractor(priority: 10)]
final class PdfTextExtractor implements TextExtractorInterface
{
// ...
}
The extractor priority is defined at registration time via the
attribute. Extractors with a higher priority are asked first whether
they can extract text from a given file (
can). The
Plain shipped with TYPO3 Core is registered with the
default priority
0
, so any custom extractor using a priority
above
0
takes precedence. The order in which extractors of the
same priority are evaluated is not defined and must not be relied upon;
use distinct priorities if the evaluation order matters.
Alternatively, the service tag
fal. can be used
directly in Configuration/Services.yaml:
MyVendor\MyExtension\Resource\TextExtraction\PdfTextExtractor:
tags:
- name: fal.text_extractor
priority: 10
Impact
Registering text extractors as tagged services has the following benefits over the previous programmatic registration:
- The registration is resolved once at container compile time instead
of executing registration code from
ext_localconf.phpon every request. Loading and validating the extractor classes per request as well as instantiating them at runtime is not necessary anymore. - Text extractors are proper services now and can use dependency injection in their constructor.
- The extractor priority is declared at the class itself instead of
depending on the loading order of
ext_localconf.phpfiles. - The registration is validated at container compile time: a service
tagged as
fal.that does not implementtext_ extractor Textfails the container build with a speaking exception, instead of causing errors when text is extracted.Extractor Interface
Registration in ext_localconf.php via
Text is not evaluated
anymore, see Breaking: #110286 - Text extractor registration and interface changed for the upgrade path.