awaiskhan18/resman 问题修复 & 功能扩展

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

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

awaiskhan18/resman

最新稳定版本:v1.0

Composer 安装命令:

composer require awaiskhan18/resman

包简介

ResMan is a PHP class that provides a convenient way to handle API responses with standard status codes and response structures. It includes methods for handling validation errors, success responses, and failure responses.

README 文档

README

ResMan is a PHP class that provides a convenient way to handle API responses with standard status codes and response structures. It includes methods for handling validation errors, success responses, and failure responses.

Installation

To use ResMan in your project, you can install it via Composer. Run the following command in your terminal:

composer require awaiskhan18/resman

Usage

First, import the ResMan class into your PHP file:


use Awaiskhan18\ResMan;

Handling Validation Errors

To handle validation errors, you can use the validationHandler method of the ResMan class. It takes a validator object as its parameter and returns a JSON response with the appropriate status code and error messages.


// Example usage of validationHandler
$validator = Validator::make($data, $rules);

if ($validator->fails()) {
    return ResMan::validationHandler($validator);
}

Handling Success Responses

To handle success responses, you can use the successHandler method of the ResMan class. It takes the response data and a status description as its parameters and returns a JSON response with the success status code (200) and the provided data.


// Example usage of successHandler
$data = [
    'user' => [
        'name' => 'John Doe',
        'email' => 'john@example.com',
    ],
];

$statusDescription = 'Data retrieved successfully';

return ResMan::successHandler($data, $statusDescription);

Constants

ResMan includes the following constants that can be used to represent different HTTP status codes:

ResMan::STATUS_SUCCESS (200) - Represents a successful response.
ResMan::STATUS_ERROR (401) - Represents an error response.

License

This package is open-source software licensed under the MIT License. See the LICENSE file for more information.

统计信息

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

GitHub 信息

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

其他信息

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