1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 12 October 2016 |
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
6
|
|
|
*/ |
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Optimizely schedule. |
11
|
|
|
*/ |
12
|
|
|
class Schedule |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The start time for the Experiment |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $startTime; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The stop time for the Experiment |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $stopTime; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The time zone to use for Experiment start/stop times |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $timezone; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
*/ |
35
|
7 |
|
public function __construct($options = array()) |
36
|
|
|
{ |
37
|
7 |
|
foreach ($options as $name=>$value) { |
38
|
|
|
switch ($name) { |
39
|
6 |
|
case 'start_time': $this->setStartTime($value); break; |
|
|
|
|
40
|
6 |
|
case 'stop_time': $this->setStopTime($value); break; |
|
|
|
|
41
|
6 |
|
case 'time_zone': $this->setTimezone($value); break; |
|
|
|
|
42
|
|
|
default: |
43
|
6 |
|
throw new \Exception('Unknown option: ' . $name); |
44
|
|
|
} |
45
|
|
|
} |
46
|
7 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Returns this object as array. |
50
|
|
|
*/ |
51
|
3 |
|
public function toArray() |
52
|
|
|
{ |
53
|
|
|
$options = array( |
54
|
3 |
|
'start_time' => $this->getStartTime(), |
55
|
3 |
|
'stop_time' => $this->getStopTime(), |
56
|
3 |
|
'time_zone' => $this->getTimezone(), |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
// Remove options with empty values |
60
|
3 |
|
$cleanedOptions = array(); |
61
|
3 |
|
foreach ($options as $name=>$value) { |
62
|
3 |
|
if ($value!==null) |
63
|
3 |
|
$cleanedOptions[$name] = $value; |
64
|
|
|
} |
65
|
|
|
|
66
|
3 |
|
return $cleanedOptions; |
67
|
|
|
} |
68
|
|
|
|
69
|
4 |
|
public function getStartTime() |
70
|
|
|
{ |
71
|
4 |
|
return $this->startTime; |
72
|
|
|
} |
73
|
|
|
|
74
|
7 |
|
public function setStartTime($startTime) |
75
|
|
|
{ |
76
|
7 |
|
$this->startTime = $startTime; |
77
|
7 |
|
} |
78
|
|
|
|
79
|
3 |
|
public function getStopTime() |
80
|
|
|
{ |
81
|
3 |
|
return $this->stopTime; |
82
|
|
|
} |
83
|
|
|
|
84
|
7 |
|
public function setStopTime($stopTime) |
85
|
|
|
{ |
86
|
7 |
|
$this->stopTime = $stopTime; |
87
|
7 |
|
} |
88
|
|
|
|
89
|
4 |
|
public function getTimezone() |
90
|
|
|
{ |
91
|
4 |
|
return $this->timezone; |
92
|
|
|
} |
93
|
|
|
|
94
|
6 |
|
public function setTimezone($timezone) |
95
|
|
|
{ |
96
|
6 |
|
$this->timezone = $timezone; |
97
|
6 |
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
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.