Completed
Push — master ( e76e8a...6b7664 )
by Alexey
05:29
created

init.php ➔ idn_to_utf8()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
1
<?php
2
3
/**
4
 * Start system core
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
session_start();
12
13
define('INJI_DOMAIN_NAME', $_SERVER['SERVER_NAME']);
14
15
spl_autoload_register(function($class_name) {
16
    if (file_exists(INJI_SYSTEM_DIR . '/Inji/' . $class_name . '.php')) {
17
        include_once INJI_SYSTEM_DIR . '/Inji/' . $class_name . '.php';
18
    }
19
});
20
21
//load core
22
Inji::$inst = new Inji();
23
Inji::$config = Config::system();
24
Inji::$inst->listen('Config-change-system', 'systemConfig', function($event) {
25
    Inji::$config = $event['eventObject'];
26
});
27
spl_autoload_register('Router::findClass');
28
29
$apps = Apps\App::getList();
30
//Make default app params
31
$finalApp = [
32
    'name' => INJI_DOMAIN_NAME,
33
    'dir' => INJI_DOMAIN_NAME,
34
    'installed' => false,
35
    'default' => true,
36
    'route' => INJI_DOMAIN_NAME,
37
];
38
foreach ($apps as $app) {
39
    if ($app->default) {
40
        $finalApp = $app->_params;
41
    }
42
    if (preg_match("!{$app->route}!i", INJI_DOMAIN_NAME)) {
43
        $finalApp = $app->_params;
44
        break;
45
    }
46
}
47
App::$cur = new App($finalApp);
48
49
$params = Tools::uriParse($_SERVER['REQUEST_URI']);
50
51
App::$cur->type = 'app';
52
App::$cur->path = INJI_PROGRAM_DIR . '/' . App::$cur->dir;
53
App::$cur->params = $params;
54
App::$cur->config = Config::app(App::$cur);
55
App::$primary = App::$cur;
56
57
if (!empty($params[0]) && file_exists(INJI_SYSTEM_DIR . '/program/' . $params[0] . '/')) {
58
59
    App::$primary->params = [];
60
61
    App::$cur = new App();
62
    App::$cur->name = $params[0];
63
    App::$cur->system = true;
64
    App::$cur->staticPath = "/" . App::$cur->name . "/static";
65
    App::$cur->templatesPath = "/" . App::$cur->name . "/static/templates";
66
    App::$cur->path = INJI_SYSTEM_DIR . '/program/' . App::$cur->name;
67
    App::$cur->type = 'app' . ucfirst(strtolower(App::$cur->name));
68
    App::$cur->installed = true;
69
    App::$cur->params = array_slice($params, 1);
70
    App::$cur->config = Config::app(App::$cur);
71
72
    Inji::$inst->listen('Config-change-app-' . App::$primary->name, 'primaryAppConfig', function($event) {
73
        App::$primary->config = $event['eventObject'];
74
    });
75
}
76
Inji::$inst->listen('Config-change-app-' . App::$cur->name, 'curAppConfig', function($event) {
77
    App::$cur->config = $event['eventObject'];
78
});
79
$shareConfig = Config::share();
80
if (empty($shareConfig['installed']) && App::$cur->name != 'setup' && (empty(App::$cur->params[0]) || App::$cur->params[0] != 'static')) {
81
    Tools::redirect('/setup');
82
}
83
putenv('COMPOSER_HOME=' . getcwd());
84
putenv('COMPOSER_CACHE_DIR=' . getcwd() . DIRECTORY_SEPARATOR . 'composerCache');
85
ComposerCmd::check();
86
if (!function_exists('idn_to_utf8')) {
87
    ComposerCmd::requirePackage("mabrahamde/idna-converter", "dev-master", './');
88
    function idn_to_utf8($domain)
89
    {
90
        if (empty(Inji::$storage['IdnaConvert'])) {
91
            Inji::$storage['IdnaConvert'] = new \idna_convert(array('idn_version' => 2008));
92
        }
93
        return Inji::$storage['IdnaConvert']->decode($domain);
94
    }
95
96
}
97
if (file_exists('vendor/autoload.php')) {
98
    include_once 'vendor/autoload.php';
99
}
100
if (file_exists(App::$primary->path . '/vendor/autoload.php')) {
101
    include_once App::$primary->path . '/vendor/autoload.php';
102
}
103
Module::$cur = Module::resolveModule(App::$cur);
104
105
if (Module::$cur === null) {
106
    INJI_SYSTEM_ERROR('Module not found', true);
107
}
108
109
Controller::$cur = Module::$cur->findController();
110
if (Controller::$cur === null) {
111
    INJI_SYSTEM_ERROR('Controller not found', true);
112
}
113 View Code Duplication
if (!empty(App::$primary->config['autoloadModules'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    foreach (App::$primary->config['autoloadModules'] as $module) {
115
        App::$cur->$module;
116
    }
117
}
118 View Code Duplication
if (App::$primary !== App::$cur) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
    foreach (App::$cur->config['autoloadModules'] as $module) {
120
        App::$cur->$module;
121
    }
122
}
123
Controller::$cur->run();
124