helhum / TYPO3-Distribution

A distribution package for TYPO3 CMS with added typo3_console support
81 stars 19 forks source link

Add PHP file content in AdditionalConfiguration.php #11

Closed stat1x closed 6 years ago

stat1x commented 7 years ago

Hi, I'm using your fantastic TYPO3-Distribution, many many thanks for it. I didn't find how I can add a PHP file content in AdditionalConfiguration.php. I see there is a PhpFileReader in your config-loader but I don't know how to use it. Can tell me if it is possible at the moment and if yes how I can achieve it.

helhum commented 6 years ago

Ca you explain a bit more high level what you are trying to achieve?

stat1x commented 6 years ago

I need to add some configuration in my AdditionalConfiguration.php but I don't find the way to do it. Here is what I want to add :

$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'error-404';
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_statheader'] = $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found';

$GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'error-503';
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling_statheader'] = $_SERVER['SERVER_PROTOCOL'] . ' 503 Service Temporarily Unavailable';

/***************************************************************/

$hostParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('.', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'), true);

if (count($hostParts) === 3) {
    $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] = 'no-reply@' . preg_replace('/^[[:alnum:]-_]+\.{1}/', '', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
    $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'] = preg_replace('/^[[:alnum:]-_]+\.{1}/', '', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
} else {
    $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] = 'no-reply@' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
    $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
}

unset($hostParts);
helhum commented 6 years ago

As long as you want to use https://github.com/helhum/typo3-config-handling, there is no way to add code to AdditionalConfiguration.php.

You have two options:

  1. Don't use https://github.com/helhum/typo3-config-handling
  2. Move as much es possible to environment config and truly dynamic config to any ext_localconf.php

I personally would go for 2., hard code the protocol for the 404 to some value that makes sense (most likely HTTP 1.1) and put the host name in an environment config (.env or similar)