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
|
|
|
use WebMarketingROI\OptimizelyPHP\Exception; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Optimizely schedule. |
13
|
|
|
*/ |
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
|
|
|
throw new Exception('Unknown option found in the Schedule entity: ' . $name); |
46
|
|
|
} |
47
|
7 |
|
} |
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
|
3 |
|
); |
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
|
3 |
|
} |
67
|
|
|
|
68
|
3 |
|
return $cleanedOptions; |
69
|
|
|
} |
70
|
|
|
|
71
|
4 |
|
public function getStartTime() |
72
|
|
|
{ |
73
|
4 |
|
return $this->startTime; |
74
|
|
|
} |
75
|
|
|
|
76
|
7 |
|
public function setStartTime($startTime) |
77
|
|
|
{ |
78
|
7 |
|
$this->startTime = $startTime; |
79
|
7 |
|
} |
80
|
|
|
|
81
|
3 |
|
public function getStopTime() |
82
|
|
|
{ |
83
|
3 |
|
return $this->stopTime; |
84
|
|
|
} |
85
|
|
|
|
86
|
7 |
|
public function setStopTime($stopTime) |
87
|
|
|
{ |
88
|
7 |
|
$this->stopTime = $stopTime; |
89
|
7 |
|
} |
90
|
|
|
|
91
|
4 |
|
public function getTimezone() |
92
|
|
|
{ |
93
|
4 |
|
return $this->timezone; |
94
|
|
|
} |
95
|
|
|
|
96
|
6 |
|
public function setTimezone($timezone) |
97
|
|
|
{ |
98
|
6 |
|
$this->timezone = $timezone; |
99
|
6 |
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
|
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.