Skip to content

Commit a0ea4d3

Browse files
⚡perf: Improved endpoint file loading
1 parent aaf01a8 commit a0ea4d3

File tree

5 files changed

+625
-600
lines changed

5 files changed

+625
-600
lines changed

src/Efi/ApiRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function send(string $method, string $route, string $scope, array $body):
4545
if (!$this->isAccessTokenValid() || !$this->options['cache']) {
4646
$this->auth->authorize();
4747
} else {
48-
if (in_array($scope, json_decode($this->cacheScopes))) {
48+
if (in_array($scope, $this->cacheScopes)) {
4949
$this->auth->accessToken = $this->cacheAccessToken;
5050
} else {
5151
$this->auth->authorize();

src/Efi/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function updateCache(array $response)
103103

104104
if ($this->options['cache']) {
105105
$this->expires = time() + $response['expires_in'];
106-
$this->scopes = ($this->options['api'] === 'CHARGES') ? json_encode(['charge']) : json_encode(explode(' ', $response['scope']));
106+
$this->scopes = ($this->options['api'] === 'CHARGES') ? ['charge'] : explode(' ', $response['scope']);
107107

108108
$session_expire = ($this->options['api'] === 'CHARGES') ? 600 : 3600;
109109
$accessTokenEncrypted = $this->encryptAccessToken();

src/Efi/Config.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Config
99
/**
1010
* @var string Configuration file path for endpoints
1111
*/
12-
private static $endpointsConfigFile = __DIR__ . '/config.json';
12+
private static $endpointsConfigFile = __DIR__ . '/EndpointsConfigFile.php';
1313

1414
/**
1515
* Set the endpoints configuration file.
@@ -30,10 +30,13 @@ public static function setEndpointsConfigFile(string $file): void
3030
*/
3131
public static function get(string $property)
3232
{
33-
$file = file_get_contents(self::$endpointsConfigFile);
34-
$config = json_decode($file, true);
33+
if (!file_exists(self::$endpointsConfigFile)) {
34+
throw new Exception('Arquivo de configuração não encontrado');
35+
}
3536

36-
if (json_last_error() !== JSON_ERROR_NONE) {
37+
$config = include self::$endpointsConfigFile;
38+
39+
if (!is_array($config) || !isset($config['APIs'])) {
3740
throw new Exception('Erro ao carregar o arquivo de endpoints');
3841
}
3942

0 commit comments

Comments
 (0)