lightsource/std-response

Standardization for a function / method response with multiple arguments

3.0.0 2021-10-01 11:31 UTC

This package is auto-updated.

Last update: 2024-05-29 04:41:21 UTC


README

What is it

Standardization for a function / method response with multiple arguments

Installation

composer require lightsource/std-response

Example of usage

use LightSource\StdResponse\StdResponse;

require_once __DIR__ . '/vendor/autoload.php';

function calc($a, $b)
{
    $value     = $a + $b;
    $isSuccess = $value > $a;

    return new StdResponse($isSuccess, ['value' => 10,]);
}

$response = calc(10, 20);

if ($response->isSuccess()) {
    $value = $response->getArgs()['value'];
    // todo
} else {
    $errorMessages = $response->getErrorMessages();
    // todo
}