Files
money/common/Controller/API/UF/Value.php
2023-06-16 00:53:21 +00:00

41 lines
1.2 KiB
PHP

<?php
namespace Aldarien\Money\Common\Controller\API\UF;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Carbon\Carbon;
use Aldarien\Money\UF\Handler as UFHandler;
class Value {
public function __invoke(Request $request, Response $response, UFHandler $handler): Response {
$fecha = Carbon::today();
$valor = $handler->get($fecha);
$output = [
'uf' => [
'date' => $fecha->format('Y-m-d'),
'value' => $valor
],
'total' => 1
];
$response->getBody()->write(json_encode($output));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
public function fecha(Request $request, Response $response, UFHandler $handler, $fecha): Response {
$fecha = Carbon::parse($fecha);
$valor = $handler->get($fecha);
$output = [
'uf' => [
'date' => $fecha->format('Y-m-d'),
'value' => $valor
],
'total' => 1
];
$response->getBody()->write(json_encode($output));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
}