108 lines
2.8 KiB
PHP
108 lines
2.8 KiB
PHP
<?php
|
|
|
|
// ========== PATHS ==========
|
|
|
|
define('ROOT_PATH', dirname(dirname(__DIR__)));
|
|
define('APP_PATH', ROOT_PATH.'/app');
|
|
define('VAR_PATH', ROOT_PATH.'/var');
|
|
|
|
// ========== PHP (static) ==========
|
|
|
|
// Charset
|
|
ini_set('default_charset', 'UTF-8');
|
|
date_default_timezone_set('Europe/Moscow');
|
|
|
|
if (5 === PHP_MAJOR_VERSION && PHP_MINOR_VERSION < 6) {
|
|
iconv_set_encoding('internal_encoding', 'UTF-8');
|
|
ini_set('mbstring.internal_encoding', 'UTF-8');
|
|
}
|
|
|
|
// ========== COMPOSER ==========
|
|
|
|
require ROOT_PATH.'/../vendor/autoload.php';
|
|
|
|
// ========== CONFIGURATION ==========
|
|
$development = false;
|
|
$config_file = APP_PATH . '/src/config.php';
|
|
if (file_exists(APP_PATH . '/src/config.local.php')) {
|
|
$config_file = APP_PATH . '/src/config.local.php';
|
|
$development = true;
|
|
}
|
|
|
|
$config = require $config_file;
|
|
|
|
$sessionStarts = 1;
|
|
$setOnlineCall = 1;
|
|
|
|
// Autoload, common variables and functions
|
|
require_once ROOT_PATH . '/../../config_common.php';
|
|
|
|
|
|
// Get Access-Token
|
|
$headers = apache_request_headers();
|
|
if (isset($headers['Access-Token'])) {
|
|
session_id(trim($headers['Access-Token']));
|
|
}
|
|
|
|
// Start session
|
|
if ($sessionStarts) {
|
|
session_start([
|
|
'name' => "PHPSESSID",
|
|
'cookie_lifetime' => 0,
|
|
'gc_maxlifetime' => 5401,
|
|
]);
|
|
}
|
|
|
|
// ========== PHP (from configuration) ==========
|
|
|
|
// Time zone
|
|
if ($config['PHP']['default_timezone'])
|
|
date_default_timezone_set($config['PHP']['default_timezone']);
|
|
else
|
|
date_default_timezone_set('Europe/Moscow');
|
|
|
|
// Errors
|
|
if ($config['PHP']['display_errors'])
|
|
ini_set('display_errors', $config['PHP']['display_errors']);
|
|
else
|
|
error_reporting(0);
|
|
|
|
if ($config['PHP']['display_startup_errors'])
|
|
ini_set('display_startup_errors', $config['PHP']['display_startup_errors']);
|
|
|
|
if ($config['PHP']['log_errors'])
|
|
ini_set('log_errors', $config['PHP']['log_errors']);
|
|
|
|
ini_set('error_log', VAR_PATH.'/log/php-'.date('Y-m').'.log');
|
|
|
|
unset($config['PHP']);
|
|
|
|
// ========== SLIM ==========
|
|
|
|
$app = new \Slim\Slim($config['Slim']);
|
|
$app->start_time = microtime(true);
|
|
$app->config('app', $config['App']);
|
|
$app->view()->setData('config', $app->config('app'));
|
|
|
|
require APP_PATH.'/src/dependencies.php';
|
|
require APP_PATH.'/src/middlewares.php';
|
|
require APP_PATH.'/src/routes.php';
|
|
|
|
// Error handler
|
|
$app->error(function (\Exception $e) use ($app) {
|
|
$app->getLog()->error($e);
|
|
$app->render('errors/error.twig');
|
|
});
|
|
|
|
// CORS for development env
|
|
if ($development) {
|
|
header("Access-Control-Allow-Origin: *");
|
|
header('Access-Control-Allow-Credentials: true');
|
|
header('Access-Control-Max-Age: 0');
|
|
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
header('Access-Control-Allow-Headers: X-Debug, X-Requested-With, Content-Type, Accept, Origin, Authorization, Access-Token');
|
|
header('Access-Control-Expose-Headers: Authorization, Access-Token');
|
|
}
|
|
|
|
$app->run();
|