miwebb/jsend

The PHP JSend implementations

v3.0.1 2022-01-11 08:56 UTC

This package is auto-updated.

Last update: 2024-04-11 14:01:18 UTC


README

Build Status Code Coverage Scrutinizer Code Quality

JSend

The PHP JSend implementation.

Examples

Use

require 'vendor/autoload.php';

use miWebb/JSend/JSend;

Create

Success

$jsend = new JSend('success', $data);
$jsend = new JSend(JSend::SUCCESS, $data);
$jsend = JSend::success($data);

Fail

$jsend = new JSend('fail', $data);
$jsend = new JSend(JSend::FAIL, $data);
$jsend = JSend::fail($data);

Error

$jsend = new JSend('error', $data, $message, $code);
$jsend = new JSend(JSend::ERROR, $data, $message, $code);
$jsend = JSend::error($message, $code, $data);

Decode

try {
	$jsend = JSend::decode($json);
} catch(UnexpectedValueException $e) {
	// Error message
}

Output

Variable

$json = $jsend->decode();
$json = (string) $jsend;

Print

$jsend->send();

Methods

$jsend = new JSend(JSend::SUCCESS, $data);
$jsend->__toString();
$jsend->toArray();
$jsend->encode();
$jsend->isSuccess();
$jsend->isFail();
$jsend->isError();
$jsend->getStatus();
$jsend->setStatus($status);
$jsend->getData();
$jsend->setData($data = null);
$jsend->getMessage();
$jsend->setMessage($message = null);
$jsend->getCode();
$jsend->setCode($code = null);
$jsend->send();
JSend::success($data = null);
JSend::fail($data);
JSend::error($message, $code = null, $data = null);
JSend::decode($input);