-
Notifications
You must be signed in to change notification settings - Fork 48
/
SetValue.php
38 lines (30 loc) · 967 Bytes
/
SetValue.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
<?php
declare(strict_types=1);
namespace Smile\GdprDump\Converter\Generator;
use Smile\GdprDump\Converter\ConverterInterface;
use Smile\GdprDump\Converter\Parameters\ValidationException;
class SetValue implements ConverterInterface
{
private mixed $value;
/**
* @inheritdoc
*/
public function setParameters(array $parameters): void
{
// The parameter must be specified, but accepts empty values
if (!array_key_exists('value', $parameters)) {
throw new ValidationException('The parameter "value" is required.');
}
if ($parameters['value'] !== null && !is_scalar($parameters['value'])) {
throw new ValidationException('The parameter "value" must be a scalar or null.');
}
$this->value = $parameters['value'];
}
/**
* @inheritdoc
*/
public function convert(mixed $value, array $context = []): mixed
{
return $this->value;
}
}