Skip to content

Commit 6e524ab

Browse files
committed
Add DataConfiguration documentation and improve doc notes
Introduces a new `DataConfiguration.md` file to explain configuration handling. Updates existing documentation with improved note formatting for clarity. Adjusts code structure in configuration-related files for better serialization and normalization setup.
1 parent a196f1a commit 6e524ab

File tree

9 files changed

+61
-23
lines changed

9 files changed

+61
-23
lines changed

docs/CloneableData.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ $todoWithDueDate = $todo->with(
5353
);
5454
```
5555

56-
> We are using the `empty` method
56+
> **Note:** We are using the `empty` method
5757
> from [Empty Data](https://github.com/nuxtifyts/php-dto/blob/main/docs/EmptyData.md)
5858
> here
5959
60-
> `emptyTodo`, `todo` and `todoWithDueDate` are all different instances.
60+
> **Important:** `emptyTodo`, `todo` and `todoWithDueDate` are all different instances.
6161
6262
Computed properties
6363
-

docs/DataConfiguration.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Data Configuration
2+
=
3+
4+
The library uses a configuration based approach to define, load and save data.
5+
It uses a `DataConfiguration` object to define many things:
6+
7+
```php
8+
use Nuxtifyts\PhpDto\Configuration\DataConfiguration;
9+
10+
$config = DataConfiguration::getInstance();
11+
```
12+
13+
The function's signature is:
14+
15+
| Argument | Type | Description |
16+
|-------------|---------------|-------------------------------------------------------------------------------------------------|
17+
| config | array \| null | The configuration array to load, by default it's `null`, which means switch to default configs. |
18+
| forceCreate | bool | If `true`, it will create a new instance of `DataConfiguration` even if it's already created. |
19+
20+
If nothing is passed, it will be the equivalent of:
21+
22+
```php
23+
DataConfiguration::getInstance([
24+
'normalizers' => [
25+
'baseNormalizers' => [
26+
JsonStringNormalizer::class,
27+
StdClassNormalizer::class,
28+
ArrayAccessNormalizer::class,
29+
ArrayNormalizer::class,
30+
],
31+
],
32+
33+
'serializers' => [
34+
'baseSerializers' => [
35+
ArraySerializer::class,
36+
DataSerializer::class,
37+
DateTimeSerializer::class,
38+
BackedEnumSerializer::class,
39+
ScalarTypeSerializer::class,
40+
]
41+
]
42+
])
43+
```

docs/DefaultValues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class UserConfigDataFallbackResolver implements FallbackResolver
7070
}
7171
```
7272

73-
>! When using `DefaultsTo` attribute, priority is given to the attribute instead of the parameter's default value.
73+
> When using `DefaultsTo` attribute, priority is given to the attribute instead of the parameter's default value.
7474
7575
If ever needed to create a new instance of a DTO with complex default value,
7676
using the constructor is no longer possible, instead, you can make use of the

docs/EmptyData.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ By calling the `empty()` method, we can create a new instance of the `TodoData`
3636
$emptyTodo = TodoData::empty();
3737
```
3838

39-
> This is really useful with [Cloneable Data](https://github.com/nuxtifyts/php-dto/blob/main/docs/CloneableData.md)
39+
> **Note:** This is really useful with [Cloneable Data](https://github.com/nuxtifyts/php-dto/blob/main/docs/CloneableData.md)
4040
4141
The `$emptyTodo` variable will contain the following data:
4242

docs/Normalizers.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ data into (preferable) an `array`/`ArrayAccess`.
77
By default, there are 4 normalizers:
88

99
- **JsonStringNormalizer** will cast json string.
10-
- **StrClassNormalizer** will cast stdObject.
10+
- **StdClassNormalizer** will cast stdObject.
1111
- **ArrayAccessNormalizer** will cast ArrayAccess.
1212
- **ArrayNormalizer** will cast array.
1313

14+
> **Note:** In order to adjust there default normalizers, for example, you don't need
15+
> to use the `StdClassNormalizer` and you want to simply remove it, you need
16+
> to [configure](https://github.com/nuxtifyts/php-dto/blob/main/docs/DataConfiguration.md)
17+
> the `DataConfiguration` object.
18+
1419
Custom normalizers:
1520
=
1621

docs/Quickstart.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ can be found here:
8181
- [Data Refiners](https://github.com/nuxtifyts/php-dto/blob/main/docs/DataRefiners.md)
8282
- [Empty Data](https://github.com/nuxtifyts/php-dto/blob/main/docs/EmptyData.md)
8383
- [Cloneable Data](https://github.com/nuxtifyts/php-dto/blob/main/docs/CloneableData.md)
84+
- [Data Configuration](https://github.com/nuxtifyts/php-dto/blob/main/docs/DataConfiguration.md)

src/Configuration/DataConfiguration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class DataConfiguration implements Configuration
1010
protected static ?self $instance = null;
1111

1212
protected function __construct(
13-
protected(set) SerializersConfiguration $serializers,
1413
protected(set) NormalizersConfiguration $normalizers,
14+
protected(set) SerializersConfiguration $serializers,
1515
) {
1616
}
1717

@@ -29,13 +29,13 @@ public static function getInstance(
2929
}
3030

3131
return self::$instance = new self(
32-
serializers: SerializersConfiguration::getInstance(
33-
Arr::getArray($config ?? [], 'serializers'),
34-
$forceCreate
35-
),
3632
normalizers: NormalizersConfiguration::getInstance(
3733
Arr::getArray($config ?? [], 'normalizers'),
3834
$forceCreate
35+
),
36+
serializers: SerializersConfiguration::getInstance(
37+
Arr::getArray($config ?? [], 'serializers'),
38+
$forceCreate
3939
)
4040
);
4141
}

src/Configuration/NormalizersConfiguration.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ class NormalizersConfiguration implements Configuration
1818
* @param array<array-key, class-string<Normalizer>> $baseNormalizers
1919
*/
2020
protected function __construct(
21-
protected(set) array $baseNormalizers = [
22-
JsonStringNormalizer::class,
23-
StdClassNormalizer::class,
24-
ArrayAccessNormalizer::class,
25-
ArrayNormalizer::class,
26-
]
21+
protected(set) array $baseNormalizers
2722
) {
2823
}
2924

src/Configuration/SerializersConfiguration.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ class SerializersConfiguration implements Configuration
1919
* @param array<array-key, class-string<Serializer>> $baseSerializers
2020
*/
2121
protected function __construct(
22-
protected(set) array $baseSerializers = [
23-
ArraySerializer::class,
24-
DataSerializer::class,
25-
DateTimeSerializer::class,
26-
BackedEnumSerializer::class,
27-
ScalarTypeSerializer::class,
28-
],
22+
protected(set) array $baseSerializers,
2923
) {
3024
}
3125

0 commit comments

Comments
 (0)