|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Mado\QueryBundle\Objects\Filter; |
|
6
|
|
|
|
|
7
|
|
|
class IdsChecker |
|
8
|
|
|
{ |
|
9
|
|
|
private $idsMustBeSubset = true; |
|
10
|
|
|
|
|
11
|
|
|
private $filtering; |
|
12
|
|
|
|
|
13
|
|
|
private $additionalFiltersIds; |
|
14
|
|
|
|
|
15
|
|
|
private $objectFilter; |
|
16
|
|
|
|
|
17
|
|
|
private $filterKey; |
|
18
|
|
|
|
|
19
|
|
|
private $finalFilterIds; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->idsMustBeSubset = true; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function setFiltering($filtering) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->filtering = $filtering; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function setAdditionalFiltersIds($additionalFiltersIds) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->additionalFiltersIds = $additionalFiltersIds; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function setObjectFilter(Filter $objectFilter) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->objectFilter = $objectFilter; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function setFilterKey($filterKey) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->filterKey = $filterKey; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function validateIds() |
|
47
|
|
|
{ |
|
48
|
|
|
$rawFilteredIds = $this->objectFilter->getIds(); |
|
49
|
|
|
|
|
50
|
|
|
foreach ($this->filtering as $key => $queryStringIds) { |
|
51
|
|
|
$qsIds = explode(',', $queryStringIds); |
|
52
|
|
|
$addFilIds = explode(',', $this->additionalFiltersIds); |
|
53
|
|
|
foreach ($qsIds as $requestedId) { |
|
54
|
|
|
if ($this->objectFilter->getOperator() == 'list') { |
|
55
|
|
|
if (!in_array($requestedId, $addFilIds)) { |
|
56
|
|
|
throw new ForbiddenContentException( |
|
|
|
|
|
|
57
|
|
|
'Oops! Forbidden requested id ' . $requestedId |
|
58
|
|
|
. ' is not available. ' |
|
59
|
|
|
. 'Available are "' . join(', ', $addFilIds) . '"' |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ($this->objectFilter->getOperator() == 'nlist') { |
|
65
|
|
|
$queryStringOperator = explode('|', key($this->filtering)); |
|
|
|
|
|
|
66
|
|
|
if (array_intersect($qsIds, $addFilIds) == []) { |
|
67
|
|
|
$this->filterKey = str_replace('nlist', 'list', $this->objectFilter->getRawFilter()); |
|
68
|
|
|
$rawFilteredIds = join(',', $qsIds); |
|
69
|
|
|
$this->idsMustBeSubset = false; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->finalFilterIds = $rawFilteredIds; |
|
76
|
|
|
|
|
77
|
|
|
if (true == $this->idsMustBeSubset) { |
|
|
|
|
|
|
78
|
|
|
foreach ($this->filtering as $key => $queryStringIds) { |
|
79
|
|
|
$qsIds = explode(',', $queryStringIds); |
|
80
|
|
|
$addFilIds = explode(',', $this->additionalFiltersIds); |
|
81
|
|
|
$this->finalFilterIds = join(',', array_intersect($qsIds, $addFilIds)); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getFilterKey() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->filterKey; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getFinalFilterIds() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->finalFilterIds; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths