injitools /
cms-Inji
| 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 | include_once INJI_SYSTEM_DIR . '/Inji/Inji.php'; |
||||
| 14 | include_once INJI_SYSTEM_DIR . '/Inji/Router.php'; |
||||
| 15 | include_once INJI_SYSTEM_DIR . '/Inji/Router/Folder.php'; |
||||
| 16 | include_once INJI_SYSTEM_DIR . '/Inji/Router/Path.php'; |
||||
| 17 | |||||
| 18 | spl_autoload_register('Inji\Router::findClass'); |
||||
| 19 | |||||
| 20 | Inji\Router::addPath(INJI_SYSTEM_DIR . '/Inji/', 'Inji\\'); |
||||
| 21 | Inji\Router::addPath(INJI_SYSTEM_DIR . '/modules/', 'Inji\\', 10); |
||||
| 22 | Inji\Router::addPath(INJI_SYSTEM_DIR . '/modules/', 'Inji\\', 20, 1, ['models', 'objects', 'controllers']); |
||||
| 23 | |||||
| 24 | //load core |
||||
| 25 | Inji::$inst = new Inji(); |
||||
| 26 | Inji::$config = Inji\Config::system(); |
||||
| 27 | Inji::$inst->listen('Config-change-system', 'systemConfig', function ($event) { |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 28 | Inji::$config = $event['eventObject']; |
||||
| 29 | return $event['eventObject']; |
||||
| 30 | }); |
||||
| 31 | |||||
| 32 | |||||
| 33 | putenv('COMPOSER_HOME=' . getcwd()); |
||||
| 34 | putenv('COMPOSER_CACHE_DIR=' . getcwd() . DIRECTORY_SEPARATOR . 'cache/composer'); |
||||
| 35 | Inji\ComposerCmd::check(); |
||||
| 36 | if (!function_exists('idn_to_utf8')) { |
||||
| 37 | Inji\ComposerCmd::requirePackage("mabrahamde/idna-converter", "dev-master", '.'); |
||||
| 38 | |||||
| 39 | function idn_to_utf8($domain) { |
||||
| 40 | if (empty(Inji::$storage['IdnaConvert'])) { |
||||
| 41 | Inji::$storage['IdnaConvert'] = new \idna_convert(array('idn_version' => 2008)); |
||||
|
0 ignored issues
–
show
The type
idna_convert was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 42 | } |
||||
| 43 | return Inji::$storage['IdnaConvert']->decode($domain); |
||||
| 44 | } |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | Inji\BowerCmd::check(); |
||||
| 48 | |||||
| 49 | if (file_exists('vendor/autoload.php')) { |
||||
| 50 | include 'vendor/autoload.php'; |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | $domain = idn_to_utf8($_SERVER['SERVER_NAME']); |
||||
| 54 | if (strpos($domain, 'www.') === 0) { |
||||
| 55 | $domain = substr($domain, 4); |
||||
| 56 | } |
||||
| 57 | define('INJI_DOMAIN_NAME', $domain); |
||||
| 58 | |||||
| 59 | |||||
| 60 | //Make default app params |
||||
| 61 | $finalApp = [ |
||||
| 62 | 'name' => INJI_DOMAIN_NAME, |
||||
| 63 | 'dir' => INJI_DOMAIN_NAME, |
||||
| 64 | 'installed' => false, |
||||
| 65 | 'default' => true, |
||||
| 66 | 'route' => INJI_DOMAIN_NAME, |
||||
| 67 | ]; |
||||
| 68 | Inji\App::$primary = Inji\App::$cur = new Inji\App($finalApp); |
||||
| 69 | $apps = Inji\Apps\App::connection('injiStorage')->setDbOption('share', true)->getList(); |
||||
| 70 | foreach ($apps as $app) { |
||||
| 71 | if ($app->default) { |
||||
| 72 | $finalApp = $app->_params; |
||||
| 73 | } |
||||
| 74 | if (preg_match("!{$app->route}!i", INJI_DOMAIN_NAME)) { |
||||
| 75 | $finalApp = $app->_params; |
||||
| 76 | break; |
||||
| 77 | } |
||||
| 78 | } |
||||
| 79 | Inji\App::$cur = new Inji\App($finalApp); |
||||
| 80 | $params = Inji\Tools::uriParse($_SERVER['REQUEST_URI']); |
||||
| 81 | |||||
| 82 | Inji\App::$cur->type = 'app'; |
||||
| 83 | Inji\App::$cur->path = INJI_PROGRAM_DIR . '/' . Inji\App::$cur->dir; |
||||
| 84 | Inji\App::$cur->params = $params; |
||||
| 85 | Inji\App::$cur->config = Inji\Config::app(Inji\App::$cur); |
||||
| 86 | if (!Inji\App::$cur->namespace) { |
||||
| 87 | Inji\App::$cur->namespace = ucfirst(Inji\App::$cur->name); |
||||
| 88 | } |
||||
| 89 | Inji\App::$primary = Inji\App::$cur; |
||||
| 90 | |||||
| 91 | if (!empty($params[0]) && file_exists(INJI_SYSTEM_DIR . '/program/' . $params[0] . '/')) { |
||||
| 92 | |||||
| 93 | Inji\App::$primary->params = []; |
||||
| 94 | |||||
| 95 | Inji\App::$cur = new Inji\App(); |
||||
| 96 | Inji\App::$cur->name = $params[0]; |
||||
| 97 | Inji\App::$cur->namespace = 'Inji\\' . ucfirst($params[0]); |
||||
| 98 | Inji\App::$cur->system = true; |
||||
| 99 | Inji\App::$cur->staticPath = "/" . Inji\App::$cur->name . "/static"; |
||||
| 100 | Inji\App::$cur->templatesPath = "/" . Inji\App::$cur->name . "/static/templates"; |
||||
| 101 | Inji\App::$cur->path = INJI_SYSTEM_DIR . '/program/' . Inji\App::$cur->name; |
||||
| 102 | Inji\App::$cur->type = 'app' . ucfirst(strtolower(Inji\App::$cur->name)); |
||||
| 103 | Inji\App::$cur->installed = true; |
||||
| 104 | Inji\App::$cur->params = array_slice($params, 1); |
||||
| 105 | Inji\App::$cur->config = Inji\Config::app(Inji\App::$cur); |
||||
| 106 | |||||
| 107 | Inji::$inst->listen('Config-change-app-' . Inji\App::$primary->name, 'primaryAppConfig', function ($event) { |
||||
|
0 ignored issues
–
show
function(...) { /* ... */ } of type callable is incompatible with the type string|array|closure expected by parameter $callback of Inji::listen().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 108 | Inji\App::$primary->config = $event['eventObject']; |
||||
| 109 | return $event['eventObject']; |
||||
| 110 | }); |
||||
| 111 | |||||
| 112 | Inji\Router::addPath(Inji\App::$cur->path . '/objects/', Inji\App::$cur->namespace . '\\', 60); |
||||
| 113 | Inji\Router::addPath(Inji\App::$cur->path . '/modules/', Inji\App::$cur->namespace . '\\', 70); |
||||
| 114 | Inji\Router::addPath(Inji\App::$cur->path . '/modules/', Inji\App::$cur->namespace . '\\', 80, 2, ['models', 'objects', 'controllers']); |
||||
| 115 | |||||
| 116 | } |
||||
| 117 | if (!empty(Inji\App::$primary->namespace)) { |
||||
| 118 | Inji\Router::addPath(Inji\App::$primary->path . '/objects/', Inji\App::$primary->namespace . '\\', 30); |
||||
| 119 | Inji\Router::addPath(Inji\App::$primary->path . '/modules/', Inji\App::$primary->namespace . '\\', 40); |
||||
| 120 | Inji\Router::addPath(Inji\App::$primary->path . '/modules/', Inji\App::$primary->namespace . '\\', 50, 1, ['models', 'objects', 'controllers']); |
||||
| 121 | } |
||||
| 122 | Inji\App::$cur->log = new Inji\Log(); |
||||
|
0 ignored issues
–
show
|
|||||
| 123 | Inji\App::$cur->log->run = defined('LOG_ENABLED'); |
||||
|
0 ignored issues
–
show
The property
log does not exist on Inji\App. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||
| 124 | Inji::$inst->listen('Config-change-app-' . Inji\App::$cur->name, 'curAppConfig', function ($event) { |
||||
|
0 ignored issues
–
show
function(...) { /* ... */ } of type callable is incompatible with the type string|array|closure expected by parameter $callback of Inji::listen().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 125 | Inji\App::$cur->config = $event['eventObject']; |
||||
| 126 | return $event['eventObject']; |
||||
| 127 | }); |
||||
| 128 | $shareConfig = Inji\Config::share(); |
||||
| 129 | if (empty($shareConfig['installed']) && Inji\App::$cur->name != 'setup' && (empty(Inji\App::$cur->params[0]) || Inji\App::$cur->params[0] != 'static')) { |
||||
| 130 | Inji\Tools::redirect('/setup'); |
||||
| 131 | } |
||||
| 132 | Inji\Module::$cur = Inji\Module::resolveModule(Inji\App::$cur); |
||||
| 133 | |||||
| 134 | if (Inji\Module::$cur === null) { |
||||
| 135 | INJI_SYSTEM_ERROR('Module not found', true); |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | Inji\Controller::$cur = Inji\Module::$cur->findController(); |
||||
| 139 | if (Inji\Controller::$cur === null) { |
||||
| 140 | INJI_SYSTEM_ERROR('Controller not found', true); |
||||
| 141 | } |
||||
| 142 | if (!empty(Inji\App::$primary->config['autoloadModules'])) { |
||||
| 143 | foreach (Inji\App::$primary->config['autoloadModules'] as $module) { |
||||
| 144 | Inji\App::$cur->$module; |
||||
| 145 | } |
||||
| 146 | } |
||||
| 147 | if (Inji\App::$primary !== Inji\App::$cur) { |
||||
| 148 | foreach (Inji\App::$cur->config['autoloadModules'] as $module) { |
||||
| 149 | Inji\App::$cur->$module; |
||||
| 150 | } |
||||
| 151 | } |
||||
| 152 | Inji\Controller::$cur->run(); |
||||
| 153 |