-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathUpdateImpostazioneProcessor.php
More file actions
33 lines (25 loc) · 991 Bytes
/
UpdateImpostazioneProcessor.php
File metadata and controls
33 lines (25 loc) · 991 Bytes
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
<?php
namespace Modules\Impostazioni\API\Controllers;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use Models\Setting;
use Modules\Impostazioni\API\Models\UpdateImpostazioneRequest;
use Modules\Impostazioni\API\Models\UpdateImpostazioneResponse;
final class UpdateImpostazioneProcessor implements ProcessorInterface
{
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): UpdateImpostazioneResponse
{
if (!$data instanceof UpdateImpostazioneRequest) {
throw new \InvalidArgumentException();
}
$id = $uriVariables['id'];
$response = new UpdateImpostazioneResponse();
$impostazione = Setting::find($id);
if (!$impostazione->editable) {
$response->edited = true;
return $response;
}
$response->edited = \Settings::setValue($impostazione->id, $data->valore);
return $response;
}
}