承接 somnambulist/api-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

somnambulist/api-bundle

Composer 安装命令:

composer require somnambulist/api-bundle

包简介

Adds infrastructure for creating an API with documentation, response handling, and more.

README 文档

README

GitHub Actions Build Status Issues License PHP Version Current Version

Provides several helpers and support objects for better handling League Fractal with Symfony. The integration with Fractal is based on Dingo API for Laravel: https://github.com/dingo/api

Requirements

  • PHP 8.4+
  • somnambulist/fractal-bundle
  • symfony/twig-bundle (for documentation output)

Installation

Install using composer, or checkout / pull the files from github.com.

  • composer require somnambulist/api-bundle

Usage

Add the SomnambulistApiBundle to your bundles.php list and add a config file in packages if you wish to configure the bundle. The following options can be set:

somnambulist_api:
   exception_handler:
      converters:
          Assert\InvalidArgumentException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\AssertionExceptionConverter
          Assert\LazyAssertionException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\LazyAssertionExceptionConverter
          Doctrine\ORM\EntityNotFoundException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\EntityNotFoundConverter
          Doctrine\ORM\NoResultException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\EntityNotFoundConverter
          Somnambulist\Components\Models\Exceptions\EntityNotFoundException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\EntityNotFoundConverter
          Somnambulist\Components\ReadModels\Exceptions\EntityNotFoundException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\EntityNotFoundConverter
          Somnambulist\Components\ReadModels\Exceptions\NoResultsException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\EntityNotFoundConverter
          Symfony\Component\Messenger\Exception\HandlerFailedException: Somnambulist\Bundles\ApiBundle\Response\ExceptionConverters\HandlerFailedExceptionConverter
      api_root: '/api'
      doc_root: '/api/docs'
   subscribers:
      exception_to_json: true
      json_to_post: true
      request_id: true
   openapi:
      path: '%kernel.project_dir%/config/openapi'
      title: 'API Docs'
      version: '1.0.0'
      description: 'The documentation for the API'
      cache_time: 1400 # cache time in seconds for the generated docs
      tags:
          tag_name: "Description for the tag"

Extend the bundled ApiController and build your API.

Optionally you can:

BC Breaks in V5

V5 drops all previously deprecated methods and makes changes to the signatures of the transformer types. Transformer types are now readonly and cannot be modified once instantiated. This means that the constructor args have changed to include all options and the order has been revised.

All response types default to a data key name, including ObjectType that previously was null. Now, you must specify a null key to remove it. Using a data key allows for applying metadata more easily to the response object.

BC Breaks in V4

V4 updates to league/fractal 0.20.0. This adds many type hints to properties and methods. Specifically in TransformerAbstract, the various overridable arrays now require the array type hint.

In addition:

  • removed RequestArgumentHelper use FormRequests instead as they provide a cleaner, self-documenting API
  • removed the configuration for the arg helper from the bundle config
  • removed withXXX from Response\AbstractType, use key, meta, and include instead
  • the AbstractType::include() method now only accepts multiple string arguments
  • the request id header string is now set via a parameter (see docs)

Package change in V3.5.0

From 3.5.0 samj/fractal-bundle has been replaced with somnambulist/fractal-bundle as samj has been abandoned and archived. The replacement provides the same service resolution and allows transformers to be tagged as well as auto-configured.

The only code change necessary is to replace SamjFractalBundle in bundles.php with SomnambulistFractalBundle.

BC Breaks in V3

From v3.0.0 the library has been re-namespaced to Somanmbulist\Bundles\ApiBundle. Be sure to update any references.

In addition:

  • ReadModelTransformer now requires somnambulist/read-models 2.0+
  • UuidValueResolver and ExternalIdentityValueResolver now require somnambulist/domain 4.0+

BC Breaks in v2

From v2.0.0 the following changes have been made:

  • use PHP 7.4 features through-out the library
  • removed Services namespace component
  • Converters namespace was changed to ExceptionConverters
  • Transformers and ExceptionConverters are now part of the Response namespace
  • TransformerBinding has been removed in favour of Types with specific interfaces
  • ApiController methods paginate, collection, item are now strictly typed
  • withIncludes method accepts multiple string arguments instead of an array
  • all transformers should be registered as container services (transformer is now a string explicitly)

To switch from TransformerBinding replace each call to:

  • TransformerBinding::item() with new ObjectType()
  • TransformerBinding::collection() with new CollectionType() or new IterableType()
  • TransformerBinding::paginate() with new PagerfantaType() for Pagerfanta.

The constructor signatures are largely the same; except collection and pagerfanta have an additional key as the last argument, defaulted to data.

When updating, remember to update the exception converters in your somnambulist.yaml config file if using the included defaults.

Tests

PHPUnit 12+ is used for testing. Run tests via vendor/bin/phpunit.

Links

somnambulist/api-bundle 适用场景与选型建议

somnambulist/api-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.9k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「json」 「api」 「bundle」 「fractal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 somnambulist/api-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 somnambulist/api-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 somnambulist/api-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 21
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-20