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).
| TYPO3 v12 | TYPO3 v13 | TYPO3 v14 | |
|---|---|---|---|
| up to v0.3 | β | β | β |
| v1.x | β | β | β |
- 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.txtor interactively - Dependency Injection: Configuration classes auto-registered as services
Add this package to your TYPO3 Extension:
composer require mteu/typo3-typed-extconfThis extension relies heavily on these key dependencies:
cuyz/valinorfor type-safe object mapping and validationnette/phpgeneratorfor PHP code generation for configuration classessymfony/consolefor the automated (or interactive) code generation
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.
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'],
) {}
}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
}
}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...
}
}Class-level attribute to specify which TYPO3 extension the configuration belongs to.
Parameters:
extensionKey(string, required): The TYPO3 extension key.
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.
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.
#[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,
) {}
}This project is built on the excellent CuyZ\Valinor library, which provides the core type mapping and validation functionality.
Special thanks to:
- CuyZ\Valinor for the powerful and flexible object mapping engine
- Romain Canon personally and the Valinor contributors in general 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 AttributesandVersion Bumperβ both of which greatly simplify maintaining this project.
Contributions are very welcome! Please have a look at the Contribution Guide. It lays out the workflow of submitting new features or bugfixes.
Please refer to our security policy if you discover a security vulnerability in this extension. Be warned, though. I cannot afford bounty. This is a private project.
This extension is licensed under the GPL-2.0-or-later license.
For issues and feature requests, please use the GitHub issue tracker.