1: <?php
2: namespace Yep\Stopwatch;
3:
4: class Manager {
5:
6: protected $stopwatches;
7:
8: 9: 10: 11: 12: 13:
14: public function addStopwatch(Stopwatch $stopwatch) {
15: $name = $stopwatch->getName();
16:
17: if (isset($this->stopwatches[$name])) {
18: throw new StopwatchAlreadyExistsException(sprintf('The stopwatch with name "%s" already exists.', $name));
19: }
20:
21: $this->stopwatches[$name] = $stopwatch;
22: }
23:
24: 25: 26: 27: 28: 29: 30: 31: 32:
33: public function getStopwatch($name, $must_exist = true) {
34: if (!isset($this->stopwatches[$name])) {
35: if ($must_exist) {
36: throw new StopwatchDoesntExistException(sprintf('The stopwatch with name "%s" doesn\'t exist.', $name));
37: }
38:
39: $this->addStopwatch(new Stopwatch($name));
40: }
41:
42: return $this->stopwatches[$name];
43: }
44:
45: 46: 47: 48: 49: 50:
51: public function stopwatchExists($name) {
52: return isset($this->stopwatches[$name]);
53: }
54:
55: 56: 57: 58: 59:
60: public function removeStopwatch($name) {
61: unset($this->stopwatches[$name]);
62: }
63:
64: 65: 66: 67: 68:
69: public function getStopwatches() {
70: return $this->stopwatches;
71: }
72: }
73: