-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathResourceIdentifier.php
More file actions
41 lines (34 loc) · 909 Bytes
/
Copy pathResourceIdentifier.php
File metadata and controls
41 lines (34 loc) · 909 Bytes
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
<?php
declare(strict_types=1);
namespace JsonApiPhp\JsonApi;
use DomainException;
use JsonApiPhp\JsonApi\Internal\PrimaryData;
final class ResourceIdentifier implements PrimaryData {
private readonly object $obj;
public function __construct(string $type, string $id, Meta ...$metas) {
if (isValidName($type) === false) {
throw new DomainException("Invalid type value: $type");
}
$this->obj = (object)[
'type' => $type,
'id' => $id,
];
foreach ($metas as $meta) {
$meta->attachTo($this->obj);
}
}
/**
* @param object $o
* @internal
*/
public function attachTo(object $o): void {
$o->data = $this->obj;
}
/**
* @param object $o
* @internal
*/
public function attachToCollection(object $o): void {
$o->data[] = $this->obj;
}
}