1
|
|
|
<?php namespace Neomerx\JsonApi\Encoder\Parameters; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 [email protected] (www.neomerx.com) |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use \Neomerx\JsonApi\Factories\Exceptions; |
20
|
|
|
use \Neomerx\JsonApi\Contracts\Encoder\Parameters\SortParameterInterface; |
21
|
|
|
use \Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @package Neomerx\JsonApi |
25
|
|
|
*/ |
26
|
|
|
class EncodingParameters implements EncodingParametersInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var array|null |
30
|
|
|
*/ |
31
|
|
|
private $includePaths; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array|null |
35
|
|
|
*/ |
36
|
|
|
private $fieldSets; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var SortParameterInterface[]|null |
40
|
|
|
*/ |
41
|
|
|
private $sortParameters; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array|null |
45
|
|
|
*/ |
46
|
|
|
private $pagingParameters; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var array|null |
50
|
|
|
*/ |
51
|
|
|
private $filteringParameters; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array|null |
55
|
|
|
*/ |
56
|
|
|
private $unrecognizedParams; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string[]|null $includePaths |
60
|
|
|
* @param array|null $fieldSets |
61
|
|
|
* @param SortParameterInterface[]|null $sortParameters |
62
|
|
|
* @param array|null $pagingParameters |
63
|
|
|
* @param array|null $filteringParameters |
64
|
|
|
* @param array|null $unrecognizedParams |
65
|
|
|
*/ |
66
|
81 |
|
public function __construct( |
67
|
|
|
$includePaths = null, |
68
|
|
|
array $fieldSets = null, |
69
|
|
|
$sortParameters = null, |
70
|
|
|
array $pagingParameters = null, |
71
|
|
|
array $filteringParameters = null, |
72
|
|
|
array $unrecognizedParams = null |
73
|
|
|
) { |
74
|
81 |
|
$this->fieldSets = $fieldSets; |
75
|
81 |
|
$this->includePaths = $includePaths; |
76
|
81 |
|
$this->sortParameters = $sortParameters; |
77
|
81 |
|
$this->pagingParameters = $pagingParameters; |
78
|
81 |
|
$this->unrecognizedParams = $unrecognizedParams; |
79
|
81 |
|
$this->filteringParameters = $filteringParameters; |
80
|
81 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @inheritdoc |
84
|
|
|
*/ |
85
|
72 |
|
public function getIncludePaths() |
86
|
|
|
{ |
87
|
72 |
|
return $this->includePaths; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @inheritdoc |
92
|
|
|
*/ |
93
|
18 |
|
public function getFieldSets() |
94
|
|
|
{ |
95
|
18 |
|
return $this->fieldSets; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @inheritdoc |
100
|
|
|
*/ |
101
|
53 |
|
public function getFieldSet($type) |
102
|
|
|
{ |
103
|
53 |
|
is_string($type) === true ?: Exceptions::throwInvalidArgument('type', $type); |
104
|
|
|
|
105
|
53 |
|
return (isset($this->fieldSets[$type]) === true ? $this->fieldSets[$type] : null); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @inheritdoc |
110
|
|
|
*/ |
111
|
12 |
|
public function getSortParameters() |
112
|
|
|
{ |
113
|
12 |
|
return $this->sortParameters; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @inheritdoc |
118
|
|
|
*/ |
119
|
11 |
|
public function getPaginationParameters() |
120
|
|
|
{ |
121
|
11 |
|
return $this->pagingParameters; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @inheritdoc |
126
|
|
|
*/ |
127
|
12 |
|
public function getFilteringParameters() |
128
|
|
|
{ |
129
|
12 |
|
return $this->filteringParameters; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @inheritdoc |
134
|
|
|
*/ |
135
|
8 |
|
public function getUnrecognizedParameters() |
136
|
|
|
{ |
137
|
8 |
|
return $this->unrecognizedParams; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @inheritdoc |
142
|
|
|
*/ |
143
|
2 |
|
public function isEmpty() |
144
|
|
|
{ |
145
|
|
|
return |
146
|
2 |
|
empty($this->getFieldSets()) === true && empty($this->getIncludePaths()) === true && |
147
|
2 |
|
empty($this->getSortParameters()) === true && empty($this->getPaginationParameters()) === true && |
148
|
2 |
|
empty($this->getFilteringParameters()) === true; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|