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\CMS\Core\Resource\TextExtraction\TextExtractorRegistry->registerTextExtractor() in ext_localconf.php.

A text extractor class implementing \TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface is registered by adding the new PHP attribute \TYPO3\CMS\Core\Attribute\AsTextExtractor to the class:

EXT:my_extension/Classes/Resource/TextExtraction/PdfTextExtractor.php
use TYPO3\CMS\Core\Attribute\AsTextExtractor;
use TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface;

#[AsTextExtractor(priority: 10)]
final class PdfTextExtractor implements TextExtractorInterface
{
    // ...
}
Copied!

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 ( canExtractText() ). The PlainTextExtractor 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.text_extractor can be used directly in Configuration/Services.yaml:

EXT:my_extension/Configuration/Services.yaml
MyVendor\MyExtension\Resource\TextExtraction\PdfTextExtractor:
  tags:
    - name: fal.text_extractor
      priority: 10
Copied!

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.php on 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.php files.
  • The registration is validated at container compile time: a service tagged as fal.text_extractor that does not implement TextExtractorInterface fails the container build with a speaking exception, instead of causing errors when text is extracted.

Registration in ext_localconf.php via TextExtractorRegistry->registerTextExtractor() is not evaluated anymore, see Breaking: #110286 - Text extractor registration and interface changed for the upgrade path.