eliashaeussler/typo3-config-objects

Provides value objects for strictly typed TYPO3 configuration

0.1.0 2025-04-16 10:27 UTC

This package is auto-updated.

Last update: 2025-04-24 05:56:40 UTC


README

Value objects for strictly typed TYPO3 configuration

Coverage Maintainability CGL Tests Supported PHP Versions

This library provides custom value objects for strictly typed TYPO3 configuration. They can be used to replace the usage of arrays in configuration files, such as Confguration/Icons.php.

🔥 Installation

Packagist Packagist Downloads

composer require eliashaeussler/typo3-config-objects

⚡ Usage

It's pretty easy: Replace arrays in your configuration files with value objects 💅. The following configuration classes are available:

IconConfiguration (for Configuration/Icons.php)

Before:

// Configuration/Icons.php

use TYPO3\CMS\Core;

return [
    'tx-example-my-icon' => [
        'provider' => Core\Imaging\IconProvider\SvgIconProvider::class,
        'source' => 'EXT:example/Resources/Public/Icons/my-icon.svg',
    ],
    'tx-example-my-second-icon' => [
        'provider' => Core\Imaging\IconProvider\BitmapIconProvider::class,
        'source' => 'EXT:example/Resources/Public/Icons/my-second-icon.jpg',
    ],
    'tx-example-my-legacy-icon' => [
        'provider' => Core\Imaging\IconProvider\SvgIconProvider::class,
        'source' => 'EXT:example/Resources/Public/Icons/my-legacy-icon.svg',
        'deprecated' => [
            'since' =>  'TYPO3 v12',
            'until' => 'TYPO3 v13',
            'replacement' => 'tx-example-my-new-icon',
        ],
    ],
    'tx-example-my-new-icon' => [
        'provider' => \Vendor\Example\Imaging\MyCustomIconProvider::class,
        'renderer' => \Vendor\Example\Renderer\MyCustomIconRenderer::class,
    ],
];

After:

// Configuration/Icons.php

use EliasHaeussler\Typo3ConfigObjects;

return Typo3ConfigObjects\Configuration\IconConfiguration::create()
    // Add a list of icons to configure
    ->add(
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-icon')
            ->useSvgIconProvider('EXT:example/Resources/Public/Icons/my-icon.svg'),
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-second-icon')
            ->useBitmapIconProvider('EXT:example/Resources/Public/Icons/my-second-icon.jpg')
    )

    // You can also use deprecated icons
    ->add(
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-legacy-icon')
            ->useSvgIconProvider('EXT:example/Resources/Public/Icons/my-legacy-icon.svg')
            ->setDeprecated(
                new Typo3ConfigObjects\ValueObject\DeprecatedIcon(
                    since: 'TYPO3 v12',
                    until: 'TYPO3 v13',
                    replacement: 'tx-example-my-new-icon',
                ),
            )
    )

    // You can also use custom icon providers and custom options
    ->add(
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-new-icon')
            ->useCustomIconProvider(\Vendor\Example\Imaging\MyCustomIconProvider::class)
            ->addOption('renderer', \Vendor\Example\Renderer\MyCustomIconRenderer::class)
    )

    // Don't forget to return an array representation (TYPO3 expects an array to be returned)
    ->toArray();

MiddlewareConfiguration (for Configuration/RequestMiddlewares.php)

Before:

// Configuration/RequestMiddlewares.php

use TYPO3\CMS\Core;

return [
    'backend' => [
        'vendor/extension/my-middleware' => [
            'target' => \Vendor\Example\Middleware\MyMiddleware::class,
        ],
        'vendor/extension/my-other-middleware' => [
            'target' => \Vendor\Example\Middleware\MyOtherMiddleware::class,
            'before' => [
                'vendor/extension/my-middleware',
            ],
            'after' => [
                'typo3/cms-backend/authentication',
            ],
        ],
    ],
    'frontend' => [
        'typo3/cms-redirects/redirecthandler' => [
            'disabled' => true,
        ],
    ],
];

After:

// Configuration/RequestMiddlewares.php

use EliasHaeussler\Typo3ConfigObjects;

return Typo3ConfigObjects\Configuration\MiddlewareConfiguration::create()
    // Add a list of middlewares
    ->addToBackendStack(
        Typo3ConfigObjects\ValueObject\RequestMiddleware::create('vendor/extension/my-middleware')
            ->setTarget(\Vendor\Example\Middleware\MyMiddleware::class),
        Typo3ConfigObjects\ValueObject\RequestMiddleware::create('vendor/extension/my-other-middleware')
            ->setTarget(\Vendor\Example\Middleware\MyOtherMiddleware::class)
            ->before('vendor/extension/my-middleware')
            ->after('typo3/cms-backend/authentication')
    )

    // You can also disable existing middlewares
    ->addToFrontendStack(
        Typo3ConfigObjects\ValueObject\RequestMiddleware::create('typo3/cms-redirects/redirecthandler')
            ->disable()
    )

    // Don't forget to return an array representation (TYPO3 expects an array to be returned)
    ->toArray();

🧑‍💻 Contributing

Please have a look at CONTRIBUTING.md.

⭐ License

This project is licensed under GNU General Public License 2.0 (or later).