1<?php
2/*
3 * vim:set softtabstop=4 shiftwidth=4 expandtab:
4 *
5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
6 * Copyright 2001 - 2020 Ampache.org
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22
23declare(strict_types=0);
24
25namespace Ampache\Config;
26
27use Ampache\Module\Util\Environment;
28use Ampache\Module\Util\EnvironmentInterface;
29use Psr\Container\ContainerInterface;
30use RuntimeException;
31
32// Register autoloaders
33$composer_autoload = __DIR__ . '/../../vendor/autoload.php';
34
35if (file_exists($composer_autoload) === false) {
36    throw new RuntimeException('Composer autoload file not found - please run `composer install`');
37}
38
39require_once $composer_autoload;
40
41/** @var ContainerInterface $dic */
42$dic = require __DIR__ . '/DicBuilder.php';
43
44// Core includes we can't do with the autoloader
45require_once __DIR__ . '/functions.php';
46
47$environment = $dic->get(EnvironmentInterface::class);
48
49// Do a check for the minimum required php version because nothing will work without it
50if ($environment->check_php_version() === false) {
51    throw new RuntimeException(
52        sprintf('Ampache requires PHP version >= %s', Environment::PHP_VERSION)
53    );
54}
55
56//error_reporting(E_ERROR); // Only show fatal errors in production
57
58AmpConfig::set('load_time_begin', microtime(true));
59
60// We still allow scripts to run (it could be the purpose of the maintenance)
61if ($environment->isCli() === false) {
62    if (file_exists(__DIR__ . '/../../.maintenance')) {
63        require_once  __DIR__ . '/../../.maintenance';
64    }
65}
66
67// Merge GET then POST into REQUEST effectively stripping COOKIE without
68// depending on a PHP setting change for the effect
69$_REQUEST = array_merge($_GET, $_POST);
70
71return $dic;
72