1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2016 Facebook, Inc. |
4
|
|
|
* |
5
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to |
6
|
|
|
* use, copy, modify, and distribute this software in source code or binary |
7
|
|
|
* form for use in connection with the web services and APIs provided by |
8
|
|
|
* Facebook. |
9
|
|
|
* |
10
|
|
|
* As with any software that integrates with the Facebook platform, your use |
11
|
|
|
* of this software is subject to the Facebook Developer Principles and |
12
|
|
|
* Policies [http://developers.facebook.com/policy/]. This copyright notice |
13
|
|
|
* shall be included in all copies or substantial portions of the software. |
14
|
|
|
* |
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
20
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21
|
|
|
* DEALINGS IN THE SOFTWARE. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
namespace Facebook\GraphNodes; |
25
|
|
|
|
26
|
|
|
use DateTime; |
27
|
|
|
use DateTimeZone; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Birthday object to handle various Graph return formats |
31
|
|
|
* |
32
|
|
|
* @package Facebook |
33
|
|
|
*/ |
34
|
|
|
class Birthday extends DateTime |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
protected $hasDate = false; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var bool |
43
|
|
|
*/ |
44
|
|
|
protected $hasYear = false; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Parses Graph birthday format to set indication flags, possible values: |
48
|
|
|
* |
49
|
|
|
* MM/DD/YYYY |
50
|
|
|
* MM/DD |
51
|
|
|
* YYYY |
52
|
|
|
* |
53
|
|
|
* @link https://developers.facebook.com/docs/graph-api/reference/user |
54
|
|
|
* |
55
|
|
|
* @param string $date |
56
|
|
|
* @param DateTimeZone $timezone |
57
|
|
|
*/ |
58
|
|
|
public function __construct($date, DateTimeZone $timezone = null) |
59
|
|
|
{ |
60
|
|
|
$parts = explode('/', $date); |
61
|
|
|
|
62
|
|
|
if (count($parts) === 3 || count($parts) === 1) { |
63
|
|
|
$this->hasYear = true; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (count($parts) === 3 || count($parts) === 2) { |
67
|
|
|
$this->hasDate = true; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
parent::__construct($date, $timezone); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns whether date object contains birth day and month |
75
|
|
|
* |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function hasDate() |
79
|
|
|
{ |
80
|
|
|
return $this->hasDate; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns whether date object contains birth year |
85
|
|
|
* |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
|
public function hasYear() |
89
|
|
|
{ |
90
|
|
|
return $this->hasYear; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|