commonhelpers / common-response
PHP class Response as a result of other classes
0.1.3
2021-11-13 20:29 UTC
Requires
- php: >=7.1
README
Class CommonHelpers\Response should use if you want to get boolean result of the operations and message. Also you have an opportunity get any data besides the boolean result and message. It is comfortable for api.
<?php namespace App; use CommonHelpers\ObjectResponse\Response; class ApiController { private $response; public function __construct() { $this->response = Response::fail(); } public function run(int $a, int $b): Response { $this->response->setResult($a > $b); $this->response->isSuccess() ? $this->response->setMessage('ok') : $this->response->setMessage('fail') ; $this->response->payload = $a * $b; return $this->response; } }