@@ -4,6 +4,7 @@ Property Attributes
44In order to provide more functionality to your DTOs, you can use the following attributes:
55- [ Computed] ( #Computed ) - To define a property that is computed from other properties.
66- [ Aliases] ( #Aliases ) - To define aliases for a property.
7+ - [ CipherTarget] ( #CipherTarget ) - To define a property that should be encrypted/decrypted.
78
89Computed
910-
@@ -46,10 +47,65 @@ final readonly class Person extends Data
4647 public function __construct(
4748 #[Aliases('first_name')]
4849 public string $firstName,
49- #[Aliases('last_name')]
50+ #[Aliases('last_name', 'family_name' )]
5051 public string $lastName
5152 ) {}
5253}
5354```
5455
5556This will make it possible to hydrate properties from multiple array keys.
57+
58+ CipherTarget
59+ -
60+
61+ Sometimes, we may need to specify that some properties are considered sensitive, and should be
62+ handled carefully, especially when saving it.
63+
64+ For this we can use encryption/decryption using the ` CipherTarget ` attribute.
65+
66+ ``` php
67+ use Nuxtifyts\PhpDto\Data;
68+ use Nuxtifyts\PhpDto\Attributes\Property\Types\ArrayOfData;
69+ use Nuxtifyts\PhpDto\Attributes\Property\CipherTarget;
70+
71+ final readonly class User extends Data
72+ {
73+ /**
74+ * @param list<UserConfigData > $userConfigs
75+ */
76+ public function __construct(
77+ #[ArrayOfData(UserConfigData::class)]
78+ #[CipherTarget(
79+ secret: 'user-configs-secret-key', // By default, it uses the class name
80+ encoded: true // By default, it does not perform encoding
81+ )]
82+ public array $userConfigs
83+ ) {}
84+ }
85+
86+ ```
87+
88+ it is also possible to specify a custom DataCipher for the property,
89+ the new class should implement the ` Nuxtifyts\PhpDto\DataCipher ` interface.
90+
91+ ``` php
92+
93+ use Nuxtifyts\PhpDto\DataCiphers\DataCipher;
94+
95+ class CustomDataCipher implements DataCipher
96+ {
97+ // Implement the interface
98+ }
99+ ```
100+
101+ Then you can specify the custom DataCipher in the ` CipherTarget ` attribute.
102+
103+ ``` php
104+ public function __construct(
105+ #[CipherTarget(
106+ dataCipherClass: CustomDataCipher::class,
107+ )]
108+ public UserConfigData $userConfig
109+ ) {}
110+ ```
111+
0 commit comments