Completed
Push — master ( d9f04e...3eb62a )
by Arman
21s queued 11s
created

Bootstrap::loadCoreFuncations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.0.0
13
 */
14
15
namespace Quantum;
16
17
use Quantum\Exceptions\StopExecutionException;
18
use Quantum\Libraries\Storage\FileSystem;
19
use Quantum\Environment\Environment;
20
use Quantum\Libraries\Config\Config;
21
use Quantum\Routes\ModuleLoader;
22
use Quantum\Libraries\Lang\Lang;
23
use Quantum\Environment\Server;
24
use Quantum\Http\HttpRequest;
25
use Quantum\Mvc\MvcManager;
26
use Quantum\Routes\Router;
27
use Quantum\Loader\Loader;
28
use Quantum\Http\Response;
29
use Quantum\Http\Request;
30
use Quantum\Di\Di;
31
32
/**
33
 * Bootstrap Class
34
 * Bootstrap is the base class which is runner of all necessary components of framework.
35
 */
36
class Bootstrap
37
{
38
39
    /**
40
     * Boots the framework.
41
     * @throws \Exception|StopExecutionException
42
     */
43
    public static function run()
44
    {
45
        try {
46
47
            self::loadCoreFuncations();
48
49
            Di::loadDefinitions();
50
51
            $loader = Di::get(Loader::class);
52
53
            $fs = Di::get(FileSystem::class);
54
55
            Environment::getInstance()->load($loader);
56
57
            HttpRequest::init(new Server);
58
59
            $request = Di::get(Request::class);
60
            $response = Di::get(Response::class);
61
62
            $router = new Router($request, $response);
63
64
            ModuleLoader::loadModulesRoutes($router, $fs);
65
66
            $router->findRoute();
67
68
            Config::getInstance()->load($loader);
69
70
            $loader->loadDir(base_dir() . DS . 'helpers');
71
            $loader->loadDir(base_dir() . DS . 'libraries');
72
73
            Lang::getInstance()
74
                    ->setLang($request->getSegment(config()->get('lang_segment')))
75
                    ->load($loader, $fs);
76
77
            MvcManager::runMvc($request, $response);
78
79
            $response->send();
80
            exit(0);
0 ignored issues
show
Best Practice introduced by
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...
81
        } catch (StopExecutionException $e) {
82
            $response->send();
83
        } catch (\Exception $e) {
84
            echo $e->getMessage();
85
            exit(1);
0 ignored issues
show
Best Practice introduced by
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...
86
        }
87
    }
88
89
    public static function loadCoreFuncations()
90
    {
91
        foreach (glob(HELPERS_DIR . DS . 'functions' . DS . '*.php') as $filename) {
92
            require_once $filename;
93
        }
94
    }
95
96
}
97