Skip to content

Commit ae35b52

Browse files
Revertendo commit 1.27.4
1 parent dde6c6a commit ae35b52

7 files changed

Lines changed: 132 additions & 191 deletions

File tree

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,4 @@ php.ini
3333
# DDEV
3434
/.ddev
3535
core.*
36-
37-
#netbeans
38-
/nbproject
36+
composer.lock

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"php": "^7 || ^8",
3131
"ext-pdo_dblib": "*",
3232
"monolog/monolog": "^2 || ^3",
33+
"uspdev/cache": "^1",
3334
"illuminate/collections": "^8 || ^9 || ^10 || ^11 || ^12 || ^13"
3435
}
3536
}

src/Cache.php

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/DB.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PDO;
66
use SplFileInfo;
77
use Throwable;
8+
use Uspdev\Cache\Cache;
89
use Uspdev\Replicado\Replicado as Config;
910

1011
class DB
@@ -15,8 +16,10 @@ class DB
1516
*/
1617
private static $instance;
1718

18-
private function __construct() {}
19-
private function __clone() {}
19+
private function __construct()
20+
{}
21+
private function __clone()
22+
{}
2023

2124
/**
2225
* Retorna uma instância do pdo - cria ou reaproveita se for o caso
@@ -26,12 +29,12 @@ private function __clone() {}
2629
protected static function getInstance()
2730
{
2831
$config = Config::getInstance();
29-
if (!self::$instance) {
32+
if (!SELF::$instance) {
3033
try {
3134
$dsn = "dblib:host={$config->host}:{$config->port};dbname={$config->database}";
32-
// self::$instance = new PDO($dsn, $config->username, $config->password, [PDO::ATTR_TIMEOUT => 10]);
33-
self::$instance = new PDO($dsn, $config->username, $config->password);
34-
self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
35+
// SELF::$instance = new PDO($dsn, $config->username, $config->password, [PDO::ATTR_TIMEOUT => 10]);
36+
SELF::$instance = new PDO($dsn, $config->username, $config->password);
37+
SELF::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
3538
} catch (Throwable $t) {
3639
$config->log('Erro na conexão ', $t->getMessage());
3740
if ($config->debug) {
@@ -41,7 +44,7 @@ protected static function getInstance()
4144
}
4245
}
4346
}
44-
return self::$instance;
47+
return SELF::$instance;
4548
}
4649

4750
/**
@@ -53,7 +56,13 @@ protected static function getInstance()
5356
*/
5457
public static function fetch(string $query, array $param = [])
5558
{
56-
return self::overrideFetch('fetch', $query, $param);
59+
$config = Config::getInstance();
60+
if ($config->usarCache) {
61+
$cache = $config->getCacheInstance();
62+
return $cache->getCached('Uspdev\Replicado\DB::overrideFetch', ['fetch', $query, $param]);
63+
} else {
64+
return SELF::overrideFetch('fetch', $query, $param);
65+
}
5766
}
5867

5968
/**
@@ -65,7 +74,13 @@ public static function fetch(string $query, array $param = [])
6574
*/
6675
public static function fetchAll(string $query, array $param = [])
6776
{
68-
return self::overrideFetch('fetchAll', $query, $param);
77+
$config = Config::getInstance();
78+
if ($config->usarCache) {
79+
$cache = $config->getCacheInstance();
80+
return $cache->getCached('Uspdev\Replicado\DB::overrideFetch', ['fetchAll', $query, $param]);
81+
} else {
82+
return SELF::overrideFetch('fetchAll', $query, $param);
83+
}
6984
}
7085

7186
/**
@@ -82,12 +97,10 @@ public static function fetchAll(string $query, array $param = [])
8297
public static function overrideFetch(string $fetchType, string $query, array $param = [])
8398
{
8499
$config = Config::getInstance();
85-
$query = self::automaticReplaces($query);
86-
$stmt = self::getInstance()->prepare($query);
100+
$query = SELF::automaticReplaces($query);
101+
$stmt = SELF::getInstance()->prepare($query);
87102
foreach ($param as $campo => $valor) {
88-
$valor = $config->sybase
89-
? mb_convert_encoding($valor, 'ISO-8859-1', 'UTF-8')
90-
: $valor;
103+
$valor = $config->sybase ? utf8_decode($valor) : $valor;
91104
$stmt->bindValue(":$campo", $valor);
92105
if ($config->debugLevel >= 2) {
93106
$queryLog = str_replace(":$campo", $valor, $queryLog ?? $query);
@@ -136,9 +149,10 @@ public static function overrideFetch(string $fetchType, string $query, array $pa
136149
*
137150
* @return bool
138151
*/
139-
public static function test()
152+
public static function test($config = [])
140153
{
141-
return self::getInstance() instanceof PDO;
154+
$config = Config::getInstance($config);
155+
return SELF::getInstance() ? true : false;
142156
}
143157

144158
/**

src/Lattes.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ protected static function _retornarDataUltimaAtualizacao(int $codpes)
239239
* @param Array $array
240240
* @return Array
241241
*/
242-
protected static function _listarAutores($array)
242+
protected static function listarAutores($array)
243243
{
244244
$aux_autores = [];
245245
if ($array) {
@@ -277,7 +277,7 @@ protected static function _listarAutores($array)
277277
* @param Integer $i
278278
* @return Bool
279279
*/
280-
protected static function _verificarFiltro($tipo, $ano, $limit_ini, $limit_fim, $i)
280+
protected static function verificarFiltro($tipo, $ano, $limit_ini, $limit_fim, $i)
281281
{
282282
if ($limit_ini == -1) {
283283
return true;
@@ -2194,7 +2194,7 @@ protected static function _listarProjetosPesquisa($codpes, $lattes_array = null,
21942194
* @return Array
21952195
* @author Masakik, em 20/4/2023
21962196
*/
2197-
protected static function _listarRegistrosPorChaveOrdenado($lattes_array, $chave, $chaveOrdenacao = null, $ordem = -1)
2197+
protected static function listarRegistrosPorChaveOrdenado($lattes_array, $chave, $chaveOrdenacao = null, $ordem = -1)
21982198
{
21992199
$registros = Arr::get($lattes_array, $chave, []);
22002200

@@ -2216,7 +2216,7 @@ protected static function _listarRegistrosPorChaveOrdenado($lattes_array, $chave
22162216
* @param Int $ordem Se -1 é decrescente, se 1, é crescente
22172217
* @author Masakik, em 20/4/2023
22182218
*/
2219-
protected static function _ordenarRegistros($registros, $chaveOrdenacao, $ordem = -1)
2219+
protected static function ordenarRegistros($registros, $chaveOrdenacao, $ordem = -1)
22202220
{
22212221
usort($registros, function ($a, $b) use ($chaveOrdenacao) {
22222222
if (Arr::get($b, $chaveOrdenacao, false) == false) {
@@ -2666,7 +2666,7 @@ protected static function _listarOrientacoesEmAndamentoIC($codpes, $lattes_array
26662666
* @param Array $array
26672667
* @return Array
26682668
*/
2669-
protected static function _listarFinanciadores($array) {
2669+
protected static function listarFinanciadores($array) {
26702670
$aux_financiadores = [];
26712671
if ($array) {
26722672
foreach ($array as $financiador) {

0 commit comments

Comments
 (0)