|
9 | 9 |
|
10 | 10 | namespace nguyenanhung\MyRequests; |
11 | 11 |
|
| 12 | +use nguyenanhung\MyDebug\Debug; |
| 13 | +use nguyenanhung\MyDebug\Benchmark; |
12 | 14 | use nguyenanhung\MyRequests\Interfaces\BackgroundRequestInterface; |
13 | 15 | use nguyenanhung\MyRequests\Interfaces\ProjectInterface; |
14 | 16 |
|
|
21 | 23 | */ |
22 | 24 | class BackgroundRequest implements ProjectInterface, BackgroundRequestInterface |
23 | 25 | { |
| 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 | + |
24 | 60 | /** |
25 | 61 | * BackgroundRequest constructor. |
26 | 62 | */ |
27 | 63 | public function __construct() |
28 | 64 | { |
| 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 . ' <-------------------------\\'); |
29 | 95 | } |
30 | 96 |
|
31 | 97 | /** |
|
0 commit comments