@@ -3,6 +3,7 @@ Property Attributes
33
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.
6+ - [ Hidden] ( #Hidden ) - To define a property that should not be serialized.
67- [ Aliases] ( #Aliases ) - To define aliases for a property.
78- [ DefaultsTo] ( #DefaultsTo ) - To define a default value for a property using a fallback resolver.
89- [ CipherTarget] ( #CipherTarget ) - To define a property that should be encrypted/decrypted.
@@ -33,6 +34,29 @@ final readonly class PersonData extends Data
3334
3435This will make the DTO aware of the ` fullName ` property, and it will not be serialized or deserialized.
3536
37+ Hidden
38+ -
39+
40+ Sometimes, we may need to specify that a property should not be serialized.
41+
42+ This can be done using the ` Hidden ` attribute.
43+
44+ ``` php
45+ use Nuxtifyts\PhpDto\Attributes\Property\Hidden;
46+ use Nuxtifyts\PhpDto\Data;
47+
48+ final readonly class PersonData extends Data
49+ {
50+ public function __construct(
51+ public string $firstName,
52+ #[Hidden]
53+ public string $lastName
54+ ) {}
55+ }
56+ ```
57+
58+ When serializing the DTO, the ` lastName ` property will not be included in the output.
59+
3660Aliases
3761-
3862
@@ -56,6 +80,11 @@ final readonly class PersonData extends Data
5680
5781This will make it possible to hydrate properties from multiple array keys.
5882
83+ > ** Note:** Sometimes, we may want to apply the ` Aliases ` attribute to the whole class,
84+ > in case we want to transform letter cases of all the keys in data array.
85+ > In such cases, we can use the [ MapName] ( https://github.com/nuxtifyts/php-dto/blob/main/docs/NameMapper.md )
86+ > attribute.
87+
5988CipherTarget
6089-
6190
0 commit comments