Files
magic-project/app/Services/ApiResponder.php

52 lines
983 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Services;
use App\Dto\ApiResponseDto;
use Illuminate\Http\JsonResponse;
class ApiResponder{
public $dto;
public function __construct(
)
{}
public function success(): JsonResponse
{
return $this->buildResponse();
}
public function error()
{
return $this->buildResponse();
}
public function setDto(ApiResponseDto $dto)
{
$this->dto = $dto;
}
// public function fromDTO(ApiResponseDto $dto)
// {
// return $dto;
// }
#Гаврилов
//СБОР СТАТИСТИКИ ПО ВЫЗЫВАЕМЫМ API ЕНДПОИНТАМ. ВНЕСТИ В TODO ПРОЕКТА
private function setStatistics()
{
}
#Гаврилов
//ДОБАВЬ ЛОГИРОВАНИЕ ОШИБОК В TRY CATCH В .LOG ФАЙЛ
private function buildResponse(): JsonResponse
{
//echo '<pre>'; var_dump((array)$this->dto); echo'</pre>';
//return (array) $this->dto;
return response()->json((array) $this->dto);
}
}