-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Factory.php
29 lines (25 loc) · 990 Bytes
/
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
<?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),
default => throw new Exception("Invalid property type: '{$type}'"),
};
}
}