-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNormalizerInterface.php
48 lines (43 loc) · 1.46 KB
/
NormalizerInterface.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
<?php
declare(strict_types=1);
namespace TypeLang\Mapper;
use TypeLang\Mapper\Exception\Definition\DefinitionException;
use TypeLang\Mapper\Exception\Mapping\RuntimeException;
interface NormalizerInterface
{
/**
* Normalizes a specific value to generic data.
*
* Can be used to convert to structural data (for JSON, BSON, MessagePack, etc)
* from an PHP values.
*
* In case that the type is specified as {@see null}, it is automatically
* inferred from the passed value.
*
* ```
* $normalizer->normalize(new ExampleClass(
* id: 42,
* name: 'Kirill',
* ));
* ```
*
* @param non-empty-string|null $type
*
* @throws RuntimeException in case of runtime mapping exception occurs
* @throws DefinitionException in case of type building exception occurs
* @throws \Throwable in case of any internal error occurs
*/
public function normalize(mixed $value, ?string $type = null): mixed;
/**
* Returns {@see true} if the value can be normalized for the given type.
*
* In case that the type is specified as {@see null}, it is automatically
* inferred from the passed value.
*
* @param non-empty-string|null $type
*
* @throws DefinitionException in case of type building exception occurs
* @throws \Throwable in case of any internal error occurs
*/
public function isNormalizable(mixed $value, ?string $type = null): bool;
}