Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/razonyang/php-jsend
Jsend port for PHP
https://github.com/razonyang/php-jsend
jsend php-jsend rest-api restful-api
Last synced: 20 days ago
JSON representation
Jsend port for PHP
- Host: GitHub
- URL: https://github.com/razonyang/php-jsend
- Owner: razonyang
- License: bsd-3-clause
- Created: 2019-08-05T06:33:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-21T04:37:13.000Z (about 5 years ago)
- Last Synced: 2024-04-14T02:23:38.616Z (7 months ago)
- Topics: jsend, php-jsend, rest-api, restful-api
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
JSend port for PHP
==================[![Build Status](https://travis-ci.org/razonyang/php-jsend.svg?branch=master)](https://travis-ci.org/razonyang/php-jsend)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/razonyang/php-jsend/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/razonyang/php-jsend/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/razonyang/php-jsend/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/razonyang/php-jsend/?branch=master)
[![Latest Stable Version](https://img.shields.io/packagist/v/razonyang/jsend.svg)](https://packagist.org/packages/razonyang/jsend)
[![Total Downloads](https://img.shields.io/packagist/dt/razonyang/jsend.svg)](https://packagist.org/packages/razonyang/jsend)
[![LICENSE](https://img.shields.io/github/license/razonyang/php-jsend)](LICENSE)The package is a PHP's implementation of [JSend](https://github.com/omniti-labs/jsend) specification.
Installation
------------```
composer require razonyang/jsend
```Usage
-----```php
// 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
------------ [Yii2 JSend](https://github.com/razonyang/yii2-jsend) - JSend port for Yii2