Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit eebc916

Browse files
author
Andrey Helldar
authored
Merge pull request #15 from TheDragonCode/2.x
Bump `dragon-code/contracts` to `2.17`
2 parents ea2955c + 49bd5ac commit eebc916

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,40 @@ class Foo
242242
}
243243
```
244244

245+
## Helpers
246+
247+
For your convenience, starting from version [2.17](https://github.com/TheDragonCode/contracts/releases/tag/v2.17.0) of
248+
the [`dragon-code/contracts`](https://github.com/TheDragonCode/contracts/releases/tag/v2.17.0) package, we have added a new interface that declares the implementation of the
249+
public `dto` method. This way you can better control your application to return DTO objects.
250+
251+
Of course, don't forget to implement the interface 😉
252+
253+
For example:
254+
255+
```php
256+
namespace App\Http\Requests\Companies;
257+
258+
use App\Objects\Company;
259+
use DragonCode\Contracts\DataTransferObject\DataTransferObject;
260+
use DragonCode\Contracts\DataTransferObject\Dtoable;
261+
262+
class CreateRequest implements Dtoable
263+
{
264+
// ...
265+
266+
public function dto(): DataTransferObject
267+
{
268+
return Company::fromRequest($this);
269+
}
270+
}
271+
272+
// Other place
273+
public function store(CreateRequest $request)
274+
{
275+
$name = $request->dto()->name;
276+
}
277+
```
278+
245279
[badge_downloads]: https://img.shields.io/packagist/dt/dragon-code/simple-data-transfer-object.svg?style=flat-square
246280

247281
[badge_license]: https://img.shields.io/packagist/l/dragon-code/simple-data-transfer-object.svg?style=flat-square

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require": {
2424
"php": "^7.3 || ^8.0",
2525
"ext-json": "*",
26-
"dragon-code/contracts": "^2.0",
26+
"dragon-code/contracts": "^2.17",
2727
"dragon-code/support": "^5.0",
2828
"symfony/http-foundation": "^4.0 || ^5.0 || ^6.0"
2929
},

0 commit comments

Comments
 (0)