1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Neomerx\JsonApi\Parser\RelationshipData; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2020 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Neomerx\JsonApi\Contracts\Factories\FactoryInterface; |
22
|
|
|
use Neomerx\JsonApi\Contracts\Parser\EditableContextInterface; |
23
|
|
|
use Neomerx\JsonApi\Contracts\Parser\IdentifierInterface; |
24
|
|
|
use Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface; |
25
|
|
|
use Neomerx\JsonApi\Contracts\Parser\ResourceInterface; |
26
|
|
|
use Neomerx\JsonApi\Contracts\Schema\PositionInterface; |
27
|
|
|
use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface; |
28
|
|
|
use Neomerx\JsonApi\Exceptions\LogicException; |
29
|
|
|
use function Neomerx\JsonApi\I18n\format as _; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @package Neomerx\JsonApi |
33
|
|
|
*/ |
34
|
|
|
class RelationshipDataIsResource extends BaseRelationshipData implements RelationshipDataInterface |
35
|
|
|
{ |
36
|
|
|
/** @var string */ |
37
|
|
|
public const MSG_INVALID_OPERATION = 'Invalid operation.'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var mixed |
41
|
|
|
*/ |
42
|
|
|
private $resource; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var null|ResourceInterface |
46
|
|
|
*/ |
47
|
|
|
private $parsedResource = null; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param FactoryInterface $factory |
51
|
|
|
* @param SchemaContainerInterface $schemaContainer |
52
|
|
|
* @param EditableContextInterface $context |
53
|
|
|
* @param PositionInterface $position |
54
|
|
|
* @param mixed $resource |
55
|
|
|
*/ |
56
|
28 |
|
public function __construct( |
57
|
|
|
FactoryInterface $factory, |
58
|
|
|
SchemaContainerInterface $schemaContainer, |
59
|
|
|
EditableContextInterface $context, |
60
|
|
|
PositionInterface $position, |
61
|
|
|
$resource |
62
|
|
|
) { |
63
|
28 |
|
parent::__construct($factory, $schemaContainer, $context, $position); |
64
|
|
|
|
65
|
28 |
|
$this->resource = $resource; |
66
|
28 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritdoc |
70
|
|
|
*/ |
71
|
1 |
|
public function isCollection(): bool |
72
|
|
|
{ |
73
|
1 |
|
return false; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
1 |
|
public function isNull(): bool |
80
|
|
|
{ |
81
|
1 |
|
return false; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritdoc |
86
|
|
|
*/ |
87
|
27 |
|
public function isResource(): bool |
88
|
|
|
{ |
89
|
27 |
|
return true; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @inheritdoc |
94
|
|
|
*/ |
95
|
1 |
|
public function isIdentifier(): bool |
96
|
|
|
{ |
97
|
1 |
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
*/ |
103
|
1 |
|
public function getIdentifier(): IdentifierInterface |
104
|
|
|
{ |
105
|
1 |
|
throw new LogicException(_(static::MSG_INVALID_OPERATION)); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @inheritdoc |
110
|
|
|
*/ |
111
|
1 |
|
public function getIdentifiers(): iterable |
112
|
|
|
{ |
113
|
1 |
|
throw new LogicException(_(static::MSG_INVALID_OPERATION)); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @inheritdoc |
118
|
|
|
*/ |
119
|
26 |
|
public function getResource(): ResourceInterface |
120
|
|
|
{ |
121
|
26 |
|
if ($this->parsedResource === null) { |
122
|
26 |
|
$this->parsedResource = $this->createParsedResource($this->resource); |
123
|
|
|
} |
124
|
|
|
|
125
|
26 |
|
return $this->parsedResource; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @inheritdoc |
130
|
|
|
*/ |
131
|
1 |
|
public function getResources(): iterable |
132
|
|
|
{ |
133
|
1 |
|
throw new LogicException(_(static::MSG_INVALID_OPERATION)); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|