Files
oficial/cli/src/Command/Money/UF.php

32 lines
1017 B
PHP
Raw Normal View History

2023-11-25 00:56:18 -03:00
<?php
namespace Incoviba\Command\Money;
use DateTimeImmutable;
use DateTimeZone;
2023-11-25 00:56:18 -03:00
use Symfony\Component\Console;
2023-11-25 21:38:00 -03:00
use Incoviba\Common\Alias\Command;
2023-11-25 00:56:18 -03:00
#[Console\Attribute\AsCommand(
2024-08-27 14:51:06 -04:00
name: 'money:uf',
description: 'Get the UF value for today'
2023-11-25 00:56:18 -03:00
)]
2023-11-25 21:38:00 -03:00
class UF extends Command
2023-11-25 00:56:18 -03:00
{
2025-05-12 18:07:14 -04:00
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
2023-11-25 00:56:18 -03:00
{
2023-11-25 21:38:00 -03:00
$this->logger->debug("Running {$this->getName()}");
$now = new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago'));
2023-11-29 20:09:08 -03:00
$uri = '/api/money/uf';
2023-11-25 00:56:18 -03:00
$data = [
'fecha' => $now->format('Y-m-d')
];
$output->writeln("POST {$uri}");
$response = $this->client->post($uri, [
'body' => http_build_query($data),
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
]);
$output->writeln("Response Code: {$response->getStatusCode()}");
return Console\Command\Command::SUCCESS;
}
}