|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\SchemaConfigurators; |
|
6
|
|
|
|
|
7
|
|
|
abstract class AbstractIndividualControlGraphQLQueryConfigurator extends AbstractGraphQLQueryConfigurator |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Create a service configuration entry comprising a field and its value, |
|
11
|
|
|
* adding an individual schema mode for access control. |
|
12
|
|
|
* It returns a single array (or null) |
|
13
|
|
|
* |
|
14
|
|
|
* @param mixed|null $value |
|
15
|
|
|
* @return array<array> The list of entries, where an entry is an array |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function getIndividualControlEntriesFromField(string $selectedField, $value, ?string $schemaMode): array |
|
18
|
|
|
{ |
|
19
|
|
|
$entriesFromField = $this->getEntriesFromField($selectedField, $value); |
|
20
|
|
|
// Attach the schemaMode to all elements in the array |
|
21
|
|
|
if (!is_null($schemaMode)) { |
|
22
|
|
|
foreach ($entriesFromField as &$entryFromField) { |
|
23
|
|
|
$entryFromField[] = $schemaMode; |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
return $entriesFromField; |
|
27
|
|
|
} |
|
28
|
|
|
/** |
|
29
|
|
|
* Create the service configuration entries comprising a directive and its value, |
|
30
|
|
|
* adding an individual schema mode for access control. |
|
31
|
|
|
* It returns an array of arrays (or null) |
|
32
|
|
|
* |
|
33
|
|
|
* @param mixed $value |
|
34
|
|
|
* @return array<array> The list of entries, where an entry is an array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function getIndividualControlEntriesFromDirective(string $selectedDirective, $value, ?string $schemaMode): ?array |
|
37
|
|
|
{ |
|
38
|
|
|
$entriesForDirective = $this->getEntriesFromDirective($selectedDirective, $value); |
|
39
|
|
|
if (!is_null($entriesForDirective) && !is_null($schemaMode)) { |
|
40
|
|
|
foreach ($entriesForDirective as &$entry) { |
|
41
|
|
|
$entry[] = $schemaMode; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
return $entriesForDirective; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|