<?php

// deployer extended buffering request code START
// Buffering php requests
isset($_SERVER['HTTP_X_DEPLOYER_DEPLOYMENT']) && $_SERVER['HTTP_X_DEPLOYER_DEPLOYMENT'] == 'a268ae680039e8ea703b28e742c39789' ? $deployerExtendedEnableBufferLock = false: $deployerExtendedEnableBufferLock = true;
isset($_ENV['DEPLOYER_DEPLOYMENT']) && $_ENV['DEPLOYER_DEPLOYMENT'] == 'a268ae680039e8ea703b28e742c39789' ? $deployerExtendedEnableBufferLock = false: $deployerExtendedEnableBufferLock = true;
clearstatcache(true, __DIR__ . '/.flag.requestbuffer');
while (file_exists(__DIR__ . '/.flag.requestbuffer') && $deployerExtendedEnableBufferLock) {
    usleep(200000);
    clearstatcache(true);
    if(time() - @filectime(__DIR__ . '/.flag.requestbuffer') > 60) @unlink(__DIR__ . '/.flag.requestbuffer');
}
// Clearstatcache for n seconds after deployclearstatcache(true, __DIR__ . '/.flag.clearstatcache')
if (file_exists(__DIR__ . '/.flag.clearstatcache')) {
    clearstatcache(true);
    if(time() - @filectime(__DIR__ . '/.flag.clearstatcache') > 150) @unlink(__DIR__ . '/.flag.clearstatcache');
}
// Action if php choose old release to serve requestclearstatcache(true, __DIR__ . '/.flag.oldrelease')
if(file_exists(__DIR__ . '/.flag.oldrelease')) {
    clearstatcache(true);
    usleep(1000000);
    if(!empty($_SERVER['REQUEST_SCHEME']) && !empty($_SERVER['SERVER_NAME'])) {
      header('Location: ' . $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '', true, 307);
    } else {
      exit();
    }
}
// deployer extended buffering request code END



/*
 * This file is part of the TYPO3 CMS project.
 *
 * 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.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

// Set up the application for the frontend
call_user_func(static function () {
    $classLoader = require dirname(__DIR__).'/vendor/autoload.php';
    \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(0, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_FE);
    \TYPO3\CMS\Core\Core\Bootstrap::init($classLoader)->get(\TYPO3\CMS\Frontend\Http\Application::class)->run();
});
