* @copyright 2020 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ if (!defined('_PS_VERSION_')) { exit; } /** * Class RetailcrmLogger * @author DIGITAL RETAIL TECHNOLOGIES SL * @license GPL * @link https://retailcrm.ru */ class RetailcrmJsonResponse { private static function jsonResponse($response) { header('Content-Type: application/json'); $result = json_encode($response); echo $result; return $result; } public static function invalidResponse($msg, $status = 404) { http_response_code($status); return self::jsonResponse([ 'success' => false, 'errorMsg' => $msg ]); } public static function successfullResponse($data = null, $key = null) { $response = [ 'success' => true, ]; if (!is_null($data)) { if (is_array($key)) { foreach ($key as $i => $value) { if (isset($data[$i])) $response[$value] = $data[$i]; } } elseif (is_string($key)) { $response[$key] = $data; } else { $response['response'] = $data; } } return self::jsonResponse($response); } }