-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Property.php
168 lines (140 loc) · 3.81 KB
/
Property.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
namespace Notion\Pages\Properties;
/**
* @psalm-type PropertyJson = array{ id: string, type: string }
*/
class Property
{
public const TYPE_RICH_TEXT = "rich_text";
public const TYPE_NUMBER = "number";
public const TYPE_SELECT = "select";
public const TYPE_MULTI_SELECT = "multi_select";
public const TYPE_DATE = "date";
public const TYPE_FORMULA = "formula";
public const TYPE_RELATION = "relation";
public const TYPE_ROLLUP = "rollup";
public const TYPE_TITLE = "title";
public const TYPE_PEOPLE = "people";
public const TYPE_FILES = "files";
public const TYPE_CHECKBOX = "checkbox";
public const TYPE_URL = "url";
public const TYPE_EMAIL = "email";
public const TYPE_PHONE_NUMBER = "phone_number";
public const TYPE_CREATED_TIME = "created_time";
public const TYPE_CREATED_BY = "created_by";
public const TYPE_LAST_EDITED_TIME = "last_edited_time";
public const TYPE_LAST_EDITED_BY = "last_edited_by";
private string $id;
private string $type;
private function __construct(
string $id,
string $type,
) {
$this->id = $id;
$this->type = $type;
}
public static function create(string $id, string $type): self
{
return new self($id, $type);
}
/**
* @param PropertyJson $array
*
* @internal
*/
public static function fromArray(array $array): self
{
return new self($array["id"], $array["type"]);
}
public function toArray(): array
{
return [
"id" => $this->id,
"type" => $this->type,
];
}
public function id(): string
{
return $this->id;
}
public function type(): string
{
return $this->type;
}
public function isRichText(): bool
{
return $this->type === self::TYPE_RICH_TEXT;
}
public function isNumber(): bool
{
return $this->type === self::TYPE_NUMBER;
}
public function isSelect(): bool
{
return $this->type === self::TYPE_SELECT;
}
public function isMultiSelect(): bool
{
return $this->type === self::TYPE_MULTI_SELECT;
}
// public function isDate(): bool
// {
// return $this->type === self::TYPE_DATE;
// }
// public function isFormula(): bool
// {
// return $this->type === self::TYPE_FORMULA;
// }
public function isRelation(): bool
{
return $this->type === self::TYPE_RELATION;
}
// public function isRollup(): bool
// {
// return $this->type === self::TYPE_ROLLUP;
// }
public function isTitle(): bool
{
return $this->type === self::TYPE_TITLE;
}
public function isPeople(): bool
{
return $this->type === self::TYPE_PEOPLE;
}
// public function isFiles(): bool
// {
// return $this->type === self::TYPE_FILES;
// }
public function isCheckbox(): bool
{
return $this->type === self::TYPE_CHECKBOX;
}
// public function isUrl(): bool
// {
// return $this->type === self::TYPE_URL;
// }
// public function isEmail(): bool
// {
// return $this->type === self::TYPE_EMAIL;
// }
// public function isPhoneNumber(): bool
// {
// return $this->type === self::TYPE_PHONE_NUMBER;
// }
// public function isCreatedTime(): bool
// {
// return $this->type === self::TYPE_CREATED_TIME;
// }
// public function isCreatedBy(): bool
// {
// return $this->type === self::TYPE_CREATED_BY;
// }
// public function isLastEditedTime(): bool
// {
// return $this->type === self::TYPE_LAST_EDITED_TIME;
// }
// public function isLastEditedBy(): bool
// {
// return $this->type === self::TYPE_LAST_EDITED_BY;
// }
}