netlogix/webapi 问题修复 & 功能扩展

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

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

netlogix/webapi

Composer 安装命令:

composer require netlogix/webapi

包简介

Create jsonapi.org web apis in flow

README 文档

README

Installation

composer require netlogix/webapi

Accept-header driven exception handling

The package ships a PSR-15 middleware that catches exceptions inside the middleware chain and turns them into a ResponseInterface. This way, any response-decorating middleware (most importantly Sitegeist.OffCORS:CorsMiddleware) sees a real response on errors and can add its headers — which the default Flow exception path, running through set_exception_handler, would bypass.

Components

  • Netlogix\WebApi\Http\Middleware\ExceptionToResponseMiddleware Catches any Throwable thrown by downstream middlewares and delegates rendering to the dispatcher below. Registered via Configuration/Settings.Middleware.yaml directly after Sitegeist.OffCORS:CorsMiddleware.
  • Netlogix\WebApi\Error\AcceptHeaderDependingExceptionHandler Picks one of the configured Flow ExceptionHandlerInterface implementations based on the request's Accept header (proper content negotiation via Neos\Flow\Http\Helper\MediaTypeHelper), invokes it, and adapts its header() / echo style output into a PSR-7 response.
  • Netlogix\WebApi\Error\JsonExceptionHandler Renders the throwable as a jsonapi.org-style error document ({"errors": [{…}]}) mirroring the shape produced by Netlogix\JsonApiOrg\Controller\ApiController::errorAction(). For plain throwables the entry carries code and title, plus an optional id from WithReferenceCodeInterface. Production-safe variant — does not publish the exception message.
  • Netlogix\WebApi\Error\JsonDebugExceptionHandler Same envelope as JsonExceptionHandler, but for plain throwables the error entry additionally carries detail (the exception message) and a meta block with exceptionType, file, line, a sanitized trace (frame args stripped) and a recursive meta.previous chain — analogous to how Neos\Flow\Error\DebugExceptionHandler extends the ProductionExceptionHandler. Reserved for non-production contexts.

Exceptions implementing JsonSerializable provide the body of one error entry (the jsonapi.org fields, e.g. code / title / detail / meta). Both handlers wrap that body in the standard {"errors": […]} envelope, so the exception decides its own representation but never the response shape.

Configuration

Configure renderers per media type under Netlogix.WebApi.error.availableErrorHandlers. The shape of the options entry mirrors Flow's own Neos.Flow.error.exceptionHandler (defaultRenderingOptions, renderingGroups, …), so the values can be copy-pasted between the two.

Netlogix:
  WebApi:
    error:
      availableErrorHandlers:
        'application/vnd.api+json':
          className: 'Netlogix\WebApi\Error\JsonExceptionHandler'
        'application/json':
          className: 'Netlogix\WebApi\Error\JsonExceptionHandler'
        '*':
          className: 'Neos\Flow\Error\ProductionExceptionHandler'
          options:
            defaultRenderingOptions:
              renderTechnicalDetails: false
              logException: true
  • Keys are IANA media types; the request's Accept header is negotiated against them, respecting q-values and */* ranges.
  • The special key * is the fallback used when no configured media type matches the request's preferences. If * is missing and nothing else matches, the exception escapes back to Flow's set_exception_handler chain.
  • The shipped Configuration/Development/Settings.ExceptionHandler.yaml swaps every renderer for its debug counterpart: Neos\Flow\Error\DebugExceptionHandler for the * fallback and Netlogix\WebApi\Error\JsonDebugExceptionHandler for both JSON media types — mirroring how Flow itself replaces the production handler with the debug variant in Development.

Logging

Logging is delegated entirely to the resolved Flow ExceptionHandler (logException in its rendering options drives ThrowableStorage); the middleware itself does not log.

netlogix/webapi 适用场景与选型建议

netlogix/webapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 305.07k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 netlogix/webapi 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-29