From 46bf95821552c3803faaa98f2015d7f38f7bd159 Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 12 Aug 2016 17:59:14 +0800 Subject: [PATCH] set default timezone when boot up --- app/Services/Application.php | 27 ++++++++++++++++++++++++++- app/Services/Boot.php | 33 ++++++--------------------------- app/Services/Utils.php | 2 -- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/app/Services/Application.php b/app/Services/Application.php index 64db3c71..afd2d8a7 100644 --- a/app/Services/Application.php +++ b/app/Services/Application.php @@ -11,7 +11,32 @@ class Application */ public function run() { - Boot::start(); + // Load Aliases + Boot::loadServices(); + + // Check Runtime Environment + Boot::checkRuntimeEnv(); + + // Set Default Timezone to UTC+8 + Boot::setTimeZone(); + + // Load dotenv Configuration + Boot::loadDotEnv(BASE_DIR); + + // Register Error Handler + Boot::registerErrorHandler(); + + // Boot Eloquent ORM + Boot::bootEloquent(Config::getDbConfig()); + + // Redirect if not installed + Boot::checkInstallation(); + + // Start Session + Boot::startSession(); + + // Start Route Dispatching + Boot::bootRouter(); } /** diff --git a/app/Services/Boot.php b/app/Services/Boot.php index 1c5ffed1..84bbd4e6 100644 --- a/app/Services/Boot.php +++ b/app/Services/Boot.php @@ -9,33 +9,6 @@ use App\Exceptions\E; class Boot { - public static function start() - { - // Load Aliases - self::loadServices(); - - // Check Runtime Environment - self::checkRuntimeEnv(); - - // Load dotenv Configuration - self::loadDotEnv(BASE_DIR); - - // Register Error Handler - self::registerErrorHandler(); - - // Boot Eloquent ORM - self::bootEloquent(Config::getDbConfig()); - - // Redirect if not installed - self::checkInstallation(); - - // Start Session - self::startSession(); - - // Start Route Dispatching - self::bootRouter(); - } - public static function loadDotEnv($dir) { if (Config::checkDotEnvExist()) { @@ -44,6 +17,12 @@ class Boot } } + public static function setTimeZone($timezone = 'Asia/Shanghai') + { + // set default time zone, UTC+8 for default + date_default_timezone_set($timezone); + } + public static function checkRuntimeEnv() { Config::checkPHPVersion(); diff --git a/app/Services/Utils.php b/app/Services/Utils.php index bb14aa35..be0a1bdf 100644 --- a/app/Services/Utils.php +++ b/app/Services/Utils.php @@ -44,8 +44,6 @@ class Utils public static function getTimeFormatted($timestamp = 0) { - // set default time zone to UTC+8 - date_default_timezone_set('Asia/Shanghai'); return ($timestamp == 0) ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', $timestamp); }