-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScalarCodec.php
More file actions
28 lines (24 loc) · 988 Bytes
/
Copy pathScalarCodec.php
File metadata and controls
28 lines (24 loc) · 988 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
<?php
declare(strict_types=1);
namespace TinyBlocks\Mapper;
use Attribute;
/**
* Declares how a type converts to and from a scalar, by naming the methods the mapper calls.
*
* <p>Each attribute is one decode and encode pair, and the attribute is repeatable. On read, the pair whose
* decode parameter type accepts the source scalar is used, so a type can be built from more than one scalar
* form. On write, the first declared pair's encode is used. A registered mapping for the same type takes
* precedence over this attribute.</p>
*
* <p>The decode method is a public static factory that builds the type from the scalar, and the encode method
* a public instance method that reduces the type back to a scalar.</p>
*
* @see Codec for the registered, closure-based equivalent.
*/
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final readonly class ScalarCodec
{
public function __construct(public string $decode, public string $encode)
{
}
}