144 lines
4.5 KiB
PHP
144 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* This file is part of TYPO3 CMS-based extension "ew-base" by evoWeb.
|
|
*
|
|
* It is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License, either version 2
|
|
* of the License, or any later version.
|
|
*/
|
|
|
|
namespace Evoweb\EwBase\Configuration;
|
|
|
|
use TYPO3\CMS\Core\Core\Environment;
|
|
|
|
class AdditionalConfiguration
|
|
{
|
|
protected string $extensionKey = 'ew_base';
|
|
|
|
protected array $developConfig = [
|
|
'BE' => [
|
|
'debug' => true,
|
|
'loginRateLimit' => 10000,
|
|
],
|
|
'FE' => [
|
|
'debug' => true,
|
|
'loginRateLimit' => 10000,
|
|
],
|
|
'GFX' => [
|
|
'processor_colorspace' => 'RGB',
|
|
'processor_path' => '/usr/bin/',
|
|
'processor_path_lzw' => '/usr/bin/',
|
|
],
|
|
'SYS' => [
|
|
'devIPmask' => '*',
|
|
'displayErrors' => 1,
|
|
'systemLogLevel' => 0,
|
|
'exceptionalErrors' => 12290,
|
|
'errorHandlerErrors' => E_ALL & ~(
|
|
2048 /* deprecated E_STRICT */ | E_NOTICE | E_COMPILE_WARNING | E_COMPILE_ERROR
|
|
| E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR
|
|
),
|
|
],
|
|
];
|
|
|
|
/**
|
|
* This is needed to override all mail settings instead of merging them.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected array $mailConfig = [
|
|
'transport' => 'smtp',
|
|
'transport_smtp_server' => 'mailpit:1025'
|
|
];
|
|
|
|
public function initialize(array $configuration = []): void
|
|
{
|
|
$this->addContextToSitename();
|
|
$this->addContextConfiguration($configuration);
|
|
if (Environment::getContext() == 'Development') {
|
|
$this->addDebugConfiguration();
|
|
}
|
|
$this->addFurtherConfigurationFiles();
|
|
}
|
|
|
|
protected function addContextToSitename(): void
|
|
{
|
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] .= ' - ' . Environment::getContext();
|
|
}
|
|
|
|
protected function addDebugConfiguration(): void
|
|
{
|
|
$GLOBALS['TYPO3_CONF_VARS'] = $this->arrayMergeRecursive(
|
|
$GLOBALS['TYPO3_CONF_VARS'],
|
|
$this->developConfig
|
|
);
|
|
$layoutRootPaths = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'] ?: [];
|
|
$partialRootPaths = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['partialRootPaths'] ?: [];
|
|
$templateRootPaths = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'] ?: [];
|
|
|
|
$GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $this->mailConfig;
|
|
|
|
if (!empty($layoutRootPaths)) {
|
|
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'] = $layoutRootPaths;
|
|
}
|
|
if (!empty($partialRootPaths)) {
|
|
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['partialRootPaths'] = $partialRootPaths;
|
|
}
|
|
if (!empty($templateRootPaths)) {
|
|
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'] = $templateRootPaths;
|
|
}
|
|
}
|
|
|
|
protected function addContextConfiguration(array $configuration): void
|
|
{
|
|
$context = (string)Environment::getContext();
|
|
if (isset($configuration[$context]) && is_array($configuration[$context])) {
|
|
$GLOBALS['TYPO3_CONF_VARS'] = $this->arrayMergeRecursive(
|
|
$GLOBALS['TYPO3_CONF_VARS'],
|
|
$configuration[$context]
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Loads additional configuration two levels up relative to instance
|
|
* or relative to ADDITIONAL_CONFIG_FILE configuration
|
|
*/
|
|
protected function addFurtherConfigurationFiles(): void
|
|
{
|
|
$paths = [
|
|
Environment::getPublicPath() . '/../../../AdditionalConfiguration.php',
|
|
Environment::getPublicPath() . '/' . ($_SERVER['ADDITIONAL_CONFIG_FILE'] ?? time() . '.php'),
|
|
];
|
|
foreach ($paths as $path) {
|
|
$path = realpath($path);
|
|
if ($path && @file_exists($path)) {
|
|
/** @noinspection */
|
|
require_once $path;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function arrayMergeRecursive(array $array1, array $array2): array
|
|
{
|
|
$merged = $array1;
|
|
|
|
foreach ($array2 as $key => $value) {
|
|
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
|
|
$merged[$key] = $this->arrayMergeRecursive($merged[$key], $value);
|
|
} elseif (is_numeric($key)) {
|
|
if (!in_array($value, $merged)) {
|
|
$merged[] = $value;
|
|
}
|
|
} else {
|
|
$merged[$key] = $value;
|
|
}
|
|
}
|
|
|
|
return $merged;
|
|
}
|
|
}
|