summaryrefslogtreecommitdiff
path: root/init.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-09 19:40:17 +0300
commitf7bfdf58def6aadc922e1632f407d1418269a0d7 (patch)
treed7a0b2819e6a26c11d40ee0b27267ea827fbb345 /init.php
initial
Diffstat (limited to 'init.php')
-rw-r--r--init.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/init.php b/init.php
new file mode 100644
index 0000000..6d9f5f0
--- /dev/null
+++ b/init.php
@@ -0,0 +1,69 @@
+<?php
+
+error_reporting(E_ALL);
+ini_set('display_errors', 1);
+date_default_timezone_set('Europe/Moscow');
+
+mb_internal_encoding('UTF-8');
+mb_regex_encoding('UTF-8');
+
+define('ROOT', __DIR__);
+define('START_TIME', microtime(true));
+
+set_include_path(get_include_path().PATH_SEPARATOR.ROOT);
+
+spl_autoload_register(function($class) {
+ if (str_ends_with($class, 'Exception')) {
+ $path = ROOT.'/engine/exceptions/'.$class.'.php';
+ } else if (in_array($class, ['MySQLConnection', 'SQLiteConnection', 'CommonDatabase'])) {
+ $path = ROOT.'/engine/database/'.$class.'.php';
+ } else if (str_starts_with($class, 'handler\\')) {
+ $path = ROOT.'/'.str_replace('\\', '/', $class).'.php';
+ }
+
+ if (isset($path)) {
+ if (!is_file($path))
+ return;
+ } else {
+ foreach (['engine', 'lib', 'model'] as $dir) {
+ if (is_file($path = ROOT.'/'.$dir.'/'.$class.'.php'))
+ break;
+ }
+ }
+
+ require_once $path;
+});
+
+$config = require_once 'config.php';
+if (file_exists(ROOT.'/config-local.php')) {
+ $config = array_replace($config, require 'config-local.php');
+}
+
+// turn off errors output on production domains
+
+require_once 'functions.php';
+
+if (PHP_SAPI == 'cli') {
+ $_SERVER['HTTP_HOST'] = $config['domain'];
+ $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+} else {
+ if (array_key_exists('HTTP_X_REAL_IP', $_SERVER))
+ $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
+}
+
+if (!$config['is_dev']) {
+ if (file_exists(ROOT.'/config-static.php'))
+ $config['static'] = require_once 'config-static.php';
+ else
+ die('confic-static.php not found');
+}
+
+if (!$config['is_dev']) {
+ error_reporting(0);
+ ini_set('display_errors', 0);
+}
+
+logging::setLogFile($config['log_file']);
+logging::enable();
+
+require 'vendor/autoload.php';