1 | <?php |
||
14 | class Schedule |
||
15 | { |
||
16 | /** |
||
17 | * The start time for the Experiment |
||
18 | * @var string |
||
19 | */ |
||
20 | private $startTime; |
||
21 | |||
22 | /** |
||
23 | * The stop time for the Experiment |
||
24 | * @var string |
||
25 | */ |
||
26 | private $stopTime; |
||
27 | |||
28 | /** |
||
29 | * The time zone to use for Experiment start/stop times |
||
30 | * @var string |
||
31 | */ |
||
32 | private $timezone; |
||
33 | |||
34 | /** |
||
35 | * Constructor. |
||
36 | */ |
||
37 | 7 | public function __construct($options = array()) |
|
38 | { |
||
39 | 7 | foreach ($options as $name=>$value) { |
|
40 | switch ($name) { |
||
41 | 6 | case 'start_time': $this->setStartTime($value); break; |
|
42 | 6 | case 'stop_time': $this->setStopTime($value); break; |
|
43 | 6 | case 'time_zone': $this->setTimezone($value); break; |
|
44 | default: |
||
45 | 6 | throw new Exception('Unknown option: ' . $name); |
|
46 | } |
||
47 | } |
||
48 | 7 | } |
|
49 | |||
50 | /** |
||
51 | * Returns this object as array. |
||
52 | */ |
||
53 | 3 | public function toArray() |
|
54 | { |
||
55 | $options = array( |
||
56 | 3 | 'start_time' => $this->getStartTime(), |
|
57 | 3 | 'stop_time' => $this->getStopTime(), |
|
58 | 3 | 'time_zone' => $this->getTimezone(), |
|
59 | ); |
||
60 | |||
61 | // Remove options with empty values |
||
62 | 3 | $cleanedOptions = array(); |
|
63 | 3 | foreach ($options as $name=>$value) { |
|
64 | 3 | if ($value!==null) |
|
65 | 3 | $cleanedOptions[$name] = $value; |
|
66 | } |
||
67 | |||
68 | 3 | return $cleanedOptions; |
|
69 | } |
||
70 | |||
71 | 4 | public function getStartTime() |
|
75 | |||
76 | 7 | public function setStartTime($startTime) |
|
80 | |||
81 | 3 | public function getStopTime() |
|
85 | |||
86 | 7 | public function setStopTime($stopTime) |
|
90 | |||
91 | 4 | public function getTimezone() |
|
95 | |||
96 | 6 | public function setTimezone($timezone) |
|
100 | } |
||
101 | |||
102 | |||
108 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.