1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mvdnbrk\Postmark\Support; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Mvdnbrk\Postmark\Support\Collection; |
7
|
|
|
|
8
|
|
|
class PostmarkDate extends DateTime |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Constants for numeric representation of the day of the week. |
12
|
|
|
*/ |
13
|
|
|
const SUNDAY = 0; |
14
|
|
|
const MONDAY = 1; |
15
|
|
|
const TUESDAY = 2; |
16
|
|
|
const WEDNESDAY = 3; |
17
|
|
|
const THURSDAY = 4; |
18
|
|
|
const FRIDAY = 5; |
19
|
|
|
const SATURDAY = 6; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Textual representation of a day, three letters. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected static $days_abbreviated = [ |
27
|
|
|
self::SUNDAY => 'Sun', |
28
|
|
|
self::MONDAY => 'Mon', |
29
|
|
|
self::TUESDAY => 'Tue', |
30
|
|
|
self::WEDNESDAY => 'Wed', |
31
|
|
|
self::THURSDAY => 'Thu', |
32
|
|
|
self::FRIDAY => 'Fri', |
33
|
|
|
self::SATURDAY => 'Sat', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the textual respresentation of a day as three letters. |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public static function getAbbreviatedDays() |
42
|
|
|
{ |
43
|
|
|
return static::$days_abbreviated; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get a collection of the textual respresentation of a day as three letters. |
48
|
|
|
* |
49
|
|
|
* @return \Mvdnbrk\Postmark\Support\Collection |
50
|
|
|
*/ |
51
|
|
|
public static function getAbbreviatedDaysCollection() |
52
|
|
|
{ |
53
|
|
|
return new Collection(static::getAbbreviatedDays()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set the instance to UTC timezone. |
58
|
|
|
* |
59
|
|
|
* @return static |
60
|
|
|
*/ |
61
|
|
|
public function inUtcTimezone() |
62
|
|
|
{ |
63
|
|
|
return parent::setTimezone(timezone_open('UTC')); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Created a new instance from a string. |
68
|
|
|
* |
69
|
|
|
* @param string $date |
70
|
|
|
* @return static |
71
|
|
|
*/ |
72
|
|
|
public static function parse($date) |
73
|
|
|
{ |
74
|
|
|
$date = new Collection(explode(' ', $date)); |
75
|
|
|
|
76
|
|
|
return new static($date->reject(function ($value) { |
77
|
|
|
return self::getAbbreviatedDaysCollection()->contains(trim($value, ',')); |
78
|
|
|
}) |
79
|
|
|
->take(5) |
80
|
|
|
->implode(' ')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Dynamically retrieve attributes on the data model. |
85
|
|
|
* |
86
|
|
|
* @param string $key |
87
|
|
|
* @throws \InvalidArgumentException |
88
|
|
|
* @return mixed |
89
|
|
|
*/ |
90
|
|
|
public function __get($key) |
91
|
|
|
{ |
92
|
|
|
switch (true) { |
93
|
|
|
case $key === 'isUtc': |
94
|
|
|
return $this->getOffset() === 0; |
95
|
|
|
case $key === 'timezone': |
96
|
|
|
return $this->getTimezone()->getName(); |
97
|
|
|
default: |
98
|
|
|
throw new \InvalidArgumentException(sprintf("Unknown getter '%s'", $key)); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.