Universal result store:
- status (bool)
- data (mixed)
- message (string)
- code (string)
Require this package in your composer.json
and update composer.
"kharanenka/php-result-store": "2.2.*"
You can use class "Result" in any places your application. Class "Result" is singleton.
- setData(mixed $obData) - Set result data
- setTrue(mixed $obData = null) - Set result data with status "true"
- setFalse(mixed $obData = null) - Set result data with status "false"
- setMessage(string $sMessage) - Set message string
- setCode(string $sCode) - Set code value
- status() - Get result status flag true/false
- data() - Get data value (object/array/string)
- message() - Get message value
- code() - Get code value
- get() - Get array result array
- getJSON() - Get array result array in JSON string
//Result array
[
'status' => false/true
'data' => object
'message' => 'Message text',
'code' => 1015,
]
//Example 1
Result::setMessage('Error')->setCode(400)->setFalse();
...
if(!Result::status()) {
return Result::get();
}
//Example 2
return Result::setTrue($obData)->getJSON();