|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace HelloFresh\Stats\Client; |
| 4 | + |
| 5 | + |
| 6 | +use HelloFresh\Stats\Client; |
| 7 | +use HelloFresh\Stats\Incrementer; |
| 8 | +use HelloFresh\Stats\State; |
| 9 | +use HelloFresh\Stats\Timer; |
| 10 | + |
| 11 | +class Memory extends AbstractClient implements Client |
| 12 | +{ |
| 13 | + /** @var Incrementer\Memory */ |
| 14 | + protected $incrementer; |
| 15 | + /** @var State\Memory */ |
| 16 | + protected $state; |
| 17 | + /** @var Timer\Memory[] */ |
| 18 | + protected $timers; |
| 19 | + |
| 20 | + /** |
| 21 | + * @inheritdoc |
| 22 | + */ |
| 23 | + protected function getIncrementer() |
| 24 | + { |
| 25 | + if (null === $this->incrementer) { |
| 26 | + $this->incrementer = new Incrementer\Memory(); |
| 27 | + } |
| 28 | + return $this->incrementer; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @inheritdoc |
| 33 | + */ |
| 34 | + protected function getState() |
| 35 | + { |
| 36 | + if (null === $this->state) { |
| 37 | + $this->state = new State\Memory(); |
| 38 | + } |
| 39 | + return $this->state; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @inheritdoc |
| 44 | + */ |
| 45 | + public function buildTimer() |
| 46 | + { |
| 47 | + $timer = new Timer\Memory(); |
| 48 | + $this->timers[] = $timer; |
| 49 | + return $timer; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @return Timer\Memory[] |
| 54 | + */ |
| 55 | + public function getTimers() |
| 56 | + { |
| 57 | + return $this->timers; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Returns all stored metrics array. |
| 62 | + * Key - metric name, value - metric value. |
| 63 | + * |
| 64 | + * @return array |
| 65 | + */ |
| 66 | + public function getIncrementedMetrics() |
| 67 | + { |
| 68 | + return $this->getIncrementer()->getMetrics(); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Returns all stored states array. |
| 73 | + * Key - metric name, value - metric value. |
| 74 | + * |
| 75 | + * @return array |
| 76 | + */ |
| 77 | + public function getStateMetrics() |
| 78 | + { |
| 79 | + return $this->getState()->getMetrics(); |
| 80 | + } |
| 81 | +} |
0 commit comments