app-verk/api-exception-bundle 问题修复 & 功能扩展

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

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

app-verk/api-exception-bundle

最新稳定版本:1.0.6

Composer 安装命令:

composer require app-verk/api-exception-bundle

包简介

catch all Symfony 3.3 or newer errors and convert it to problem json RFC7807 response

README 文档

README

Build Status

Catch all Symfony 3.3 or newer errors and convert it to problem+json RFC7807 response

Installation:

Required the bundle with composer:

$ php composer.phar require app-verk/api-exception-bundle

Add bundle to AppKernel:

<?php
    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            
            new AppVerk\ApiExceptionBundle\AppVerkApiExceptionBundle(),
        );
    }

Configuration:

AppVerkApiProblemExceptionBundle automatically catch your errors by ApiExceptionSubscriber and return application/problem+json response:

{
  "detail": "Description of problem",
  "status": 404,
  "type": "about:blank",
  "title": "Not Found"
}

changing data structure:

Bundle provide ResponseFactoryInterface for overriding response data, if u want change response data.

Example usage:

to receive response like:

{
  "exception": {
      "detail": "Description of problem",
      "status": 404,
      "type": "about:blank",
      "title": "Not Found"
  }
}

create new CustomResponseFactory:

<?php

...
class FBExceptionResponseFactory implements ResponseFactoryInterface
{
    public function createResponse(ApiProblemInterface $apiProblem)
    {
        $data = $apiProblem->ToArray();

        $response = new JsonResponse(
            $this->prepareData($data)
        );

        $response->headers->set('Content-Type', 'application/problem+json');

        return $response;
    }

    public function prepareData($data)
    {
        return [
            'exception' => [
                $data
            ],
        ];
    }
}

Config reference:

app_verk_api_exception:
    response_factory: AppVerk\ApiExceptionBundle\Factory\ApiProblemResponseFactory
    enabled: true
    paths_excluded: ['/admin/']

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 6
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固