Se avanza en la pagina de inicio, falta los indicadores
This commit is contained in:
34
common/Service/Indicadores.php
Normal file
34
common/Service/Indicadores.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace ProVM\KI\Common\Service;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class Indicadores {
|
||||
//protected $cliente;
|
||||
protected $base_uri;
|
||||
|
||||
public function __construct(string $indicadores_url) {
|
||||
$this->base_uri = $indicadores_url;
|
||||
}
|
||||
public function get(string $indicador, \DateTime $fecha) {
|
||||
$url = implode('/', [
|
||||
$this->base_uri,
|
||||
$indicador,
|
||||
$fecha->format('d-m-Y')
|
||||
]);
|
||||
if ( ini_get('allow_url_fopen') ) {
|
||||
$json = file_get_contents($url);
|
||||
} else {
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
$json = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
}
|
||||
$data = json_decode($json);
|
||||
$valor = 0;
|
||||
if (isset($data->serie[0])) {
|
||||
$valor = $data->serie[0]->valor;
|
||||
}
|
||||
return $valor;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user