sinema/json-api-error
最新稳定版本:0.8
Composer 安装命令:
composer require sinema/json-api-error
包简介
Format generic JSON:API errors
README 文档
README
Spec
https://jsonapi.org/examples/#error-objects-basics
Installation
composer require sinema/json-api-error
Usage
Basic Usage
<?php use Sinemah\JsonApi\Error\Error; use Sinemah\JsonApi\Error\ErrorBag; $errors = new ErrorBag(); $errors->add( Error::fromArray( [ 'status' => 404, 'source' => null, 'title' => 'Item not found', 'detail' => sprintf('Item %s not found', 'some-id'), ] ) ); $errors->toArray()
Result as JSON representation
[
{
"status": 404,
"title": "Item not found",
"detail": "Item some-id not found"
}
]
Response Usage
<?php use Sinemah\JsonApi\Error\Error; use Sinemah\JsonApi\Error\Response; $response = Response::get(); $response->add( Error::fromArray( [ 'status' => 404, 'source' => null, 'title' => 'Item not found', 'detail' => sprintf('Item %s not found', 'some-id'), ] ) ); $response->toArray()
Result as JSON representation
{
"errors": [
{
"status": 404,
"title": "Item not found",
"detail": "Item some-id not found"
}
]
}
统计信息
- 总下载量: 3.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-16