Overview

Namespaces

  • Yep
    • Stopwatch

Classes

  • Yep\Stopwatch\Event
  • Yep\Stopwatch\Formatter
  • Yep\Stopwatch\Lap
  • Yep\Stopwatch\Manager
  • Yep\Stopwatch\Stopwatch

Exceptions

  • Yep\Stopwatch\StopwatchAlreadyExistsException
  • Yep\Stopwatch\StopwatchDoesntExistException
  • Yep\Stopwatch\StopwatchEventDoesntExistException
  • Yep\Stopwatch\StopwatchLapNotStartedException
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace Yep\Stopwatch;
 3: 
 4: class Manager {
 5:     /** @var Stopwatch[] */
 6:     protected $stopwatches;
 7: 
 8:     /**
 9:      * Adds the stopwatch into the manager
10:      *
11:      * @param Stopwatch $stopwatch
12:      * @throws StopwatchAlreadyExistsException
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:      * Returns the stopwatch from the manager if exists (or creates and adds new one)
26:      *
27:      * @param string $name
28:      * @param bool   $must_exist
29:      * @return Stopwatch
30:      * @throws StopwatchDoesntExistException
31:      * @throws StopwatchAlreadyExistsException
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:      * Retuns true, if the stopwatch exists or false if not
47:      *
48:      * @param string $name
49:      * @return bool
50:      */
51:     public function stopwatchExists($name) {
52:         return isset($this->stopwatches[$name]);
53:     }
54: 
55:     /**
56:      * Removes the stopwatch from the manager
57:      *
58:      * @param string $name
59:      */
60:     public function removeStopwatch($name) {
61:         unset($this->stopwatches[$name]);
62:     }
63: 
64:     /**
65:      * Returns all stopwatches
66:      *
67:      * @return Stopwatch[]
68:      */
69:     public function getStopwatches() {
70:         return $this->stopwatches;
71:     }
72: }
73: 
API documentation generated by ApiGen