-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
UserByOneofInputObjectTypeResolver.php
executable file
·164 lines (153 loc) · 6.69 KB
/
UserByOneofInputObjectTypeResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
declare(strict_types=1);
namespace PoPCMSSchema\Users\TypeResolvers\InputObjectType;
use PoP\ComponentModel\TypeResolvers\InputTypeResolverInterface;
use PoP\ComponentModel\FilterInputs\FilterInputInterface;
use PoP\ComponentModel\TypeResolvers\InputObjectType\AbstractOneofQueryableInputObjectTypeResolver;
use PoP\ComponentModel\TypeResolvers\ScalarType\IDScalarTypeResolver;
use PoP\ComponentModel\TypeResolvers\ScalarType\StringScalarTypeResolver;
use PoP\Root\App;
use PoPCMSSchema\SchemaCommons\FilterInputs\IncludeFilterInput;
use PoPCMSSchema\Users\Constants\InputProperties;
use PoPCMSSchema\Users\FilterInputs\EmailFilterInput;
use PoPCMSSchema\Users\FilterInputs\UsernameFilterInput;
use PoPCMSSchema\Users\Module;
use PoPCMSSchema\Users\ModuleConfiguration;
use PoPSchema\SchemaCommons\TypeResolvers\ScalarType\EmailScalarTypeResolver;
class UserByOneofInputObjectTypeResolver extends AbstractOneofQueryableInputObjectTypeResolver
{
private ?IDScalarTypeResolver $idScalarTypeResolver = null;
private ?StringScalarTypeResolver $stringScalarTypeResolver = null;
private ?EmailScalarTypeResolver $emailScalarTypeResolver = null;
private ?IncludeFilterInput $includeFilterInput = null;
private ?UsernameFilterInput $usernameFilterInput = null;
private ?EmailFilterInput $emailFilterInput = null;
final public function setIDScalarTypeResolver(IDScalarTypeResolver $idScalarTypeResolver): void
{
$this->idScalarTypeResolver = $idScalarTypeResolver;
}
final protected function getIDScalarTypeResolver(): IDScalarTypeResolver
{
if ($this->idScalarTypeResolver === null) {
/** @var IDScalarTypeResolver */
$idScalarTypeResolver = $this->instanceManager->getInstance(IDScalarTypeResolver::class);
$this->idScalarTypeResolver = $idScalarTypeResolver;
}
return $this->idScalarTypeResolver;
}
final public function setStringScalarTypeResolver(StringScalarTypeResolver $stringScalarTypeResolver): void
{
$this->stringScalarTypeResolver = $stringScalarTypeResolver;
}
final protected function getStringScalarTypeResolver(): StringScalarTypeResolver
{
if ($this->stringScalarTypeResolver === null) {
/** @var StringScalarTypeResolver */
$stringScalarTypeResolver = $this->instanceManager->getInstance(StringScalarTypeResolver::class);
$this->stringScalarTypeResolver = $stringScalarTypeResolver;
}
return $this->stringScalarTypeResolver;
}
final public function setEmailScalarTypeResolver(EmailScalarTypeResolver $emailScalarTypeResolver): void
{
$this->emailScalarTypeResolver = $emailScalarTypeResolver;
}
final protected function getEmailScalarTypeResolver(): EmailScalarTypeResolver
{
if ($this->emailScalarTypeResolver === null) {
/** @var EmailScalarTypeResolver */
$emailScalarTypeResolver = $this->instanceManager->getInstance(EmailScalarTypeResolver::class);
$this->emailScalarTypeResolver = $emailScalarTypeResolver;
}
return $this->emailScalarTypeResolver;
}
final public function setIncludeFilterInput(IncludeFilterInput $includeFilterInput): void
{
$this->includeFilterInput = $includeFilterInput;
}
final protected function getIncludeFilterInput(): IncludeFilterInput
{
if ($this->includeFilterInput === null) {
/** @var IncludeFilterInput */
$includeFilterInput = $this->instanceManager->getInstance(IncludeFilterInput::class);
$this->includeFilterInput = $includeFilterInput;
}
return $this->includeFilterInput;
}
final public function setUsernameFilterInput(UsernameFilterInput $usernameFilterInput): void
{
$this->usernameFilterInput = $usernameFilterInput;
}
final protected function getUsernameFilterInput(): UsernameFilterInput
{
if ($this->usernameFilterInput === null) {
/** @var UsernameFilterInput */
$usernameFilterInput = $this->instanceManager->getInstance(UsernameFilterInput::class);
$this->usernameFilterInput = $usernameFilterInput;
}
return $this->usernameFilterInput;
}
final public function setEmailFilterInput(EmailFilterInput $emailFilterInput): void
{
$this->emailFilterInput = $emailFilterInput;
}
final protected function getEmailFilterInput(): EmailFilterInput
{
if ($this->emailFilterInput === null) {
/** @var EmailFilterInput */
$emailFilterInput = $this->instanceManager->getInstance(EmailFilterInput::class);
$this->emailFilterInput = $emailFilterInput;
}
return $this->emailFilterInput;
}
public function getTypeName(): string
{
return 'UserByInput';
}
public function getTypeDescription(): ?string
{
return $this->__('Oneof input to specify the property and data to fetch a user', 'users');
}
/**
* @return array<string,InputTypeResolverInterface>
*/
public function getInputFieldNameTypeResolvers(): array
{
return [
InputProperties::ID => $this->getIDScalarTypeResolver(),
InputProperties::USERNAME => $this->getStringScalarTypeResolver(),
InputProperties::EMAIL => $this->getEmailScalarTypeResolver(),
];
}
/**
* @return string[]
*/
public function getSensitiveInputFieldNames(): array
{
$sensitiveInputFieldNames = parent::getSensitiveInputFieldNames();
/** @var ModuleConfiguration */
$moduleConfiguration = App::getModule(Module::class)->getConfiguration();
if ($moduleConfiguration->treatUserEmailAsSensitiveData()) {
$sensitiveInputFieldNames[] = InputProperties::EMAIL;
}
return $sensitiveInputFieldNames;
}
public function getInputFieldDescription(string $inputFieldName): ?string
{
return match ($inputFieldName) {
InputProperties::ID => $this->__('Query by user ID', 'users'),
InputProperties::USERNAME => $this->__('Query by username', 'users'),
InputProperties::EMAIL => $this->__('Query by email', 'users'),
default => parent::getInputFieldDescription($inputFieldName),
};
}
public function getInputFieldFilterInput(string $inputFieldName): ?FilterInputInterface
{
return match ($inputFieldName) {
InputProperties::ID => $this->getIncludeFilterInput(),
InputProperties::USERNAME => $this->getUsernameFilterInput(),
InputProperties::EMAIL => $this->getEmailFilterInput(),
default => parent::getInputFieldFilterInput($inputFieldName),
};
}
}