Skip to content

Commit

Permalink
Merge pull request #26 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
nguyenanhung authored Oct 16, 2020
2 parents a25a002 + d7894b7 commit d01e324
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 127 deletions.
114 changes: 114 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<?php
require_once __DIR__ . '/vendor/autoload.php'; // Current Package test, remove if init other package
require_once __DIR__ . '/functions.php';

use nguyenanhung\MyDebug\Debug;

// Test Content
$logPath = testLogPath();
$logSubPath = 'tests-debug-2';
$logFilename = 'Log-' . date('Y-m-d') . '.log';
$name = 'Test';
$msg = 'Test Log lan 2';
$context = [
'name' => 'Nguyen An Hung',
'email' => '[email protected]'
];
// 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
<?php
require_once __DIR__ . '/vendor/autoload.php'; // Current Package test, remove if init other package
require_once __DIR__ . '/functions.php';

use nguyenanhung\MyDebug\Benchmark;

$benchmark = new Benchmark();
/***************************** SIMPLE BENCHMARKING BY CI *****************************/
$benchmark->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
<?php
require_once __DIR__ . '/vendor/autoload.php'; // Current Package test, remove if init other package
require_once __DIR__ . '/functions.php';

use nguyenanhung\MyDebug\Manager\File;

$file = new File();
$file->setExclude(['*.zip']);
$file->setInclude(['*.log']);
d($file->getVersion());

$path = testLogPath();

d($file->scanAndZip($path, 3));
```

## Utils
```php
<?php
require_once __DIR__ . '/vendor/autoload.php'; // Current Package test, remove if init other package
require_once __DIR__ . '/functions.php';

use nguyenanhung\MyDebug\Utils;

$utils = new Utils();
$str = 'Nguyễn An Hưng';

d($utils->getVersion());
d($utils::slugify($str));
d($utils::convert_vi_to_en($str));
```

## Support
If any question & request, please contact following information

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"alchemy/zippy": "^0.4"
},
"require-dev": {
"ext-zip": "*",
"kint-php/kint": "^3.0"
},
"suggest": {
Expand Down
19 changes: 10 additions & 9 deletions src/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @copyright: 713uk13m <[email protected]>
*/
public function __construct()
{
}
/***************************** SIMPLE BENCHMARKING BY CI *****************************/

/**
* List of all benchmark markers
*
Expand All @@ -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
*/
Expand All @@ -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
Expand Down Expand Up @@ -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';
}
}
63 changes: 0 additions & 63 deletions src/BenchmarkInterface.php

This file was deleted.

9 changes: 5 additions & 4 deletions src/Manager/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @since 2018-10-17
* @version 0.1.2.5
*/
class Utils implements ProjectInterface, UtilsInterface
class Utils implements ProjectInterface
{
use Version;

Expand Down
49 changes: 0 additions & 49 deletions src/UtilsInterface.php

This file was deleted.

0 comments on commit d01e324

Please sign in to comment.