PHP Classes

File: src/Helpers/ResponseHelper.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Polr Restful API   src/Helpers/ResponseHelper.php   Download  
File: src/Helpers/ResponseHelper.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Polr Restful API
Provide an API for the Polr URL shortener service
Author: By
Last change:
Date: 6 years ago
Size: 995 bytes
 

Contents

Class file image Download
<?php

namespace Lagdo\Polr\Api\Helpers;

class
ResponseHelper
{
   
/**
     * Create a JSON response for API calls
     *
     * @param string $result The result data of the API call
     * @param string $message The result message of the API call
     * @param number $code The HTTP code returned by the API call
     *
     * @return Response
     */
   
public static function make($result = null, $message = 'OK', $code = 200)
    {
       
$response = compact('message');
        if(
$code == 200)
        {
           
$response['settings'] = [
               
'analytics' => env('SETTING_ADV_ANALYTICS'),
               
'username' => UserHelper::$username,
               
'roles' => UserHelper::$USER_ROLES,
            ];
        }
        if(
$result !== null && $result !== false)
        {
           
$response["result"] = $result;
        }
   
        return
response()->json($response, $code)
            ->
header('Content-Type', 'application/json')
            ->
header('Access-Control-Allow-Origin', '*');
    }
}