Skip to content

[FEATURE] Using PHP attributes to configure indexer (Request for comments) #4561

@3l73

Description

@3l73

Currently the indexer are defined in TypoScript. The purpose of TypoScript itself is rendering the website, not configure services or functions.

The use of PHP attributes to register Solr indexer could replace the TypoScript configuration.

PHP attributes are widely used within Symfony and other projects like PHPUnit.

It offers a standardized way to add services with configuration without change configuration files.

The attribute can either be used on the class name or on a method.

Example to use with a class:

<?php
namespace Vendor\Extension\Solr\Indexer;

use ApacheSolrForTypo3\Solr\Attributes\AsIndexer;

#[AsIndexer(tables: ['tt_content'])]
class ExampleIndexer
{
     public function __invoke(array $data): void
     {
     }
}

Example to use with methods:

<?php
namespace Vendor\Extension\Solr\Indexer;

use ApacheSolrForTypo3\Solr\Attributes\AsIndexer;

class ExampleIndexer
{
     #[AsIndexer(tables: ['tt_content'])]
     public function indexTtContent(array $data): void
     {
     }

     #[AsIndexer(tables: ['pages'])]
     public function indexPages(array $data): void
     {
     }
}

What needs to be considered

Using PHP attributes could have some side effects. Every package that is installed could add a indexer just by having a class that uses this tag.

Therefor is has to be possible to exclude classes that should not used as indexer. This coud be done with a black or white list that should be part of the site settings.

Another topic is extending existing indexer in case a table contains additional columns.

Target versions
The target version should be 14

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions