From 1ae683ab85b78fcf24b14debac1b2a2ed205c7a8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Tue, 23 Feb 2021 20:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=90=E8=97=8F=E6=AD=A3=E5=BC=8F=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Error.php | 19 +++++++++++++++++++ Core/Model.php | 3 ++- public/index.php | 16 +++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Core/Error.php b/Core/Error.php index e95ec56..a7cbb24 100644 --- a/Core/Error.php +++ b/Core/Error.php @@ -10,6 +10,22 @@ namespace Core; class Error { + /** + * Error handler. Convert all errors to Exceptions by throwing an ErrorException. + * + * @param int $level Error level + * @param string $message Error message + * @param string $file Filename the error was raised in + * @param int $line Line number in the file + * + * @return void + */ + public static function errorHandlerNone($level, $message, $file, $line) + { + echo "Handler captured error $level: '$message'" . PHP_EOL; + } + + /** * Error handler. Convert all errors to Exceptions by throwing an ErrorException. * @@ -63,4 +79,7 @@ class Error View::renderTemplate("$code.html"); } } + public static function exceptionHandlerNone($exception){ + + } } diff --git a/Core/Model.php b/Core/Model.php index 0116a54..8072edb 100644 --- a/Core/Model.php +++ b/Core/Model.php @@ -50,7 +50,8 @@ abstract class Model PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, ); static $db = null; - + $option=array(); + $timeout=time() + 20; if ($db === null) { $dsn = 'mysql:host=' . Config::DB_HOST . ';dbname=' . Config::DB_NAME . ';charset=utf8'; try { diff --git a/public/index.php b/public/index.php index 1120f65..730a3d2 100644 --- a/public/index.php +++ b/public/index.php @@ -7,14 +7,24 @@ /** * Composer */ + require dirname(__DIR__) . '/vendor/autoload.php'; require dirname(__DIR__) . '/App/Config.php'; + + /** * Error and Exception handling */ -error_reporting(E_ALL); -set_error_handler('Core\Error::errorHandler'); -set_exception_handler('Core\Error::exceptionHandler'); +if($_SERVER['HTTP_HOST'] == '127.0.0.1'){ + error_reporting(E_ALL); + set_error_handler('Core\Error::errorHandler'); + set_exception_handler('Core\Error::exceptionHandler'); +}else{ + error_reporting(0); + set_error_handler('Core\Error::errorHandlerNone'); + set_exception_handler('Core\Error::exceptionHandlerNone'); +} + /** * Routing */