razonyang / jsend
JSend port for PHP
Installs: 3 834
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 0
Open Issues: 0
1.0.0
2019-08-20 09:35 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-09-04 23:05:05 UTC
README
The package is a PHP's implementation of JSend specification.
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
- Yii2 JSend - JSend port for Yii2