1. Go to this page and download the library: Download mteu/typo3-typed-extconf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mteu / typo3-typed-extconf example snippets
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(
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
}
}
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...
}
}
#[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,
) {}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.