injitools /
cms-Inji
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
1 ignored issue
–
show
|
|||
| 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 | if (!function_exists('idn_to_utf8')) { |
||
| 30 | function idn_to_utf8($domain) |
||
| 31 | { |
||
| 32 | if (empty(Inji::$storage['IdnaConvert'])) { |
||
| 33 | Inji::$storage['IdnaConvert'] = new IdnaConvert(); |
||
| 34 | } |
||
| 35 | return Inji::$storage['IdnaConvert']->decode($domain); |
||
| 36 | } |
||
| 37 | |||
| 38 | } |
||
| 39 | |||
| 40 | $apps = Apps\App::getList(); |
||
| 41 | //Make default app params |
||
| 42 | $finalApp = [ |
||
| 43 | 'name' => INJI_DOMAIN_NAME, |
||
| 44 | 'dir' => INJI_DOMAIN_NAME, |
||
| 45 | 'installed' => false, |
||
| 46 | 'default' => true, |
||
| 47 | 'route' => INJI_DOMAIN_NAME, |
||
| 48 | ]; |
||
| 49 | foreach ($apps as $app) { |
||
| 50 | if ($app->default) { |
||
| 51 | $finalApp = $app->_params; |
||
| 52 | } |
||
| 53 | if (preg_match("!{$app->route}!i", INJI_DOMAIN_NAME)) { |
||
| 54 | $finalApp = $app->_params; |
||
| 55 | break; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | App::$cur = new App($finalApp); |
||
| 59 | |||
| 60 | $params = Tools::uriParse($_SERVER['REQUEST_URI']); |
||
| 61 | |||
| 62 | App::$cur->type = 'app'; |
||
| 63 | App::$cur->path = INJI_PROGRAM_DIR . '/' . App::$cur->dir; |
||
| 64 | App::$cur->params = $params; |
||
| 65 | App::$cur->config = Config::app(App::$cur); |
||
| 66 | App::$primary = App::$cur; |
||
| 67 | |||
| 68 | if (!empty($params[0]) && file_exists(INJI_SYSTEM_DIR . '/program/' . $params[0] . '/')) { |
||
| 69 | |||
| 70 | App::$primary->params = []; |
||
| 71 | |||
| 72 | App::$cur = new App(); |
||
| 73 | App::$cur->name = $params[0]; |
||
| 74 | App::$cur->system = true; |
||
| 75 | App::$cur->staticPath = "/" . App::$cur->name . "/static"; |
||
| 76 | App::$cur->templatesPath = "/" . App::$cur->name . "/static/templates"; |
||
| 77 | App::$cur->path = INJI_SYSTEM_DIR . '/program/' . App::$cur->name; |
||
| 78 | App::$cur->type = 'app' . ucfirst(strtolower(App::$cur->name)); |
||
| 79 | App::$cur->installed = true; |
||
| 80 | App::$cur->params = array_slice($params, 1); |
||
| 81 | App::$cur->config = Config::app(App::$cur); |
||
| 82 | |||
| 83 | Inji::$inst->listen('Config-change-app-' . App::$primary->name, 'primaryAppConfig', function($event) { |
||
| 84 | App::$primary->config = $event['eventObject']; |
||
| 85 | }); |
||
| 86 | } |
||
| 87 | Inji::$inst->listen('Config-change-app-' . App::$cur->name, 'curAppConfig', function($event) { |
||
| 88 | App::$cur->config = $event['eventObject']; |
||
| 89 | }); |
||
| 90 | $shareConfig = Config::share(); |
||
| 91 | if (empty($shareConfig['installed']) && App::$cur->name != 'setup' && (empty(App::$cur->params[0]) || App::$cur->params[0] != 'static')) { |
||
| 92 | Tools::redirect('/setup'); |
||
| 93 | } |
||
| 94 | putenv('COMPOSER_HOME=' . getcwd()); |
||
| 95 | ComposerCmd::check(); |
||
| 96 | if (file_exists(App::$primary->path . '/vendor/autoload.php')) { |
||
| 97 | include_once App::$primary->path . '/vendor/autoload.php'; |
||
| 98 | } |
||
| 99 | Module::$cur = Module::resolveModule(App::$cur); |
||
| 100 | |||
| 101 | if (Module::$cur === null) { |
||
| 102 | INJI_SYSTEM_ERROR('Module not found', true); |
||
| 103 | } |
||
| 104 | |||
| 105 | Controller::$cur = Module::$cur->findController(); |
||
| 106 | if (Controller::$cur === null) { |
||
| 107 | INJI_SYSTEM_ERROR('Controller not found', true); |
||
| 108 | } |
||
| 109 | View Code Duplication | if (!empty(App::$primary->config['autoloadModules'])) { |
|
| 110 | foreach (App::$primary->config['autoloadModules'] as $module) { |
||
| 111 | App::$cur->$module; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | View Code Duplication | if (App::$primary !== App::$cur) { |
|
| 115 | foreach (App::$cur->config['autoloadModules'] as $module) { |
||
| 116 | App::$cur->$module; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | Controller::$cur->run(); |
||
| 120 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.