定制 neography7/easy-response 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

neography7/easy-response

最新稳定版本:1.0.0

Composer 安装命令:

composer require neography7/easy-response

包简介

Standardized response for REST APIs with easy usability.

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

Easy Response allows you to create REST Callbacks in an easy way. This package has 3 ways to create callbacks which you can use what you want. But if it's suitable for you, the helpers will be more easy and clean.

This package follows PSR-2 and PSR-4 standards.

Installation

You can install the package via composer:

composer require neography7/easy-response

Usage

There are three ways to use this package but using it with the helpers is recommended.

1) Helpers

easySuccess helper

easySuccess( message, title = null, data = null);
easySuccess(
    message: 'Test message',
    title: 'Test Title',
    data: [
        "key" => "value"
    ]
);

or like this

easySuccess('Test message', 'Test Title', [ "key" => "value" ]);

easyError helper

easyError( message, title = null, code = null, data = null);
easyError(
    message: 'Test message',
    title: 'Test Title',
    code: 400,
    data: [
        "key" => "value"
    ]
);

or like this

easyError('Test message', 'Test Title', 400, [ "key" => "value" ]);

2) Class

Firstly import the class, then create an instance.

use Neography7\EasyResponse\EasyResponse;

$callback = new EasyResponse;

You can add message, title, success, code, data or add custom key with chaining methods.

$callback->title("Title")
            ->message("Message")
            ->success("true")
            ->response();

The response method is going to make it all together into an array then it responds as a json callback. If success is given as true, the response code will be 200. Additionally, you can add data, code, and custom key-value with the chaining methods.

$callback->title("Error Title")
            ->message("Error message.")
            ->success("false")
            ->code(404)
            ->data["key" => value]
            ->addKey("key", value)
            ->response();

If you want to remove the key that you added, you can use this method.

$callback->removeKey("key");

3) Static Class

Firstly import the class that initializes EasyResponse, then call the success or error method that you want to use.

use Neography7\EasyResponse\EA;

$callbackSuccess = EA::success($message, $title = null);
$callbackError = EA::error($message, $title = null, $code = null);

You must to call response method after use.

$callback EA::success("Message", "Title")->response();

Testing

I recommend testbench with "nunomaduro/collision" for testing.

php vendor/bin/testbench package:test

Roadmap

  • The package were created
  • More helpers function will be added
  • Initial callbacks messages and their translations will be added

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email ilkerakyel97@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固