1 | <?php |
||
17 | class ProfilerExtension extends Asm89_Extension implements DataCollectorInterface, Serializable |
||
18 | { |
||
19 | /** |
||
20 | * Data about fetchBlock requests. |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $fetchBlock = []; |
||
25 | |||
26 | /** |
||
27 | * Data about generateKey requests. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $generateKey = []; |
||
32 | |||
33 | /** |
||
34 | * Cache hits. |
||
35 | * |
||
36 | * @var int |
||
37 | */ |
||
38 | private $hits = 0; |
||
39 | |||
40 | /** |
||
41 | * Caching strategy used. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $strategyClass; |
||
46 | |||
47 | /** |
||
48 | * @param CacheStrategyInterface $cacheStrategy |
||
49 | */ |
||
50 | public function __construct(CacheStrategyInterface $cacheStrategy) |
||
51 | { |
||
52 | parent::__construct(new ProfilerStrategy($cacheStrategy, $this)); |
||
53 | |||
54 | $this->strategyClass = get_class($cacheStrategy); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Collects data for the given Request and Response. |
||
59 | * |
||
60 | * @param Request $request A Request instance |
||
61 | * @param Response $response A Response instance |
||
62 | * @param Exception $exception An Exception instance |
||
63 | */ |
||
64 | public function collect(Request $request, Response $response, Exception $exception = null) |
||
68 | |||
69 | /** |
||
70 | * Store a fetch request. |
||
71 | * |
||
72 | * @param mixed $key |
||
73 | * @param string $output |
||
74 | */ |
||
75 | public function addFetchBlock($key, $output) |
||
83 | |||
84 | /** |
||
85 | * Store a generateKey request. |
||
86 | * |
||
87 | * @param string $annotation |
||
88 | * @param mixed $value |
||
89 | */ |
||
90 | public function addGenerateKey($annotation, $value) |
||
91 | { |
||
92 | $this->generateKey[] = [ |
||
93 | 'annotation' => $annotation, |
||
94 | 'value' => $value, |
||
95 | ]; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Get data stored in this profiler. |
||
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | public function getData() |
||
104 | { |
||
105 | return [ |
||
106 | 'fetchBlock' => $this->fetchBlock, |
||
107 | 'generateKey' => $this->generateKey, |
||
108 | 'hits' => $this->hits, |
||
109 | 'strategyClass' => $this->strategyClass, |
||
110 | ]; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * String representation of object. |
||
115 | * |
||
116 | * @link http://php.net/manual/en/serializable.serialize.php |
||
117 | * |
||
118 | * @return string The string representation of the object or null. |
||
119 | */ |
||
120 | public function serialize() |
||
124 | |||
125 | /** |
||
126 | * Constructs the object. |
||
127 | * |
||
128 | * @link http://php.net/manual/en/serializable.unserialize.php |
||
129 | * |
||
130 | * @param string $serialized The string representation of the object. |
||
131 | */ |
||
132 | public function unserialize($serialized) |
||
143 | |||
144 | /** |
||
145 | * Reset profiler data |
||
146 | */ |
||
147 | public function reset() |
||
153 | } |
||
154 |