1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Clubdeuce\Tessitura\Resources; |
4
|
|
|
|
5
|
|
|
use Clubdeuce\Tessitura\Base\Base; |
6
|
|
|
use DateTime; |
7
|
|
|
use DateTimeZone; |
8
|
|
|
use Exception; |
9
|
|
|
use InvalidArgumentException; |
10
|
|
|
use Throwable; |
11
|
|
|
|
12
|
|
|
class ProductionSeason extends Base |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string[] |
16
|
|
|
*/ |
17
|
|
|
protected array $_response = []; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var Performance[] |
21
|
|
|
*/ |
22
|
|
|
protected array $_performances = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get the response data for this production season. |
26
|
|
|
* |
27
|
|
|
* @return mixed[] The response data |
28
|
|
|
*/ |
29
|
4 |
|
public function response(): array |
30
|
|
|
{ |
31
|
4 |
|
return $this->_response; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws InvalidArgumentException |
36
|
|
|
*/ |
37
|
4 |
|
public function firstPerformanceDate(string $timezone = 'America/New_York'): DateTime|bool |
38
|
|
|
{ |
39
|
|
|
try { |
40
|
4 |
|
$timezone = new DateTimeZone($timezone); |
41
|
1 |
|
} catch (Exception $e) { |
42
|
1 |
|
throw new InvalidArgumentException($e->getMessage()); |
43
|
|
|
} |
44
|
|
|
|
45
|
3 |
|
$date = isset($this->response()['FirstPerformanceDate']) ? $this->response()['FirstPerformanceDate'] : false; |
46
|
3 |
|
if ($date) { |
47
|
|
|
try { |
48
|
2 |
|
$result = DateTime::createFromFormat(' Y-m-d\TG:i:sp', $date, $timezone); |
49
|
2 |
|
if ($result === false) { |
50
|
|
|
throw new Exception("Invalid date format for FirstPerformanceDate"); |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
return $result; |
54
|
|
|
} catch (Throwable $e) { |
55
|
|
|
throw new Exception("Unable to parse FirstPerformanceDate: " . $e->getMessage()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @throws InvalidArgumentException |
64
|
|
|
*/ |
65
|
3 |
|
public function lastPerformanceDate(string $timezone = 'America/New_York'): DateTime|bool |
66
|
|
|
{ |
67
|
|
|
try { |
68
|
3 |
|
$timezone = new DateTimeZone($timezone); |
69
|
1 |
|
} catch (Exception $e) { |
70
|
1 |
|
throw new InvalidArgumentException($e->getMessage()); |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
$date = isset($this->response()['LastPerformanceDate']) ? $this->response()['LastPerformanceDate'] : false; |
74
|
2 |
|
if ($date) { |
75
|
|
|
try { |
76
|
1 |
|
$result = DateTime::createFromFormat(' Y-m-d\TG:i:sp', $date, $timezone); |
77
|
1 |
|
if ($result === false) { |
78
|
|
|
throw new Exception("Invalid date format for LastPerformanceDate"); |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
return $result; |
82
|
|
|
} catch (Throwable $e) { |
83
|
|
|
throw new Exception("Unable to parse LastPerformanceDate: " . $e->getMessage()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return Performance[] |
92
|
|
|
*/ |
93
|
1 |
|
public function performances(): array |
94
|
|
|
{ |
95
|
1 |
|
return $this->_performances; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|