Skip to content

Commit 807a525

Browse files
author
Kirill Nesmeyanov
committed
Add normalizer/denormalizer interface descriptions
1 parent 03d159b commit 807a525

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/DenormalizerInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@
55
namespace TypeLang\Mapper;
66

77
use JetBrains\PhpStorm\Language;
8+
use TypeLang\Mapper\Exception\Definition\TypeNotFoundException;
89

910
interface DenormalizerInterface
1011
{
1112
/**
13+
* Denormalizes a specific type from generic data.
14+
*
15+
* Can be used to convert to PHP values from an external data source
16+
* such as JSON, MessagePack, BSON, etc.
17+
*
18+
* ```
19+
* $denormalizer->denormalize(\json_decode('{
20+
* "id": 42,
21+
* "name": "Kirill"
22+
* }'), ExampleClass::class);
23+
* ```
24+
*
1225
* @param non-empty-string $type
1326
*/
1427
public function denormalize(mixed $value, #[Language('PHP')] string $type): mixed;
1528

1629
/**
30+
* Returns {@see true} if the value can be denormalized for the given type.
31+
*
1732
* @param non-empty-string $type
33+
* @throws TypeNotFoundException in case of type not found
34+
* @throws \Throwable in case of any internal error occurs
1835
*/
1936
public function isDenormalizable(mixed $value, #[Language('PHP')] string $type): bool;
2037
}

src/NormalizerInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,39 @@
55
namespace TypeLang\Mapper;
66

77
use JetBrains\PhpStorm\Language;
8+
use TypeLang\Mapper\Exception\Definition\TypeNotFoundException;
89

910
interface NormalizerInterface
1011
{
1112
/**
13+
* Normalizes a specific value to generic data.
14+
*
15+
* Can be used to convert to structural data (for JSON, BSON, MessagePack, etc)
16+
* from an PHP values.
17+
*
18+
* In case that the type is specified as {@see null}, it is automatically
19+
* inferred from the passed value.
20+
*
21+
* ```
22+
* $normalizer->normalize(new ExampleClass(
23+
* id: 42,
24+
* name: 'Kirill',
25+
* ));
26+
* ```
27+
*
1228
* @param non-empty-string|null $type
1329
*/
1430
public function normalize(mixed $value, #[Language('PHP')] ?string $type = null): mixed;
1531

1632
/**
33+
* Returns {@see true} if the value can be normalized for the given type.
34+
*
35+
* In case that the type is specified as {@see null}, it is automatically
36+
* inferred from the passed value.
37+
*
1738
* @param non-empty-string|null $type
39+
* @throws TypeNotFoundException in case of type not found
40+
* @throws \Throwable in case of any internal error occurs
1841
*/
1942
public function isNormalizable(mixed $value, #[Language('PHP')] ?string $type = null): bool;
2043
}

0 commit comments

Comments
 (0)