PHP JSEND

Build Status
Scrutinizer Code Quality
Code Coverage
Latest Stable Version
Total Downloads
LICENSE

The package is an implementation of JSend specification for PHP.

Installation

composer require razonyang/jsend

Usage

// generates resposne payload.
$payload = PayloadFactory::success($data); // success payload.
// $payload = PayloadFactory::fail($data); // fail payload.
// $payload = PayloadFactory::error($message, $code, $data); // error payload, the code and data are optional.

// if the factory is not suite for your case, creates payload instance directly.
// $payload = (new Payload())->setStatus($status)->setData($data);

// sends response.
echo $payload->toString($options); // the options the second parameter of json_encode, default to JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES

// the payload can also be formatted like this(same effect as above):
// echo json_encode($payload->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

Integration

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据