Skip to content

Commit d7e4124

Browse files
713uk13m713uk13m
authored andcommitted
Add simple BackgroundRequest
1 parent 974d4a9 commit d7e4124

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/BackgroundRequest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace nguyenanhung\MyRequests;
1111

12+
use nguyenanhung\MyDebug\Debug;
13+
use nguyenanhung\MyDebug\Benchmark;
1214
use nguyenanhung\MyRequests\Interfaces\BackgroundRequestInterface;
1315
use nguyenanhung\MyRequests\Interfaces\ProjectInterface;
1416

@@ -21,11 +23,75 @@
2123
*/
2224
class BackgroundRequest implements ProjectInterface, BackgroundRequestInterface
2325
{
26+
/**
27+
* @var object \nguyenanhung\MyDebug\Benchmark
28+
*/
29+
private $benchmark;
30+
/**
31+
* @var object \nguyenanhung\MyDebug\Debug Call to class
32+
*/
33+
private $debug;
34+
/**
35+
* Set Debug Status
36+
*
37+
* @var bool
38+
*/
39+
public $debugStatus = FALSE;
40+
41+
/**
42+
* @var null Set level Debug: DEBUG, INFO, ERROR ....
43+
*/
44+
public $debugLevel = NULL;
45+
46+
/**
47+
* Set Logger Path to Save
48+
*
49+
* @var null|string
50+
*/
51+
public $debugLoggerPath = NULL;
52+
53+
/**
54+
* Set Logger Filename to Save
55+
*
56+
* @var string
57+
*/
58+
public $debugLoggerFilename;
59+
2460
/**
2561
* BackgroundRequest constructor.
2662
*/
2763
public function __construct()
2864
{
65+
if (self::USE_BENCHMARK === TRUE) {
66+
$this->benchmark = new Benchmark();
67+
$this->benchmark->mark('code_start');
68+
}
69+
$this->debug = new Debug();
70+
if (empty($this->debugLoggerPath)) {
71+
$this->debugStatus = FALSE;
72+
}
73+
$this->debug->setDebugStatus($this->debugStatus);
74+
$this->debug->setGlobalLoggerLevel($this->debugLevel);
75+
$this->debug->setLoggerPath($this->debugLoggerPath);
76+
$this->debug->setLoggerSubPath(__CLASS__);
77+
if (empty($this->debugLoggerFilename)) {
78+
$this->debugLoggerFilename = 'Log-' . date('Y-m-d') . '.log';
79+
}
80+
$this->debug->setLoggerFilename($this->debugLoggerFilename);
81+
$this->debug->debug(__FUNCTION__, '/-------------------------> Begin Logger - My Background Request - Version: ' . self::VERSION . ' - Last Modified: ' . self::LAST_MODIFIED . ' <-------------------------\\');
82+
}
83+
84+
/**
85+
* BackgroundRequest destructor.
86+
*/
87+
public function __destruct()
88+
{
89+
if (self::USE_BENCHMARK === TRUE) {
90+
$this->benchmark->mark('code_end');
91+
$this->debug->debug(__FUNCTION__, 'Elapsed Time: ===> ' . $this->benchmark->elapsed_time('code_start', 'code_end'));
92+
$this->debug->debug(__FUNCTION__, 'Memory Usage: ===> ' . $this->benchmark->memory_usage());
93+
}
94+
$this->debug->debug(__FUNCTION__, '/-------------------------> End Logger - My Background Request - Version: ' . self::VERSION . ' - Last Modified: ' . self::LAST_MODIFIED . ' <-------------------------\\');
2995
}
3096

3197
/**

src/Interfaces/ProjectInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
interface ProjectInterface
2020
{
21-
const VERSION = '0.1.3.8';
22-
const LAST_MODIFIED = '2018-10-13';
21+
const VERSION = '0.1.3.9';
22+
const LAST_MODIFIED = '2018-10-16';
2323
const MIN_PHP_VERSION = '5.3';
2424
const GET = 'GET';
2525
const HEAD = 'HEAD';

0 commit comments

Comments
 (0)