kharanenka / php-result-store
Universal result store
Installs: 31 945
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^6.5
README
Universal result store:
- status (bool)
- data (mixed)
- message (string)
- code (string)
Installation
Require this package in your composer.json
and update composer.
"kharanenka/php-result-store": "2.2.*"
Usage
You can use class "Result" in any places your application. Class "Result" is singleton.
Set result data methods:
- 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
Get result data method:
- 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();