PHP code example of commonhelpers / common-response

1. Go to this page and download the library: Download commonhelpers/common-response library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

commonhelpers / common-response example snippets




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;
    }
}