Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generate Data Transfer Objects directly from JSON objects

License

NotificationsYou must be signed in to change notification settings

atymic/json2dto

Repository files navigation

Build StatusStyleCILatest Version on PackagistTotal Downloads

Spatie's Data Transfer Object library is awesome, but typing out DTOscan quickly become a chore. Inspired by Json2Typescript style tools, we built one for PHP DTOs.

Web Version

Try it out athttps://json2dto.atymic.dev
The web version has all of the same tools as the cli version in an easy to use GUI. When generating nested DTOs, thetool will create a zip file.

CLI Tool

Prefer to use the tool locally? You can installjson2dto via composer and generate files directly from json files.

composer global require atymic/json2dto# Install Globallycomposer require atymic/json2dto --dev# Install locally in a project

Usage

The tool accepts json input either as a filename (second argument) or viastdin.
You should run the tool in the root of your project (where yourcomposer.json is located) as it will resolve namespacesbased on your PSR4 autoloading config. If you aren't using PSR4, your generated folder structure might not match.

Examples

# Generate PHP 7.4 typed DTO./vendor/bin/json2dto generate"App\DTO" test.json -name"Test" --typed# Generate PHP 8.0 typed DTO (DTO V3)./vendor/bin/json2dto generate"App\DTO" test.json -name"Test" --v3# Generate a flexible DTO (with nested DTOs)./vendor/bin/json2dto generate"App\DTO" test.json -name"Test" --nested --flexible# Generate a DTO from stdinwget http://example.com/cat.json| ./vendor/bin/json2dto generate"App\DTO" -name Cat

Usage

json2dto generate [options] [--] <namespace> [<json>]Arguments:  namespace                       Namespace to generate the class(es) in  json                            File containing the json stringOptions:      --nested                    Generate nested DTOs      --typed                     Generate PHP >= 7.4 strict typing      --flexible                  Generate a flexible DTO      --dry                       Dry run, print generated files      --v3                        Generate V3 DTO  -h, --help                      Display this help message

About

Generate Data Transfer Objects directly from JSON objects

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp