-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Factory.php
34 lines (30 loc) · 1.31 KB
/
Factory.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
<?php
namespace Notion\Pages\Properties;
use Exception;
class Factory
{
/**
* @param array{ type: string } $array
*/
public static function fromArray(array $array): PropertyInterface
{
$type = $array["type"];
return match($type) {
Property::TYPE_TITLE => Title::fromArray($array),
Property::TYPE_RICH_TEXT => RichTextProperty::fromArray($array),
Property::TYPE_NUMBER => Number::fromArray($array),
Property::TYPE_SELECT => Select::fromArray($array),
Property::TYPE_MULTI_SELECT => MultiSelect::fromArray($array),
Property::TYPE_FORMULA => Formula::fromArray($array),
Property::TYPE_RELATION => Relation::fromArray($array),
Property::TYPE_PEOPLE => People::fromArray($array),
Property::TYPE_CHECKBOX => Checkbox::fromArray($array),
Property::TYPE_URL => Url::fromArray($array),
Property::TYPE_EMAIL => Email::fromArray($array),
Property::TYPE_PHONE_NUMBER => PhoneNumber::fromArray($array),
Property::TYPE_CREATED_TIME => CreatedTime::fromArray($array),
Property::TYPE_LAST_EDITED_TIME => LastEditedTime::fromArray($array),
default => throw new Exception("Invalid property type: '{$type}'"),
};
}
}