2023-09-12
This commit is contained in:
41
app/src/Service/Money.php
Normal file
41
app/src/Service/Money.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user