42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
![]() |
<?php
|
||
|
namespace Incoviba\Service;
|
||
|
|
||
|
use DateTimeInterface;
|
||
|
use Incoviba\Common\Define\Money\Provider;
|
||
|
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||
|
use Incoviba\Service\Money\MiIndicador;
|
||
|
|
||
|
class Money
|
||
|
{
|
||
|
protected array $providers;
|
||
|
public function register(string $name, Provider $provider): Money
|
||
|
{
|
||
|
if (isset($this->providers) and isset($this->providers[$name]) and $this->providers[$name] === $provider) {
|
||
|
return $this;
|
||
|
}
|
||
|
$this->providers[$name] = $provider;
|
||
|
return $this;
|
||
|
}
|
||
|
public function getProvider(string $name): Provider
|
||
|
{
|
||
|
return $this->providers[$name];
|
||
|
}
|
||
|
|
||
|
public function getUF(DateTimeInterface $dateTime): float
|
||
|
{
|
||
|
try {
|
||
|
return $this->getProvider('uf')->get(MiIndicador::UF, $dateTime);
|
||
|
} catch (EmptyResponse) {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
public function getIPC(DateTimeInterface $dateTime): float
|
||
|
{
|
||
|
try {
|
||
|
return $this->getProvider('ipc')->get(MiIndicador::IPC, $dateTime);
|
||
|
} catch (EmptyResponse) {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
}
|