1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Validation\Rules\Generic; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2020 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Limoncello\Validation\Contracts\Execution\ContextInterface; |
22
|
|
|
use Limoncello\Validation\Rules\ExecuteRule; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @package Limoncello\Validation |
26
|
|
|
*/ |
27
|
|
|
final class Value extends ExecuteRule |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Property key. |
31
|
|
|
*/ |
32
|
|
|
private const PROPERTY_VALUE = self::PROPERTY_LAST + 1; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param array $value |
36
|
|
|
*/ |
37
|
1 |
|
public function __construct($value) |
38
|
|
|
{ |
39
|
1 |
|
parent::__construct([ |
40
|
1 |
|
static::PROPERTY_VALUE => $value, |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param mixed $value |
46
|
|
|
* @param ContextInterface $context |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
* |
50
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
51
|
|
|
*/ |
52
|
1 |
|
public static function execute($value, ContextInterface $context): array |
53
|
|
|
{ |
54
|
1 |
|
$value = $context->getProperties()->getProperty(static::PROPERTY_VALUE); |
55
|
|
|
|
56
|
1 |
|
return static::createSuccessReply($value); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|