From 45a3c35ed986614efb6957fdbeecb71860a2af1d Mon Sep 17 00:00:00 2001 From: 713uk13m <713uk13m@713uk13ms-MacBook-Pro.local> Date: Sun, 17 Feb 2019 19:47:45 +0700 Subject: [PATCH] update new version --- classmap.php | 37 ------------------------- composer.json.dist | 58 ---------------------------------------- src/Debug.php | 21 +++++++++++---- src/ProjectInterface.php | 2 +- src/Utils.php | 10 +++++++ test/test_benchmark.php | 1 - test/test_debug.php | 1 - test/test_file.php | 1 - test/test_utils.php | 1 - 9 files changed, 27 insertions(+), 105 deletions(-) delete mode 100644 classmap.php delete mode 100644 composer.json.dist diff --git a/classmap.php b/classmap.php deleted file mode 100644 index bae9117..0000000 --- a/classmap.php +++ /dev/null @@ -1,37 +0,0 @@ - - * Date: 9/19/18 - * Time: 13:37 - */ -spl_autoload_register(function ($className) { - $className = ltrim($className, '\\'); - $fileName = ''; - if ($lastNsPos = strripos($className, '\\')) { - $namespace = substr($className, 0, $lastNsPos); - $className = substr($className, $lastNsPos + 1); - $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; - } - $fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php'; - // - if (strpos($fileName, 'nguyenanhung\MyDebug\Interfaces') !== FALSE) { - $fileName = str_replace('nguyenanhung\MyDebug\Interfaces', 'src\Interfaces', $fileName); - } elseif (strpos($fileName, 'nguyenanhung\MyDebug\Repository') !== FALSE) { - $fileName = str_replace('nguyenanhung\MyDebug\Repository', 'src\Repository', $fileName); - } elseif (strpos($fileName, 'nguyenanhung\MyDebug\Helpers') !== FALSE) { - $fileName = str_replace('nguyenanhung\MyDebug\Helpers', 'src\Helpers', $fileName); - } elseif (strpos($fileName, 'nguyenanhung\MyDebug\Manager') !== FALSE) { - $fileName = str_replace('nguyenanhung\MyDebug\Manager', 'src\Manager', $fileName); - } else { - $fileName = str_replace('nguyenanhung\MyDebug', 'src', $fileName); - } - - if (file_exists($fileName)) { - require $fileName; - - return TRUE; - } - - return FALSE; -}); diff --git a/composer.json.dist b/composer.json.dist deleted file mode 100644 index 47e173b..0000000 --- a/composer.json.dist +++ /dev/null @@ -1,58 +0,0 @@ -{ - "name": "nguyenanhung/my-debug", - "type": "library", - "description": "My Debug, Logger Library", - "keywords": [ - "debug", - "logger", - "log" - ], - "homepage": "https://github.com/nguyenanhung/my-debug", - "license": "GPL-3.0", - "authors": [ - { - "name": "Nguyen An Hung", - "email": "dev@nguyenanhung.com", - "homepage": "https://nguyenanhung.com", - "role": "Developer" - } - ], - "require": { - "ext-json": "*", - "monolog/monolog": "^1.23", - "cocur/slugify": "^1.4.1", - "theseer/directoryscanner": "^1.3", - "symfony/process": "^3.4.17", - "symfony/filesystem": "^3.4.17", - "symfony/polyfill": "^1.9.0", - "doctrine/collections": "1.3.0", - "alchemy/zippy": "^0.4.9" - }, - "require-dev": { - "kint-php/kint": "^3.0" - }, - "suggest": { - "ext-curl": "Needed to support cURL", - "ext-json": "Needed to support JSON", - "ext-iconv": "Needed to support ICONV", - "ext-mbstring": "Needed to support MbString", - "ext-openssl": "Needed to support OpenSSL" - }, - "autoload": { - "psr-4": { - "nguyenanhung\\MyDebug\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" - } - }, - "config": { - "process-timeout": 0 - }, - "scripts": { - "start": "php -S localhost:8080 -t public", - "test": "phpunit" - } -} diff --git a/src/Debug.php b/src/Debug.php index b5998b0..9c2d7df 100644 --- a/src/Debug.php +++ b/src/Debug.php @@ -205,6 +205,8 @@ public function setLoggerFilename($loggerFilename = '') { if (!empty($loggerFilename)) { $this->loggerFilename = trim($loggerFilename); + } else { + $this->loggerFilename = 'Log-' . date('Y-m-d') . '.log'; } return $this; @@ -239,6 +241,8 @@ public function setLoggerDateFormat($loggerDateFormat = NULL) { if (!empty($loggerDateFormat) && is_string($loggerDateFormat)) { $this->loggerDateFormat = $loggerDateFormat; + } else { + $this->loggerDateFormat = "Y-m-d H:i:s u"; } return $this; @@ -274,6 +278,8 @@ public function setLoggerLineFormat($loggerLineFormat = NULL) { if (!empty($loggerLineFormat) && is_string($loggerLineFormat)) { $this->loggerLineFormat = $loggerLineFormat; + } else { + $this->loggerLineFormat = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; } return $this; @@ -300,6 +306,11 @@ public function log($level = '', $name = 'log', $msg = 'My Message', $context = $level = strtolower(trim($level)); if ($this->DEBUG == TRUE) { if (!class_exists('\Monolog\Logger')) { + if (function_exists('log_message')) { + $errorMsg = 'Không tồn tại class Monolog'; + log_message('error', $errorMsg); + } + return FALSE; } try { @@ -308,7 +319,7 @@ public function log($level = '', $name = 'log', $msg = 'My Message', $context = if (empty($this->loggerFilename)) { $this->loggerFilename = 'Log-' . date('Y-m-d') . '.log'; } - $listLevel = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency']; + $listLevel = array('debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'); if ( // Tồn tại Global Logger Level isset($this->globalLoggerLevel) && @@ -351,8 +362,8 @@ public function log($level = '', $name = 'log', $msg = 'My Message', $context = $keyLevel = \Monolog\Logger::WARNING; } $loggerFilename = $this->loggerPath . DIRECTORY_SEPARATOR . $loggerSubPath . DIRECTORY_SEPARATOR . $this->loggerFilename; - $dateFormat = $this->loggerDateFormat ? $this->loggerDateFormat : "Y-m-d H:i:s u"; - $output = $this->loggerLineFormat ? $this->loggerLineFormat : "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; + $dateFormat = !empty($this->loggerDateFormat) ? $this->loggerDateFormat : "Y-m-d H:i:s u"; + $output = !empty($this->loggerLineFormat) ? $this->loggerLineFormat : "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; $formatter = new \Monolog\Formatter\LineFormatter($output, $dateFormat); $stream = new \Monolog\Handler\StreamHandler($loggerFilename, $keyLevel, self::LOG_BUBBLE, self::FILE_PERMISSION); $stream->setFormatter($formatter); @@ -368,12 +379,12 @@ public function log($level = '', $name = 'log', $msg = 'My Message', $context = } } catch (\Exception $e) { - $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage(); if (function_exists('log_message')) { + $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage(); log_message('error', $message); } - return $message; + return FALSE; } } diff --git a/src/ProjectInterface.php b/src/ProjectInterface.php index 4c79654..0ac4680 100644 --- a/src/ProjectInterface.php +++ b/src/ProjectInterface.php @@ -18,7 +18,7 @@ */ interface ProjectInterface { - const VERSION = '0.1.3'; + const VERSION = '0.1.4'; /** * Hàm lấy thông tin phiên bản Packages diff --git a/src/Utils.php b/src/Utils.php index a31e9bc..44d9863 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -47,6 +47,11 @@ public function __construct() public static function slugify($str = '') { if (!class_exists('\Cocur\Slugify\Slugify')) { + if (function_exists('log_message')) { + $message = 'Không tồn tại class Slugify'; + log_message('error', $message); + } + return self::convert_vi_to_en($str); } try { @@ -55,6 +60,11 @@ public static function slugify($str = '') return $slugify->slugify($str); } catch (\Exception $e) { + if (function_exists('log_message')) { + $message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage(); + log_message('error', $message); + } + return self::convert_vi_to_en($str); } } diff --git a/test/test_benchmark.php b/test/test_benchmark.php index 7764dc3..32af9ca 100644 --- a/test/test_benchmark.php +++ b/test/test_benchmark.php @@ -1,6 +1,5 @@