Issues (536)

src/Initializer/bootstrap.php (3 issues)

1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
use BlitzPHP\Container\Services;
13
use BlitzPHP\Core\Application;
14
use BlitzPHP\Loader\DotEnv;
15
16
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
17
18
// Se rassurer que le dossier courant pointe sur le dossier du front controller
19
if (! defined('TEST_PATH')) {
20
    // On doit aussi verifier qu'on n'est pas en phase de test, sinon khalan ne trouvera pas le dossier des specs
21
    chdir(WEBROOT);
0 ignored issues
show
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
22
}
23
24
return function (array $paths, string $paths_config_file, bool $is_cli): void {
25
    // Le chemin d'accès vers le dossier de l'application
26
    if (is_dir($paths['app'])) {
27
        if (($_temp = realpath($paths['app'])) !== false) {
28
            $paths['app'] = $_temp;
29
        } else {
30
            $paths['app'] = strtr(rtrim($paths['app'], '/\\'), '/\\', DS . DS);
31
        }
32
    } else {
33
        header('HTTP/1.1 503 Service Unavailable.', true, 503);
34
        echo 'Your application folder path does not appear to be set correctly. ';
35
        echo 'Please open the following file and correct this: "' . $paths_config_file . '"';
36
37
        exit(3); // EXIT_CONFIG
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
38
    }
39
40
    // Le chemin d'accès vers le dossier de stockage des fichiers
41
    if (is_dir($paths['storage'])) {
42
        if (($_temp = realpath($paths['storage'])) !== false) {
43
            $paths['storage'] = $_temp;
44
        } else {
45
            $paths['storage'] = strtr(rtrim($paths['storage'], '/\\'), '/\\', DS . DS);
46
        }
47
    } elseif (is_dir($paths['app'] . $paths['storage'] . DS)) {
48
        $paths['storage'] = $paths['app'] . strtr(trim($paths['storage'], '/\\'), '/\\', DS . DS);
49
    } else {
50
        header('HTTP/1.1 503 Service Unavailable.', true, 503);
51
        echo 'Your storage folder path does not appear to be set correctly. ';
52
        echo 'Please open the following file and correct this: "' . $paths_config_file . '"';
53
54
        exit(3); // EXIT_CONFIG
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
55
    }
56
57
    /**
58
     * Chemin vers le framework
59
     */
60
    defined('SYST_PATH') || define('SYST_PATH', dirname(__DIR__) . DS);
61
62
    /**
63
     * Chemin d'acces du dossier "vendor"
64
     */
65
    defined('VENDOR_PATH') || define('VENDOR_PATH', dirname(SYST_PATH, 3) . DS);
66
67
    /**
68
     * Chemin vers l'application
69
     */
70
    defined('APP_PATH') || define('APP_PATH', realpath($paths['app']) . DS);
71
72
    /**
73
     * Chemin vers le dossier de stockage
74
     */
75
    defined('STORAGE_PATH') || define('STORAGE_PATH', realpath($paths['storage']) . DS);
76
77
    if (file_exists(APP_PATH . 'Config' . DS . 'constants.php')) {
78
        require_once APP_PATH . 'Config' . DS . 'constants.php';
79
    }
80
    require_once SYST_PATH . 'Constants' . DS . 'constants.php';
81
82
    /**
83
     * On charge le helper `common` qui est utilisé par le framework et presque toutes les applications
84
     */
85
    require_once SYST_PATH . 'Helpers' . DS . 'common.php';
86
87
    /**
88
     * On initialise le parsing du fichier .env
89
     */
90
    DotEnv::init(ROOTPATH);
91
92
    // Initialise et enregistre le loader avec la pile SPL autoloader.
93
    Services::autoloader()->initialize()->register();
94
    Services::autoloader()->loadHelpers();
95
96
    /**
97
     * Initialisation de Kint
98
     */
99
    require_once __DIR__ . DS . 'kint.php';
100
101
    /**
102
     * Lancement de l'application
103
     */
104
    $app = new Application();
105
    $app->init();
106
107
    if (! $is_cli) {
108
        $app->run();
109
    }
110
};
111