mteu/typo3-typed-extconf 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mteu/typo3-typed-extconf

Composer 安装命令:

composer require mteu/typo3-typed-extconf

包简介

Typed Extension Configuration - 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

README 文档

README

CGL Tests Coverage Maintainability

Extension Icon

TYPO3 Typed Extension Configuration

TYPO3 versions Latest version Stability PHP Version Require

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 Support

TYPO3 v12 TYPO3 v13 TYPO3 v14
up to v0.3
v1.x

🚀 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:

💡 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

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
    }
}

Using the ExtensionConfigurationProvider

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.

🧑‍💻 Example

#[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.

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 Attributes and Version 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 a 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.

mteu/typo3-typed-extconf 适用场景与选型建议

mteu/typo3-typed-extconf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 88.49k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2025 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mteu/typo3-typed-extconf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mteu/typo3-typed-extconf 我们能提供哪些服务?
定制开发 / 二次开发

基于 mteu/typo3-typed-extconf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 88.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 18
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2025-07-21