<?php

$customChanges = [
  'BE' => [
      'installToolPassword' => $_ENV['TYPO3_BE_INSTALL_TOOL_PASSWORD'],
  ],
  'DB' => [
      'Connections' => [
          'Default' => [
              'dbname' => $_ENV['TYPO3_DB_NAME'],
              'host' => $_ENV['TYPO3_DB_HOST'],
              'password' => $_ENV['TYPO3_DB_PASSWORD'],
              'port' => $_ENV['TYPO3_DB_PORT'],
              'user' => $_ENV['TYPO3_DB_USER'],
              'unix_socket' => $_ENV['TYPO3_DB_UNIX_SOCKET'],
          ],
      ],
      'extTablesDefinitionScript' => 'extTables.php',
  ],
  'MAIL' => [
      'transport' => $_ENV['TYPO3_MAIL_TRANSPORT'],
      'transport_smtp_server' => $_ENV['TYPO3_MAIL_SMTP_SERVER'],
      'transport_smtp_encrypt' => $_ENV['TYPO3_MAIL_SMTP_ENCRYPT'],
      'transport_smtp_username' => $_ENV['TYPO3_MAIL_SMTP_USER'],
      'transport_smtp_password' => $_ENV['TYPO3_MAIL_SMTP_PASSWORD'],
  ],
  'SYS' => [
    'caching' => [
      'cacheConfigurations' => [
        'hash' => [
          'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend',
        ],
        'imagesizes' => [
          'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend',
          'options' => [
            'compression' => true,
          ],
        ],
        'pages' => [
          'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend',
          'options' => [
            'compression' => true,
          ],
        ],
        'rootline' => [
          'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend',
          'options' => [
            'compression' => true,
          ],
        ],
      ],
    ],
  ],
];


\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript(
    'developmentConfiguration',
    'setup',
    'config.contentObjectExceptionHandler = 0'
);

// MAIL
// $GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport'] = 'mbox';
// $GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_mbox_file'] = dirname(__DIR__, 2).'/mbox';
$GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_path'] = '/usr/bin/';
//
$GLOBALS['TYPO3_CONF_VARS'] = array_replace_recursive($GLOBALS['TYPO3_CONF_VARS'], $customChanges);

$context = strtolower((string)\TYPO3\CMS\Core\Core\Environment::getContext());

$contextParts = explode('/', $context);
$dir = realpath(__DIR__);

$file = $dir . '/additional_' . $contextParts[0] . '.php';
if (is_file($file)) {
    include_once($file);
}

if (isset($contextParts[1])) {
    $file = $dir . '/additional_' . $contextParts[0] . '_' . $contextParts[1] . '.php';
    if (is_file($file)) {
        include_once($file);
    }
}
