mteu / typo3-typed-extconf
Aims to provide a type-safe extension configuration management for TYPO3, ensuring proper types instead of string-only values from backend configuration or mixed types from config/system/settings.php
Installs: 144
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 0
Forks: 1
Open Issues: 1
Type:typo3-cms-extension
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0
- ext-filter: *
- cuyz/valinor: ^2.0
- nette/php-generator: ^4.1.6
- symfony/console: ^7.3
- typo3/cms-core: ~12.4.31 || ~13.4.12
Requires (Dev)
- eliashaeussler/phpunit-attributes: ^1.7
- eliashaeussler/version-bumper: ^3.0
- phpunit/phpcov: ^10.0 || ^11.0.0
- phpunit/phpunit: ^11.5 || ^12.1
- roave/security-advisories: dev-latest
- symfony/dependency-injection: ^7.3
- typo3/testing-framework: ^8.2 || ^9.2
- dev-main
- 0.2.0
- 0.1.1
- 0.1.0
- dev-docs/thank-contributor
- dev-task/bump-stability-to-beta
- dev-task/add-extension-icon
- dev-docs/review-documentation
- dev-task/reorganise-fixtures
- dev-renovate/phpunit-phpcov-10.0.x-lockfile
- dev-renovate/phpunit-phpunit-11.5.x-lockfile
- dev-renovate/eliashaeussler-version-bumper-3.0.x-lockfile
- dev-renovate/cuyz-valinor-2.x-lockfile
- dev-renovate/typo3-testing-framework-8.2.x-lockfile
- dev-renovate/patch-symfony
- dev-renovate/nette-php-generator-4.1.x-lockfile
- dev-task/remove-settings-predefinition
- dev-task/refactor-class-generation
- dev-task/refactor-pipelines
- dev-task/require-shadow-deps
- dev-task/require-extensionkey-in-attribute
- dev-task/remove-singletoninterface-from-provider
- dev-renovate/cuyz-valinor-2.1.x-lockfile
- dev-task/rector
- dev-task/set-typo3-v12-support
- dev-docs/custom-treemapper
- dev-bugfix/fix-service-injection
- dev-task/set-public-service-visibility
- dev-feature/construct-with-custom-mapper
- dev-feature/inject-extconf-provider
- dev-renovate/patch-phpstan-packages
- dev-task/drop-default-value
- dev-feature/support-typo3-v12
- dev-revert-4-feature/support-typo3-v12
- dev-feature/support-php82
- dev-docs/improve-documentation
This package is auto-updated.
Last update: 2025-07-25 14:48:27 UTC
README
TYPO3 Typed Extension Configuration
This TYPO3 CMS extension aims to provide a type-safe extension configuration
management for TYPO3, ensuring proper types instead of string-only values from
backend configuration or mixed types from config/system/settings.php|additional.php
(or custom solutions around those).
Warning
This extension is in a testing and review phase and hence marked beta
. Be
cautious when using this in production environments.
π Features
- Type Safety: Automatic conversion from TYPO3's string configuration to proper PHP types
- Schema Definition: Define configuration using PHP attributes and constructor parameters
- Path Mapping: Support for nested configuration with dot notation (
api.endpoint
) - Configuration Generation: Generate classes from
ext_conf_template.txt
or interactively - Dependency Injection: Configuration classes auto-registered as services
β‘οΈ Installation
Add this package to your TYPO3 Extension:
composer require mteu/typo3-typed-extconf
This extension relies heavily on these key dependencies:
cuyz/valinor
for type-safe object mapping and validationnette/phpgenerator
for PHP code generation for configuration classessymfony/console
for the automated (or interactive) code generation
π‘ Usage
Tip
For a comprehensive developer guide with advanced examples and best practices, check out the Developer Guide.
Note
If you're in a hurry you might want to have this package generate
configuration classes automatically based on your extension's
ext_conf_template.txt
.
Run ./vendor/bin/typo3 typed-extconf:generate
or consult the
Command Guide.
Use with caution, though, since this functionality is not well tested, yet.
1. Define Configuration Schema
Create a configuration class for your extension using PHP attributes:
<?php use mteu\TypedExtConf\Attribute\ExtConfProperty; use mteu\TypedExtConf\Attribute\ExtensionConfig; #[ExtensionConfig(extensionKey: 'my_extension')] final readonly class MyExtensionConfig { public function __construct( #[ExtConfProperty()] public int $maxItems = 10, #[ExtConfProperty(required: false)] public bool $enableFeature = true, #[ExtConfProperty(path: 'api.endpoint')] public string $apiEndpoint = '/api/v1', #[ExtConfProperty()] public array $allowedTypes = ['default', 'fallback'], ) {} }
2. Access Typed Configuration
Option A: Direct Injection (Recommended)
Directly inject your configuration object using dependency injection:
<?php final readonly class MyService { public function __construct( private MyExtensionConfig $config, ) {} public function doSomething(): void { // All properties are guaranteed to have the correct types $maxItems = $this->config->maxItems; // int $isEnabled = $this->config->enableFeature; // bool $endpoint = $this->config->apiEndpoint; // string $types = $this->config->allowedTypes; // array } }
Option B: Using the Provider
Alternatively, use the configuration provider service:
<?php use mteu\TypedExtConf\Provider\ExtensionConfigurationProvider; final readonly class MyService { public function __construct( private ExtensionConfigurationProvider $configurationProvider, ) {} public function doSomething(): void { $config = $this->configurationProvider->get(MyExtensionConfig::class); // Use configuration... } }
π Attribute Reference
#[ExtensionConfig]
Class-level attribute to specify which TYPO3 extension the configuration belongs to.
Parameters:
extensionKey
(string, required): The TYPO3 extension key.
#[ExtConfProperty]
Property/parameter-level attribute for configuration value mapping.
Parameters:
path
(string, optional): Custom configuration path using dot notation (e.g., 'api.endpoint')required
(bool, optional): Whether the configuration value is required (default: false)
Note
Default values are defined as PHP constructor parameter defaults, not in the attribute.
How It Works
TYPO3 stores extension configuration in $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']
as an associative array with
string values. Those strings could be manually altered by the developers to other types.
This extension automatically converts those types to proper PHP types using your configuration class schema.
π§βπ» Real-world example with nested configuration
#[ExtensionConfig(extensionKey: 'my_complex_ext')] final readonly class ComplexConfiguration { public function __construct( #[ExtConfProperty(path: 'api.endpoint')] public string $endpoint = '/api', // Nested configuration object public DatabaseConfiguration $database, #[ExtConfProperty()] public string $environment = 'production', ) {} } final readonly class DatabaseConfiguration { public function __construct( #[ExtConfProperty(path: 'db.host')] public string $host = 'localhost', #[ExtConfProperty(path: 'db.port')] public int $port = 3306, #[ExtConfProperty(path: 'db.ssl')] public bool $enableSsl = true, ) {} }
π Credits
This project is built on the excellent CuyZ\Valinor library, which provides the core type mapping and validation functionality. Without Valinor's robust object mapping capabilities, this extension would not be possible.
Special thanks to:
- CuyZ\Valinor for the powerful and flexible object mapping engine
- Romain Canon and the Valinor contributors for their excellent work
- Elias HΓ€uΓler for his extensive help reviewing this extension and
contributing substantial improvements. Be sure to check out his Composer
packages β
PHPUnit Attributes
andVersion Bumper
β both of which greatly simplify maintaining this project.
π€ Contributing
Contributions are very welcome! Please have a look at the Contribution Guide. It lays out the workflow of submitting new features or bugfixes.
π Security
Please refer to our security policy if you discover a security vulnerability in this extension. Be warned, though. I cannot afford bounty. This is private project.
β License
This extension is licensed under the GPL-2.0-or-later license.
π¬ Support
For issues and feature requests, please use the GitHub issue tracker.