• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

atymic/json2dto: Generate Data Transfer Objects directly from JSON objects

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

atymic/json2dto

开源软件地址:

https://github.com/atymic/json2dto

开源编程语言:

PHP 51.4%

开源软件介绍:

Json 2 DTO

Build Status StyleCI Latest Version on Packagist Total Downloads

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

Web Version

Try it out at https://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, the tool will create a zip file.

CLI Tool

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

composer global require atymic/json2dto # Install Globally

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

Usage

The tool accepts json input either as a filename (second argument) or via stdin.
You should run the tool in the root of your project (where your composer.json is located) as it will resolve namespaces based 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 stdin
wget 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 string

Options:
      --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



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
LearnWebCode/json-example发布时间:2022-07-09
下一篇:
manton/jsonfeed-wp: WordPress plugin to add a JSON Feed to your site.发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap