diff --git a/README.md b/README.md index 41826cd..1afb1b0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,119 @@ +[![Latest Stable Version](https://poser.pugx.org/nguyenanhung/my-debug/v)](https://packagist.org/packages/nguyenanhung/my-debug) +[![Latest Unstable Version](https://poser.pugx.org/nguyenanhung/my-debug/v/unstable)](https://packagist.org/packages/nguyenanhung/my-debug) +[![Total Downloads](https://poser.pugx.org/nguyenanhung/my-debug/downloads)](https://packagist.org/packages/nguyenanhung/my-debug) +[![License](https://poser.pugx.org/nguyenanhung/my-debug/license)](https://packagist.org/packages/nguyenanhung/my-debug) +[![Monthly Downloads](https://poser.pugx.org/nguyenanhung/my-debug/d/monthly)](https://packagist.org/packages/nguyenanhung/my-debug) +[![Daily Downloads](https://poser.pugx.org/nguyenanhung/my-debug/d/daily)](https://packagist.org/packages/nguyenanhung/my-debug) +[![composer.lock](https://poser.pugx.org/nguyenanhung/my-debug/composerlock)](https://packagist.org/packages/nguyenanhung/my-debug) + # My Debug +## Debug +```php + 'Nguyen An Hung', + 'email' => 'dev@nguyenanhung.com' +]; +// Call +$debug = new Debug(); +$debug->setDebugStatus(TRUE); +$debug->setGlobalLoggerLevel(NULL); +$debug->setLoggerPath($logPath); +$debug->setLoggerSubPath($logSubPath); +$debug->setLoggerFilename($logFilename); +$debug->__construct(); +echo "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; +echo "\n getVersion: " . $debug->getVersion() . "\n"; +echo "\n setDebugStatus: " . $debug->getDebugStatus() . "\n"; +echo "\n setLoggerPath: " . $debug->getLoggerPath() . "\n"; +echo "\n setLoggerSubPath: " . $debug->getLoggerSubPath() . "\n"; +echo "\n setLoggerFilename: " . $debug->getLoggerFilename() . "\n"; +echo "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; + +d($debug->debug($name, $msg . ' - DEBUG', $context)); +d($debug->info($name, $msg . ' - INFO', $context)); +d($debug->notice($name, $msg . ' - NOTICE', $context)); +d($debug->warning($name, $msg . ' - WARNING', $context)); +d($debug->error($name, $msg . ' - ERROR', $context)); +d($debug->critical($name, $msg . ' - CRITICAL', $context)); +d($debug->alert($name, $msg . ' - ALERT', $context)); +d($debug->emergency($name, $msg . ' - EMERGENCY', $context)); +``` + +## Benchmark +```php +mark('code_start'); +$mathFunctions = ["abs", "acos", "asin", "atan", "bindec", "floor", "exp", "sin", "tan", "pi", "is_finite", "is_nan", + "sqrt"]; +$count = 9999; +for ($i = 0; $i < $count; $i++) { + foreach ($mathFunctions as $key => $function) { + call_user_func_array($function, [$i]); + echo ($key + 1) . " -> " . $function . "\n"; + } +} +$benchmark->mark('code_end'); + +d($benchmark->getVersion()); +d($benchmark->elapsed_time('code_start', 'code_end')); +d($benchmark->memory_usage()); +/***************************** SIMPLE BENCHMARKING BY CI *****************************/ +``` + +## Manage File +```php +setExclude(['*.zip']); +$file->setInclude(['*.log']); +d($file->getVersion()); + +$path = testLogPath(); + +d($file->scanAndZip($path, 3)); +``` + +## Utils +```php +getVersion()); +d($utils::slugify($str)); +d($utils::convert_vi_to_en($str)); +``` + ## Support If any question & request, please contact following information diff --git a/composer.json b/composer.json index 0810363..2afec23 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,7 @@ "alchemy/zippy": "^0.4" }, "require-dev": { + "ext-zip": "*", "kint-php/kint": "^3.0" }, "suggest": { diff --git a/src/Benchmark.php b/src/Benchmark.php index 6c07dc6..6432a74 100644 --- a/src/Benchmark.php +++ b/src/Benchmark.php @@ -21,17 +21,20 @@ * @since 2018-10-17 * @version 0.1.2.5 */ -class Benchmark implements ProjectInterface, BenchmarkInterface +class Benchmark implements ProjectInterface { use Version; /** * Benchmark constructor. + * + * @author : 713uk13m + * @copyright: 713uk13m */ public function __construct() { } - /***************************** SIMPLE BENCHMARKING BY CI *****************************/ + /** * List of all benchmark markers * @@ -45,7 +48,7 @@ public function __construct() * Multiple calls to this function can be made so that several * execution points can be timed. * - * @param string $name Marker name + * @param string $name Marker name * * @return void */ @@ -64,9 +67,9 @@ public function mark($name) * execution time to be shown in a template. The output class will * swap the real value for this variable. * - * @param string $point1 A particular marked point - * @param string $point2 A particular marked point - * @param int $decimals Number of decimal places + * @param string $point1 A particular marked point + * @param string $point2 A particular marked point + * @param int $decimals Number of decimal places * * @return string Calculated elapsed time on success, * an '{elapsed_string}' if $point1 is empty @@ -99,8 +102,6 @@ public function elapsed_time($point1 = '', $point2 = '', $decimals = 4) */ public function memory_usage() { - $memory = round(memory_get_usage() / 1024 / 1024, 2) . 'MB'; - - return $memory; + return round(memory_get_usage() / 1024 / 1024, 2) . 'MB'; } } diff --git a/src/BenchmarkInterface.php b/src/BenchmarkInterface.php deleted file mode 100644 index 733a1db..0000000 --- a/src/BenchmarkInterface.php +++ /dev/null @@ -1,63 +0,0 @@ - - * Date: 10/13/18 - * Time: 11:04 - */ - -namespace nguyenanhung\MyDebug; - -/** - * Interface BenchmarkInterface - * - * @category Interface - * @package nguyenanhung\MyDebug - * @author 713uk13m - * @copyright 713uk13m - */ -interface BenchmarkInterface -{ - /** - * Set a benchmark marker - * - * Multiple calls to this function can be made so that several - * execution points can be timed. - * - * @param string $name Marker name - * - * @return void - */ - public function mark($name); - - /** - * Elapsed time - * - * Calculates the time difference between two marked points. - * - * If the first parameter is empty this function instead returns the - * {elapsed_time} pseudo-variable. This permits the full system - * execution time to be shown in a template. The output class will - * swap the real value for this variable. - * - * @param string $point1 A particular marked point - * @param string $point2 A particular marked point - * @param int $decimals Number of decimal places - * - * @return string Calculated elapsed time on success, - * an '{elapsed_string}' if $point1 is empty - * or an empty string if $point1 is not found. - */ - public function elapsed_time($point1 = '', $point2 = '', $decimals = 4); - - /** - * Function memory_usage - * - * @author: 713uk13m - * @time : 10/13/18 10:52 - * - * @return string - */ - public function memory_usage(); -} diff --git a/src/Manager/File.php b/src/Manager/File.php index cde3837..a088c84 100644 --- a/src/Manager/File.php +++ b/src/Manager/File.php @@ -33,6 +33,7 @@ class File extends Filesystem { const VERSION = '1.0.0'; + /** @var null|array Mảng dữ liệu chứa các thuộc tính cần quét */ private $scanInclude = ['*.log', '*.txt']; /** @var null|array Mảng dữ liệu chứa các thuộc tính bỏ qua không quét */ @@ -143,8 +144,8 @@ public function cleanLog($path = '', $dayToDelete = 3) $dateTime = new DateTime("-" . $dayToDelete . " days"); $deleteTime = $dateTime->format($format); // Lấy modifyTime của file - $getfileTime = filemtime($filename); - $fileTime = date($format, $getfileTime); + $getFileTime = filemtime($filename); + $fileTime = date($format, $getFileTime); if ($fileTime < $deleteTime) { $this->chmod($filename, 0777); $this->remove($filename); @@ -233,8 +234,8 @@ public function scanAndZip($scanPath = '', $dayToZip = 3, $zipPath = '') $SplFileInfo = new SplFileInfo($fileName); $filename = $SplFileInfo->getPathname(); // Lấy modifyTime của file - $getfileTime = filemtime($filename); - $fileTime = date($format, $getfileTime); + $getFileTime = filemtime($filename); + $fileTime = date($format, $getFileTime); if ($fileTime < $zipTime) { if (!file_exists($zipPath)) { $this->mkdir($zipPath); diff --git a/src/ProjectInterface.php b/src/ProjectInterface.php index f6c598c..576ad65 100644 --- a/src/ProjectInterface.php +++ b/src/ProjectInterface.php @@ -18,7 +18,7 @@ */ interface ProjectInterface { - const VERSION = '2.0.0'; + const VERSION = '2.0.0.1'; /** * Hàm lấy thông tin phiên bản Packages diff --git a/src/Utils.php b/src/Utils.php index 946d0e2..2118ceb 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -22,7 +22,7 @@ * @since 2018-10-17 * @version 0.1.2.5 */ -class Utils implements ProjectInterface, UtilsInterface +class Utils implements ProjectInterface { use Version; diff --git a/src/UtilsInterface.php b/src/UtilsInterface.php deleted file mode 100644 index bc8d268..0000000 --- a/src/UtilsInterface.php +++ /dev/null @@ -1,49 +0,0 @@ - - * Date: 9/30/18 - * Time: 17:10 - */ - -namespace nguyenanhung\MyDebug; - -/** - * Interface UtilsInterface - * - * @category Interface - * @package nguyenanhung\MyDebug - * @author 713uk13m - * @copyright 713uk13m - */ -interface UtilsInterface -{ - /** - * Function slugify - * - * @author: 713uk13m - * @time : 10/7/18 03:16 - * - * @param string $str String to Slug - * - * @return mixed String as Slug - */ - public static function slugify($str = ''); - - /** - * Function convert_vi_to_en - * - * Hàm chuyển đổi ký tự từ tiếng Việt, - * và các ký tự đặc biệt sang ký tự không dấu - * - * Sử dụng trong trường hợp class slugify nó không chạy - * - * @author: 713uk13m - * @time : 10/13/18 01:17 - * - * @param string $str Chuỗi ký tự đầu vào - * - * @return mixed|string Đầu ra rà 1 chuỗi ký tự - */ - public static function convert_vi_to_en($str = ''); -}