1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Webino (http://webino.sk) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/webino for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk) |
7
|
|
|
* @author Peter Bačinský <[email protected]> |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace WebinoAppLib\Service; |
12
|
|
|
|
13
|
|
|
use Tracy\Debugger as Tracy; |
14
|
|
|
use Tracy\IBarPanel; |
15
|
|
|
use WebinoAppLib\Options\DebuggerOptions; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Debugger |
19
|
|
|
*/ |
20
|
|
|
class Debugger implements DebuggerInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var DebuggerOptions |
24
|
|
|
*/ |
25
|
|
|
private $options; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param array|DebuggerOptions $options |
29
|
|
|
*/ |
30
|
|
|
public function __construct($options = null) |
31
|
|
|
{ |
32
|
|
|
$options instanceof DebuggerOptions |
33
|
|
|
or $options = new DebuggerOptions((array) $options); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->options = $options; |
|
|
|
|
36
|
|
|
if ($options->isDisabled() || Tracy::isEnabled()) { |
|
|
|
|
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
Tracy::enable( |
41
|
|
|
$options->getMode(), |
42
|
|
|
$options->getLog(), |
43
|
|
|
$options->getEmail() |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
Tracy::$showBar = $options->hasBar(); |
47
|
|
|
Tracy::$strictMode = $options->isStrict(); |
48
|
|
|
Tracy::$maxDepth = $options->getMaxDepth(); |
49
|
|
|
Tracy::$maxLength = $options->getMaxLen(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $id |
54
|
|
|
* @return IBarPanel|null |
55
|
|
|
*/ |
56
|
|
|
public function getBarPanel($id) |
57
|
|
|
{ |
58
|
|
|
return Tracy::getBar()->getPanel($id); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param object|IBarPanel $panel |
63
|
|
|
* @param string|null $id |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
|
|
public function setBarPanel(IBarPanel $panel, $id = null) |
67
|
|
|
{ |
68
|
|
|
Tracy::getBar()->addPanel($panel, $id); |
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function setBarInfo($info, $value = null) |
76
|
|
|
{ |
77
|
|
|
$_info = is_string($info) ? $info = [$info => (string) $value] : (array) $info; |
78
|
|
|
|
79
|
|
|
/** @var \Tracy\DefaultBarPanel $panel */ |
80
|
|
|
$panel = $this->getBarPanel('Tracy:info'); |
81
|
|
|
$panel and $panel->data = array_replace(is_array($panel->data) ? $panel->data : [], $_info); |
|
|
|
|
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function dump($subject, $return = false) |
90
|
|
|
{ |
91
|
|
|
return Tracy::dump($subject, $return); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function barDump($subject, $title = null, array $options = null) |
98
|
|
|
{ |
99
|
|
|
Tracy::barDump($subject, $title, $options); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function timer($name = null) |
106
|
|
|
{ |
107
|
|
|
return Tracy::timer($name); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.