From 8b55ad611f11ca172e57b45c338addc3e183dc15 Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 10 Jan 2025 20:20:47 +0300 Subject: [PATCH] New mappers added: `LowerCaseMapper` and `UpperCaseMapper` --- docs/as-a-resource/mapping-property-names.md | 33 ++++++++++++++++++++ src/Mappers/LowerCaseMapper.php | 15 +++++++++ src/Mappers/UpperCaseMapper.php | 15 +++++++++ tests/MappingTest.php | 14 +++++++++ 4 files changed, 77 insertions(+) create mode 100644 src/Mappers/LowerCaseMapper.php create mode 100644 src/Mappers/UpperCaseMapper.php diff --git a/docs/as-a-resource/mapping-property-names.md b/docs/as-a-resource/mapping-property-names.md index 770107b6e..bf26a62e0 100644 --- a/docs/as-a-resource/mapping-property-names.md +++ b/docs/as-a-resource/mapping-property-names.md @@ -80,3 +80,36 @@ And a transformed version of the data object will look like this: 'record_company' => 'RCA Records', ] ``` + +### Available mappers: + +```php +class ContractData extends Data +{ + public function __construct( + #[MapName(CamelCaseMapper::class)] + public string $name, + #[MapName(SnakeCaseMapper::class)] + public string $recordCompany, + #[MapName(new ProvidedNameMapper('country field'))] + public string $country, + #[MapName(StudlyCaseMapper::class)] + public string $cityName, + #[MapName(LowerCaseMapper::class)] + public string $addressLine1, + #[MapName(UpperCaseMapper::class)] + public string $addressLine2, + ) { + } +} +``` +```php +[ + 'name' => 'Rick Astley', + 'record_company' => 'RCA Records', + 'country field' => 'Belgium', + 'CityName' => 'Antwerp', + 'addressline1' => 'some address line 1', + 'ADDRESSLINE2' => 'some address line 2', +] +``` diff --git a/src/Mappers/LowerCaseMapper.php b/src/Mappers/LowerCaseMapper.php new file mode 100644 index 000000000..732592e12 --- /dev/null +++ b/src/Mappers/LowerCaseMapper.php @@ -0,0 +1,15 @@ + 'camelCase', 'snake_case' => 'snake_case', 'StudlyCase' => 'StudlyCase', + 'lowercase' => 'lowercase', + 'UPPERCASE' => 'UPPERCASE', 'i_provided' => 'provided', ]); @@ -343,10 +353,14 @@ public function __construct( 'camelCase' => 'camelCase', 'snake_case' => 'snake_case', 'StudlyCase' => 'StudlyCase', + 'lowercase' => 'lowercase', + 'UPPERCASE' => 'UPPERCASE', 'i_provided' => 'provided', ])) ->camel_case->toBe('camelCase') ->snakeCase->toBe('snake_case') ->studly_case->toBe('StudlyCase') + ->lowercase->toBe('lowercase') + ->uppercase->toBe('UPPERCASE') ->provided->toBe('provided'); });