codexsoft/transmission-ts-converter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codexsoft/transmission-ts-converter

Composer 安装命令:

composer require codexsoft/transmission-ts-converter

包简介

Typescript converter for CodexSoft Transmission library for building HTTP API

README 文档

README

This library provides a way to convert Transmission elements into typescript interfaces (recursively). It supports references.

Installation

composer require codexsoft/transmission-ts-converter

Extending

By default, only basic element classes can be converted: CollectionElement, JsonElement, StringElement, NumberElement, BoolElement, ScalarElement. You can add your own converters (each needs to extend CodexSoft\Transmission\Typescript\Converters\AbstractElementTsConverter)

$toTs = (new TransmissionToTypescriptConverter());
$toTs->addKnownConverter(MyElement::class => MyElementTsConverter::class);

Usage

Using this utility you can generate SDK for typescript. For given directory with controllers that implement CodexSoft\Transmission\OpenApi3\OpenApi3OperationInterface generator of whole API can be easily implemented.

// ...preparing Symfony Finder or whatever
$endpointReflections = [];
foreach ($finder->getIterator() as $fileInfo) {
    $fqnClassName = (string) 'App'.(new \Stringy\Stringy($fileInfo->getRealPath()))
        ->removeRight('.php')
        ->replace('/', "\\");
        
    $reflectionClass = new \ReflectionClass($fqnClassName);
    if ($reflectionClass->isAbstract()) {
        continue;
    }

    if (!$reflectionClass->implementsInterface(OpenApi3OperationInterface::class)) {
        continue;
    }
    
    $endpointReflections[] = $reflectionClass;
    
    $toTs = (new TransmissionToTypescriptConverter());
    
    /**
     * Set ref interface name generator
     */
    $toTs->setCreateRefClosure(function(string $class) {
        $reflection = new \ReflectionClass($class);
        return (string) (new \Stringy\Stringy('I'.$reflection->getShortName()))->removeRight('Transformer');
    });
}
    

Testing

php ./vendor/bin/phpunit

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固