<?php
include __DIR__ . '/../app/config/config.php';
include __DIR__ . '/../app/config/loader.php';
include __DIR__ . '/../app/config/di.php';
include __DIR__ . '/../../vendor/autoload.php';

try {
	$app = new \Phalcon\Mvc\Application($di);
	$app->handle($_SERVER['REQUEST_URI'])->send();
} catch (Exception $e) {
	$err = "********************************************************\n[T] \t" . date('Y-m-d H:i:s') . "\n[F] \t" . $e->getFile() . ' : ' . $e->getLine() . "\n[C] \t" . $e->getCode() . "\n[M] \t" . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
	!is_dir(DIR_LOG . APP_NAME) && mkdir(DIR_LOG . APP_NAME, 0777, true);
	file_put_contents(DIR_LOG . APP_NAME . '/' . date('Y_m_d') . '.log', $err, FILE_APPEND);

    header('HTTP/2.0 400');
	die(json_encode(['code' => 400, 'msg' => $e->getMessage(), 'data' => ''], 320));
}

