@@ 13-65 (lines=53) @@ | ||
10 | * |
|
11 | * @package Mikemirten\Component\JsonApi\Document |
|
12 | */ |
|
13 | class SingleIdentifierDocument extends AbstractDocument |
|
14 | { |
|
15 | /** |
|
16 | * Resource identifier |
|
17 | * |
|
18 | * @var ResourceIdentifierObject |
|
19 | */ |
|
20 | protected $identifier; |
|
21 | ||
22 | /** |
|
23 | * SingleResourceDocument constructor. |
|
24 | * |
|
25 | * @param ResourceIdentifierObject $resource |
|
26 | * @param array $metadata |
|
27 | */ |
|
28 | public function __construct(ResourceIdentifierObject $resource, array $metadata = []) |
|
29 | { |
|
30 | $this->identifier = $resource; |
|
31 | $this->metadata = $metadata; |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * Get resource identifier |
|
36 | * |
|
37 | * @return ResourceIdentifierObject |
|
38 | */ |
|
39 | public function getIdentifier(): ResourceIdentifierObject |
|
40 | { |
|
41 | return $this->identifier; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * {@inheritdoc} |
|
46 | */ |
|
47 | public function toArray(): array |
|
48 | { |
|
49 | $data = parent::toArray(); |
|
50 | ||
51 | $data['data'] = $this->getIdentifier()->toArray(); |
|
52 | ||
53 | return $data; |
|
54 | } |
|
55 | ||
56 | /** |
|
57 | * Cast to a string |
|
58 | * |
|
59 | * @return string |
|
60 | */ |
|
61 | public function __toString(): string |
|
62 | { |
|
63 | return sprintf('Document contains [%s]', $this->identifier); |
|
64 | } |
|
65 | } |
@@ 13-65 (lines=53) @@ | ||
10 | * |
|
11 | * @package Mikemirten\Component\JsonApi\Document |
|
12 | */ |
|
13 | class SingleIdentifierRelationship extends AbstractRelationship |
|
14 | { |
|
15 | /** |
|
16 | * Resource identifier |
|
17 | * |
|
18 | * @var ResourceIdentifierObject |
|
19 | */ |
|
20 | protected $identifier; |
|
21 | ||
22 | /** |
|
23 | * SingleIdentifierRelationship constructor. |
|
24 | * |
|
25 | * @param ResourceIdentifierObject $identifier |
|
26 | * @param array $metadata |
|
27 | */ |
|
28 | public function __construct(ResourceIdentifierObject $identifier, array $metadata = []) |
|
29 | { |
|
30 | $this->identifier = $identifier; |
|
31 | $this->metadata = $metadata; |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * Get resource identifier |
|
36 | * |
|
37 | * @return ResourceIdentifierObject |
|
38 | */ |
|
39 | public function getIdentifier(): ResourceIdentifierObject |
|
40 | { |
|
41 | return $this->identifier; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * {@inheritdoc} |
|
46 | */ |
|
47 | public function toArray(): array |
|
48 | { |
|
49 | $data = parent::toArray(); |
|
50 | ||
51 | $data['data'] = $this->getIdentifier()->toArray(); |
|
52 | ||
53 | return $data; |
|
54 | } |
|
55 | ||
56 | /** |
|
57 | * Cast to a string |
|
58 | * |
|
59 | * @return string |
|
60 | */ |
|
61 | public function __toString(): string |
|
62 | { |
|
63 | return sprintf('Relationship contains [%s]', $this->identifier); |
|
64 | } |
|
65 | } |
@@ 13-65 (lines=53) @@ | ||
10 | * |
|
11 | * @package Mikemirten\Component\JsonApi |
|
12 | */ |
|
13 | class SingleResourceDocument extends AbstractDocument |
|
14 | { |
|
15 | /** |
|
16 | * Resource |
|
17 | * |
|
18 | * @var ResourceObject |
|
19 | */ |
|
20 | protected $resource; |
|
21 | ||
22 | /** |
|
23 | * SingleIdentifierDocument constructor. |
|
24 | * |
|
25 | * @param ResourceObject $resource |
|
26 | * @param array $metadata |
|
27 | */ |
|
28 | public function __construct(ResourceObject $resource, array $metadata = []) |
|
29 | { |
|
30 | $this->resource = $resource; |
|
31 | $this->metadata = $metadata; |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * Get resource |
|
36 | * |
|
37 | * @return ResourceObject |
|
38 | */ |
|
39 | public function getResource(): ResourceObject |
|
40 | { |
|
41 | return $this->resource; |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * {@inheritdoc} |
|
46 | */ |
|
47 | public function toArray(): array |
|
48 | { |
|
49 | $data = parent::toArray(); |
|
50 | ||
51 | $data['data'] = $this->getResource()->toArray(); |
|
52 | ||
53 | return $data; |
|
54 | } |
|
55 | ||
56 | /** |
|
57 | * Cast to a string |
|
58 | * |
|
59 | * @return string |
|
60 | */ |
|
61 | public function __toString(): string |
|
62 | { |
|
63 | return sprintf('Document contains [%s]', $this->resource); |
|
64 | } |
|
65 | } |