Skip to content

Commit 1a75749

Browse files
author
awu
committed
DataMapperSymfony implementation and add usage example in README.md
1 parent 55b72fd commit 1a75749

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,37 @@ data_mapper:
8282
InterfaceOrClassName: 'ClassName', # Class mapping for interfaces or other classes
8383
...: ...
8484
```
85+
86+
## Usage
87+
```php
88+
<?php
89+
90+
declare(strict_types=1);
91+
92+
namespace App\Controller;
93+
94+
use App\Dto\TestClass;
95+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
96+
use Symfony\Component\HttpFoundation\Request;
97+
use Symfony\Component\HttpFoundation\Response;
98+
use Symfony\Component\Routing\Attribute\Route;
99+
use Wundii\DataMapper\DataMapper;
100+
101+
final class YourController extends AbstractController
102+
{
103+
public function __construct(
104+
private readonly DataMapper $dataMapper,
105+
) {
106+
}
107+
108+
#[Route('/do-something/', name: 'app_do-something')]
109+
public function doSomething(Request $request): Response
110+
{
111+
$testClass = $this->dataMapper->request($request, TestClass::class);
112+
113+
// Do something with $testClass
114+
115+
return $this->json(...);
116+
}
117+
}
118+
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/console": "^6.4 || ^7.0",
2323
"symfony/dependency-injection": "^6.4||^7.0",
2424
"symfony/http-kernel": "^6.4||^7.0",
25-
"wundii/data-mapper": "^1.2.5"
25+
"wundii/data-mapper": "dev-main"
2626
},
2727
"require-dev": {
2828
"ext-dom": "*",

src/DependencyInjection/DataMapperExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Wundii\DataMapper\DataMapper;
1515
use Wundii\DataMapper\Enum\AccessibleEnum;
1616
use Wundii\DataMapper\Enum\ApproachEnum;
17+
use Wundii\DataMapper\Framework\DataMapperSymfony;
1718

1819
class DataMapperExtension extends Extension
1920
{
@@ -50,7 +51,7 @@ public function load(array $configs, ContainerBuilder $container): void
5051
]);
5152
$container->setDefinition(DataConfig::class, $dataConfigDef);
5253

53-
$dataMapperDef = new Definition(DataMapper::class, [
54+
$dataMapperDef = new Definition(DataMapperSymfony::class, [
5455
$dataConfigDef,
5556
]);
5657
$container->setDefinition(DataMapper::class, $dataMapperDef);

0 commit comments

Comments
 (0)