1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @fabfuel <[email protected]> |
4
|
|
|
* @created 22.11.14, 08:20 |
5
|
|
|
*/ |
6
|
|
|
namespace Fabfuel\Prophiler\Toolbar\Formatter; |
7
|
|
|
|
8
|
|
|
use Fabfuel\Prophiler\Benchmark\BenchmarkInterface; |
9
|
|
|
use Fabfuel\Prophiler\Toolbar\Formatter\Encoder\EncoderInterface; |
10
|
|
|
|
11
|
|
|
class BenchmarkFormatterAbstract |
12
|
|
|
{ |
13
|
|
|
const NUMBER_COLORS = 5; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var BenchmarkInterface |
17
|
|
|
*/ |
18
|
|
|
protected $benchmark; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var EncoderInterface |
22
|
|
|
*/ |
23
|
|
|
protected $encoder; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
1 |
|
public function getName() |
29
|
|
|
{ |
30
|
1 |
|
$encoder = $this->getEncoder(); |
31
|
|
|
|
32
|
|
|
return $encoder |
33
|
1 |
|
? $encoder->encode($this->getBenchmark()->getName()) |
34
|
1 |
|
: $this->getBenchmark()->getName(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
6 |
|
public function getComponent() |
41
|
|
|
{ |
42
|
6 |
|
$encoder = $this->getEncoder(); |
43
|
|
|
|
44
|
|
|
return $encoder |
45
|
6 |
|
? $encoder->encode($this->getBenchmark()->getComponent()) |
46
|
6 |
|
: $this->getBenchmark()->getComponent(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return BenchmarkInterface |
51
|
|
|
*/ |
52
|
24 |
|
public function getBenchmark() |
53
|
|
|
{ |
54
|
24 |
|
return $this->benchmark; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param BenchmarkInterface $benchmark |
59
|
|
|
*/ |
60
|
26 |
|
public function setBenchmark(BenchmarkInterface $benchmark) |
61
|
|
|
{ |
62
|
26 |
|
$this->benchmark = $benchmark; |
63
|
26 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return EncoderInterface |
67
|
|
|
*/ |
68
|
7 |
|
public function getEncoder() |
69
|
|
|
{ |
70
|
7 |
|
return $this->encoder; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param EncoderInterface $encoder |
75
|
|
|
*/ |
76
|
|
|
public function setEncoder(EncoderInterface $encoder) |
77
|
|
|
{ |
78
|
|
|
$this->encoder = $encoder; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
3 |
|
public function getId() |
85
|
|
|
{ |
86
|
3 |
|
return spl_object_hash($this->getBenchmark()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
5 |
|
public function getColorClass() |
93
|
|
|
{ |
94
|
5 |
|
return sprintf( |
95
|
5 |
|
'color-%s', |
96
|
5 |
|
strlen($this->getComponent()) % self::NUMBER_COLORS |
97
|
5 |
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
3 |
|
public function getIcon() |
104
|
|
|
{ |
105
|
3 |
|
switch ($this->getBenchmark()->getComponent()) { |
106
|
3 |
|
case 'MongoDB': |
107
|
1 |
|
return 'leaf'; |
108
|
2 |
|
default: |
109
|
2 |
|
return 'cog'; |
110
|
2 |
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
7 |
|
public function getMetadata() |
117
|
|
|
{ |
118
|
7 |
|
return $this->getBenchmark()->getMetadata(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return double |
123
|
|
|
*/ |
124
|
1 |
|
public function getStartTime() |
125
|
|
|
{ |
126
|
1 |
|
return $this->getBenchmark()->getStartTime(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return double |
131
|
|
|
*/ |
132
|
1 |
|
public function getEndTime() |
133
|
|
|
{ |
134
|
1 |
|
return $this->getBenchmark()->getEndTime(); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|