/** * Подключение к MySQL */ public function init($connect_options) { extract($connect_options); if (isset($db_name)) { $this->db_name = $db_name; } if (isset($encoding)) { $this->encoding = $encoding; } if (isset($table_prefix)) { $this->table_prefix = $table_prefix; } if (isset($noConnectAbort)) { $this->noConnectAbort = $noConnectAbort; } $dsn = "mysql:host={$host};port={$port};dbname={$db_name};charset={$encoding}"; $dt = new \DateTime(); $offset = $dt->format("P"); $opt = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, \PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = '{$offset}'"); $this->pdo = new \PDO($dsn, $user, $pass, $opt); $error = $this->pdo->errorInfo(); if ((int) $error[0]) { if ($this->noConnectAbort) { return false; } else { INJI_SYSTEM_ERROR($error[2], true); } } else { $this->connect = true; return true; } }
/** * Run controller */ public function run() { if (!empty($this->params[0]) && method_exists($this, $this->params[0] . 'Action')) { $this->method = $this->params[0]; $this->params = array_slice($this->params, 1); } elseif (!method_exists($this, $this->method . 'Action')) { INJI_SYSTEM_ERROR('method not found', true); } if (!$this->checkAccess()) { $msg = !empty($this->module->app->access->config['access']['accessTree'][App::$cur->type]['msg']) ? $this->module->app->access->config['access']['accessTree'][App::$cur->type]['msg'] : 'У вас нет прав доступа'; Tools::redirect($this->access->getDeniedRedirect(), $msg); } $this->run = true; call_user_func_array([$this, $this->method . 'Action'], $this->params); }
setlocale(LC_ALL, 'ru_RU.UTF-8', 'rus_RUS.UTF-8', 'Russian_Russia.65001'); setlocale(LC_NUMERIC, 'C'); //default timezone date_default_timezone_set('Asia/Krasnoyarsk'); // time start define('INJI_TIME_START', microtime(true)); // system files dir define('INJI_SYSTEM_DIR', __DIR__ . '/system'); // apps files dir define('INJI_PROGRAM_DIR', __DIR__ . '/program'); // check base config if (!file_exists(INJI_SYSTEM_DIR) || !is_dir(INJI_SYSTEM_DIR)) { INJI_SYSTEM_ERROR('Error in base config: INJI_SYSTEM_DIR not correct', true); } if (!file_exists(INJI_PROGRAM_DIR) || !is_dir(INJI_PROGRAM_DIR)) { INJI_SYSTEM_ERROR('Error in base config: INJI_PROGRAM_DIR not correct', true); } foreach ($_SERVER as $key => $item) { if (strpos($key, 'HTTP_AUTHORIZATION') !== false) { $auth = explode(':', base64_decode(substr($item, 6))); $_SERVER['PHP_AUTH_USER'] = $auth[0]; $_SERVER['PHP_AUTH_PW'] = isset($auth[1]) ? $auth[1] : ''; } } require_once INJI_SYSTEM_DIR . '/init.php'; /** * System error messages */ function INJI_SYSTEM_ERROR($msg, $fatal = false) { if ($fatal) {
if (empty(Inji::$storage['IdnaConvert'])) { Inji::$storage['IdnaConvert'] = new \idna_convert(array('idn_version' => 2008)); } return Inji::$storage['IdnaConvert']->decode($domain); } } if (file_exists('vendor/autoload.php')) { include_once 'vendor/autoload.php'; } if (file_exists(App::$primary->path . '/vendor/autoload.php')) { include_once App::$primary->path . '/vendor/autoload.php'; } Module::$cur = Module::resolveModule(App::$cur); if (Module::$cur === null) { INJI_SYSTEM_ERROR('Module not found', true); } Controller::$cur = Module::$cur->findController(); if (Controller::$cur === null) { INJI_SYSTEM_ERROR('Controller not found', true); } if (!empty(App::$primary->config['autoloadModules'])) { foreach (App::$primary->config['autoloadModules'] as $module) { App::$cur->{$module}; } } if (App::$primary !== App::$cur) { foreach (App::$cur->config['autoloadModules'] as $module) { App::$cur->{$module}; } } Controller::$cur->run();