-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoload.php
More file actions
61 lines (52 loc) · 2.23 KB
/
autoload.php
File metadata and controls
61 lines (52 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
/**
* autoload.php has been Psalm level 1 tested according to setting in psalm.xml at root.
* i.e on the command line run e.g c:\wamp64\www\invoice>php ./vendor/bin/psalm autoload.php
*
* Result:
* ------------------------------
* No errors found!
* ------------------------------
*
* In addition, session related $_ENV variables are saved to server related $_SERVER variables and
* can be viewed under the application's debug mode menu's FAQ's Php Details? Variables
*/
$autoloadPath = __DIR__ . '/vendor/autoload.php';
if (!file_exists($autoloadPath)) {
fwrite(
STDERR,
"Dependencies not found. Please run 'composer install' in the project directory first.\n" .
"If Composer is not installed, visit https://getcomposer.org/download/ for instructions.\n"
);
exit(1);
}
require_once $autoloadPath;
// Only attempt to use Dotenv if the class exists (in case dependencies are not fully installed)
if (class_exists('Dotenv\Dotenv')) {
/** @var class-string<\Dotenv\Dotenv> $dotenvClass */
$dotenvClass = 'Dotenv\Dotenv';
$dotenv = $dotenvClass::createImmutable(__DIR__);
$dotenv->load();
} else {
fwrite(STDERR, "Dotenv not found. Ensure your Composer dependencies are installed.\n");
exit(1);
}
// Safely parse and mirror important environment variables
$_ENV['YII_ENV'] = isset($_ENV['YII_ENV']) && strlen($_ENV['YII_ENV']) > 0 ? $_ENV['YII_ENV'] : null;
$_SERVER['YII_ENV'] = $_ENV['YII_ENV'];
$_ENV['YII_DEBUG'] = isset($_ENV['YII_DEBUG']) && strlen($_ENV['YII_DEBUG']) > 0
? filter_var($_ENV['YII_DEBUG'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
: false;
$_SERVER['YII_DEBUG'] = $_ENV['YII_DEBUG'];
$_ENV['BUILD_DATABASE'] = isset($_ENV['BUILD_DATABASE']) && strlen($_ENV['BUILD_DATABASE']) > 0
? filter_var($_ENV['BUILD_DATABASE'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)
: false;
$_SERVER['BUILD_DATABASE'] = $_ENV['BUILD_DATABASE'];
/**
* Building the database takes longer than usual and the .env $_ENV['BUILD_DATABASE'] should be set to false afterwards
* https://stackoverflow.com/questions/3829403/how-to-increase-the-execution-timeout-in-php
*/
if ($_SERVER['BUILD_DATABASE']) {
ini_set('max_execution_time', '360');
}