定制 clubdrei/typo3-env-config 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

clubdrei/typo3-env-config

最新稳定版本:1.0.0

Composer 安装命令:

composer require clubdrei/typo3-env-config

包简介

Dependency-free parser for converting flat environment variables into nested PHP arrays (TYPO3-focused, framework-agnostic)

README 文档

README

Dependency-free parser for converting flat environment variables into nested PHP arrays.

Main use case: TYPO3-style keys like TYPO3_CONF_VARS__.... Also works in any PHP project (framework agnostic).

Requirements

  • PHP >=5.4

Installation

composer require clubdrei/typo3-env-config

What it does

Input:

TYPO3_CONF_VARS__DB__Connections__Default__host=127.0.0.1
TYPO3_CONF_VARS__DB__Connections__Default__dbname=mydb

Output:

[
    'TYPO3_CONF_VARS' => [
        'DB' => [
            'Connections' => [
                'Default' => [
                    'host' => '127.0.0.1',
                    'dbname' => 'mydb',
                ],
            ],
        ],
    ],
];

Usage

1) Parse directly from runtime environment

Use parseFromEnvironment() when values already exist in $_SERVER, $_ENV, and/or getenv().

<?php

use Clubdrei\Typo3EnvConfig\Parser;

$parsed = Parser::parseFromEnvironment('TYPO3_CONF_VARS');

if (isset($parsed['TYPO3_CONF_VARS'])) {
    $config = array_replace_recursive($config, $parsed['TYPO3_CONF_VARS']);
}

Lookup precedence in parseFromEnvironment():

  1. $_SERVER
  2. $_ENV
  3. getenv() (PHP >=7.1 only, where parameterless getenv() is available)

First value found for a key wins. This matches the common $_SERVER / $_ENV / getenv() behavior used in Laravel and vlucas/phpdotenv setups.

2) Parse a custom key/value array

Use parseFromArray() when you already have env variables in your own array.

<?php

use Clubdrei\Typo3EnvConfig\Parser;

$env = [
    'APP_CONFIG__database__host' => '127.0.0.1',
    'APP_CONFIG__database__name' => 'mydb',
    'APP_CONFIG__features__0' => 'search',
    'APP_CONFIG____emptySegment' => 'yes',
    'UNRELATED__value' => 'ignored',
];

$parsed = Parser::parseFromArray($env, 'APP_CONFIG');

Result:

[
    'APP_CONFIG' => [
        'database' => [
            'host' => '127.0.0.1',
            'name' => 'mydb',
        ],
        'features' => [
            '0' => 'search',
        ],
        '' => [
            'emptySegment' => 'yes',
        ],
    ],
];

Notes:

  • Keys outside the selected prefix are ignored.
  • Numeric and empty segments are kept as-is.
  • Values can be processed with special placeholders.

3) Value processors

The parser supports these value processors:

  • %int:VALUE% casts VALUE to int
  • %bool:VALUE% casts VALUE to bool (Symfony-style semantics)
  • %typo3.environment.getProjectPath% resolves TYPO3\CMS\Core\Core\Environment::getProjectPath()
  • %typo3.environment.getVarPath% resolves TYPO3\CMS\Core\Core\Environment::getVarPath()

Example:

<?php

use Clubdrei\Typo3EnvConfig\Parser;

$env = [
    'TYPO3_CONF_VARS__SYS__maxRetries' => '%int:3%',
    'TYPO3_CONF_VARS__SYS__displayErrors' => '%bool:false%',
    'TYPO3_CONF_VARS__SYS__projectPath' => '%typo3.environment.getProjectPath%',
];

$parsed = Parser::parseFromArray($env, 'TYPO3_CONF_VARS');

API

  • Parser::parseFromEnvironment($prefix = 'TYPO3_CONF_VARS', $separator = '__')
  • Parser::parseFromArray(array $environmentVariables, $prefix = 'TYPO3_CONF_VARS', $separator = '__')

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固