Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/rentpix.corals.io/Corals/core/Foundation/Helpers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/rentpix.corals.io/Corals/core/Foundation/Helpers/api_helpers.php
<?php

use Illuminate\Validation\ValidationException;

if (!function_exists('apiOptionAsObject')) {
    /**
     * @param $key
     * @param $value
     * @param $keyLabel
     * @param $valueLabel
     * @return false|mixed
     */
    function apiOptionAsObject($key, $value, $keyLabel = 'key', $valueLabel = 'value')
    {
        return current(apiPluck([$key => $value], $keyLabel, $valueLabel));
    }
}

if (!function_exists('apiPluck')) {
    /**
     * @param $array
     * @param string $keyLabel
     * @param string $valueLabel
     * @return array
     */
    function apiPluck($array, $keyLabel = 'key', $valueLabel = 'value')
    {
        if ($array instanceof \Illuminate\Support\Collection) {
            $array = $array->toArray();
        } elseif (!is_array($array)) {
            return [];
        }

        $result = [];

        foreach ($array as $key => $value) {
            $result[] = [$keyLabel => $key, $valueLabel => $value];
        }

        return $result;
    }
}

if (!function_exists('apiResponse')) {
    /**
     * @param $data
     * @param string $message
     * @param string $status
     * @param int $httpStatus
     * @param array $headers
     * @param int $options
     * @return \Illuminate\Http\JsonResponse
     */
    function apiResponse($data, $message = '', $status = 'success', $httpStatus = 200, $headers = [], $options = 0)
    {
        if ($httpStatus > 511) {
            $httpStatus = 500;
        }
        
        return response()->json([
            'status' => $status,
            'message' => strip_tags($message),
            'data' => $data,
        ], $httpStatus, $headers, $options);
    }
}
if (!function_exists('apiExceptionResponse')) {
    /**
     * @param $exception
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     */
    function apiExceptionResponse($exception, $data = [])
    {
        logger(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2), -1));

        report($exception);

        if ($exception instanceof ValidationException) {
            return response()->json([
                'message' => trans('validation.message'),
                'errors' => $exception->validator->getMessageBag()
            ], 422);
        }

        return apiResponse($data,
            strip_tags($exception->getMessage()), 'error', $exception->getCode() ?: 400);
    }
}

Spamworldpro Mini