1 | <?php |
||
52 | class ObjectFactory |
||
53 | { |
||
54 | /** |
||
55 | * Create an object |
||
56 | * |
||
57 | * @param RepositoryPathInterface $path Repository object path |
||
58 | * @param ResourceInterface $objectResource |
||
59 | * @return ObjectInterface Object |
||
60 | * @throws InvalidArgumentException If the object type is undefined |
||
61 | */ |
||
62 | 18 | public static function createFromResource(RepositoryPathInterface $path, ResourceInterface $objectResource) |
|
83 | |||
84 | /** |
||
85 | * Create and return a new object |
||
86 | * |
||
87 | * @param RepositoryPathInterface $path Repository object path |
||
88 | * @param string $payload Object payload |
||
89 | * @param array $propertyData Object property data |
||
90 | * @return ObjectInterface Object |
||
91 | */ |
||
92 | 1 | public static function createFromParams(RepositoryPathInterface $path, $payload = '', array $propertyData = []) |
|
93 | { |
||
94 | // Determine the object class |
||
95 | 1 | $objectClass = self::objectClassFromType($path->getType()); |
|
96 | |||
97 | // Prepare the system properties collection |
||
98 | 1 | $systemPropertyData = (empty($propertyData[SystemProperties::COLLECTION]) || |
|
99 | !is_array( |
||
100 | 1 | $propertyData[SystemProperties::COLLECTION] |
|
101 | 1 | )) ? [] : $propertyData[SystemProperties::COLLECTION]; |
|
102 | 1 | $systemPropertyData[SystemProperties::PROPERTY_ID] = $path->getId()->getId(); |
|
103 | 1 | $systemPropertyData[SystemProperties::PROPERTY_TYPE] = $path->getType()->getType(); |
|
104 | 1 | $systemPropertyData[SystemProperties::PROPERTY_REVISION] = $path->getRevision()->getRevision(); |
|
105 | 1 | $systemPropertyData[SystemProperties::PROPERTY_CREATED] = $path->getCreationDate()->format('U'); |
|
106 | 1 | $propertyData[SystemProperties::COLLECTION] = $systemPropertyData; |
|
107 | |||
108 | // Instantiate the object |
||
109 | 1 | return Kernel::create($objectClass, [$payload, $propertyData, $path]); |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * Determine and validate the object class name from its type |
||
114 | * |
||
115 | * @param Type $type Object type |
||
116 | * @return string Object class name |
||
117 | * @throws InvalidArgumentException If the object type is invalid |
||
118 | */ |
||
119 | 18 | protected static function objectClassFromType(Type $type) |
|
133 | } |
||
134 |