Skip to content

Commit 6d7e892

Browse files
committed
wip
1 parent 489c0e4 commit 6d7e892

File tree

9 files changed

+22
-130
lines changed

9 files changed

+22
-130
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [4.0.0] - 2025-05-20
10+
## [4.0.0] - 2025-06-08
1111

1212
### Added
1313

1414
- Attribute `OpenSoutheners\LaravelDto\Attributes\Inject` to inject container stuff
1515
- Attribute `OpenSoutheners\LaravelDto\Attributes\Authenticated` that uses base `Illuminate\Container\Attributes\Authenticated` to inject current authenticated user
1616
- Ability to register custom mappers (extending package functionality)
17+
- `OpenSoutheners\LaravelDto\Contracts\MapeableObject` interface to add custom mapping logic to your own objects classes
1718
- ObjectMapper now extracts type info from generics inside collections typed properties [#1]
1819

1920
### Changed
2021

22+
- Package renamed to `open-southeners/laravel-data-mapper`
23+
- Config file changed and renamed to `config/data-mapper.php` (publish the new one using `php artisan vendor:publish --tag="laravel-data-mapper"`)
2124
- Full refactor [#7]
2225

2326
### Removed
2427

2528
- Abstract class `OpenSoutheners\LaravelDto\DataTransferObject` (using POPO which means _Plain Old Php Objects_)
2629
- Attribute `OpenSoutheners\LaravelDto\Attributes\WithDefaultValue` (when using with `Illuminate\Contracts\Auth\Authenticatable` can be replaced by `OpenSoutheners\LaravelDto\Attributes\Authenticated`)
30+
- Artisan commands: `make:dto`, `dto:typescript`
2731

2832
## [3.7.0] - 2025-03-04
2933

File renamed without changes.

src/Mappers/ObjectDataMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function normalisePropertyKey(MappingValue $mappingValue, string $key)
108108
$class = new ReflectionClass($mappingValue->objectClass);
109109

110110
$normaliseProperty = count($class->getAttributes(NormaliseProperties::class)) > 0
111-
?: (app('config')->get('data-transfer-objects.normalise_properties') ?? true);
111+
?: (app('config')->get('data-mapper.normalise_properties') ?? true);
112112

113113
if (! $normaliseProperty) {
114114
return $key;

src/ServiceProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ public function boot()
3232
{
3333
if ($this->app->runningInConsole()) {
3434
$this->publishes([
35-
__DIR__.'/../config/data-transfer-objects.php' => config_path('data-transfer-objects.php'),
36-
], 'config');
37-
38-
$this->commands([DtoMakeCommand::class, DtoTypescriptGenerateCommand::class]);
35+
__DIR__.'/../config/data-mapper.php' => config_path('data-mapper.php'),
36+
], ['config', 'laravel-data-mapper']);
3937
}
4038

4139
$this->app->beforeResolving(

src/Support/TypeScript.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Support\Collection;
88
use Illuminate\Support\Facades\Schema;
9+
use OpenSoutheners\LaravelDto\Attributes\AsType;
910
use OpenSoutheners\LaravelDto\Contracts\MapeableObject;
1011
use OpenSoutheners\LaravelDto\DataTransferObjects\MappingValue;
1112
use OpenSoutheners\LaravelDto\PropertyInfoExtractor;
13+
use ReflectionClass;
1214
use Stringable;
1315
use Symfony\Component\TypeInfo\Type;
1416
use Symfony\Component\TypeInfo\TypeIdentifier;
@@ -78,6 +80,16 @@ public function fromClass(string $class): self
7880

7981
private function typeName(string $class): string
8082
{
83+
$reflectionClass = new ReflectionClass($class);
84+
85+
$attributes = $reflectionClass->getAttributes(AsType::class);
86+
87+
$asTypeAttribute = reset($attributes);
88+
89+
if ($asTypeAttribute) {
90+
return $asTypeAttribute->newInstance()->typeName;
91+
}
92+
8193
return class_basename($class);
8294
}
8395

tests/Integration/DataTransferObjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function test_data_transfer_object_filled_via_request()
114114

115115
public function test_data_transfer_object_without_property_keys_normalisation_when_disabled_from_config()
116116
{
117-
config(['data-transfer-objects.normalise_properties' => false]);
117+
config(['data-mapper.normalise_properties' => false]);
118118

119119
$post = Post::create([
120120
'id' => 2,

tests/Integration/DtoMakeCommandTest.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

tests/Integration/DtoTypescriptGenerateCommandTest.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/Integration/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ protected function defineEnvironment($app)
3737
'prefix' => '',
3838
]);
3939

40-
$app['config']->set('data-transfer-objects', include_once __DIR__.'/../../config/data-transfer-objects.php');
40+
$app['config']->set('data-mapper', include_once __DIR__.'/../../config/data-mapper.php');
4141
}
4242
}

0 commit comments

Comments
 (0)