Skip to content

Commit fffde67

Browse files
committed
renamed reAuth to reconnect
1 parent b43a66f commit fffde67

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ should not use the "authorization" middleware, but you do need to use the "recon
829829
},
830830

831831
This will make the API connect to the database specifying "mevdschee" as the username and "secret123" as the password.
832+
The OpenAPI specification is less specific on allowed and disallowed operations, when you are using database permissions,
833+
as the permissions are not read in the reflection step.
832834

833835
NB: You may want to retrieve the username and password from the session (the "$_SESSION" variable).
834836

api.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4116,27 +4116,29 @@ private function database(): ReflectedDatabase
41164116

41174117
private function loadDatabase(bool $useCache): ReflectedDatabase
41184118
{
4119-
$data = $useCache ? $this->cache->get('ReflectedDatabase') : '';
4119+
$key = sprintf('%s-ReflectedDatabase', $this->db->getCacheKey());
4120+
$data = $useCache ? $this->cache->get($key) : '';
41204121
if ($data != '') {
41214122
$database = ReflectedDatabase::fromJson(json_decode(gzuncompress($data)));
41224123
} else {
41234124
$database = ReflectedDatabase::fromReflection($this->db->reflection());
41244125
$data = gzcompress(json_encode($database, JSON_UNESCAPED_UNICODE));
4125-
$this->cache->set('ReflectedDatabase', $data, $this->ttl);
4126+
$this->cache->set($key, $data, $this->ttl);
41264127
}
41274128
return $database;
41284129
}
41294130

41304131
private function loadTable(string $tableName, bool $useCache): ReflectedTable
41314132
{
4132-
$data = $useCache ? $this->cache->get("ReflectedTable($tableName)") : '';
4133+
$key = sprintf('%s-ReflectedTable(%s)', $this->db->getCacheKey(), $tableName);
4134+
$data = $useCache ? $this->cache->get($key) : '';
41334135
if ($data != '') {
41344136
$table = ReflectedTable::fromJson(json_decode(gzuncompress($data)));
41354137
} else {
41364138
$tableType = $this->database()->getType($tableName);
41374139
$table = ReflectedTable::fromReflection($this->db->reflection(), $tableName, $tableType);
41384140
$data = gzcompress(json_encode($table, JSON_UNESCAPED_UNICODE));
4139-
$this->cache->set("ReflectedTable($tableName)", $data, $this->ttl);
4141+
$this->cache->set($key, $data, $this->ttl);
41404142
}
41414143
return $table;
41424144
}
@@ -5467,6 +5469,17 @@ private function query(string $sql, array $parameters): \PDOStatement
54675469
$stmt->execute($parameters);
54685470
return $stmt;
54695471
}
5472+
5473+
public function getCacheKey(): string
5474+
{
5475+
return md5(json_encode([
5476+
$this->driver,
5477+
$this->address,
5478+
$this->port,
5479+
$this->database,
5480+
$this->username
5481+
]));
5482+
}
54705483
}
54715484
}
54725485

@@ -9688,7 +9701,7 @@ public function __construct(Config $config)
96889701
$config->getUsername(),
96899702
$config->getPassword()
96909703
);
9691-
$prefix = sprintf('phpcrudapi-%s-%s-%s-', $config->getDriver(), $config->getDatabase(), substr(md5(__FILE__), 0, 8));
9704+
$prefix = sprintf('phpcrudapi-%s-', substr(md5(__FILE__), 0, 8));
96929705
$cache = CacheFactory::create($config->getCacheType(), $prefix, $config->getCachePath());
96939706
$reflection = new ReflectionService($db, $cache, $config->getCacheTime());
96949707
$responder = new JsonResponder();

src/Tqdev/PhpCrudApi/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(Config $config)
5353
$config->getUsername(),
5454
$config->getPassword()
5555
);
56-
$prefix = sprintf('phpcrudapi-%s-%s-%s-', $config->getDriver(), $config->getDatabase(), substr(md5(__FILE__), 0, 8));
56+
$prefix = sprintf('phpcrudapi-%s-', substr(md5(__FILE__), 0, 8));
5757
$cache = CacheFactory::create($config->getCacheType(), $prefix, $config->getCachePath());
5858
$reflection = new ReflectionService($db, $cache, $config->getCacheTime());
5959
$responder = new JsonResponder();

src/Tqdev/PhpCrudApi/Column/ReflectionService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,29 @@ private function database(): ReflectedDatabase
3434

3535
private function loadDatabase(bool $useCache): ReflectedDatabase
3636
{
37-
$data = $useCache ? $this->cache->get('ReflectedDatabase') : '';
37+
$key = sprintf('%s-ReflectedDatabase', $this->db->getCacheKey());
38+
$data = $useCache ? $this->cache->get($key) : '';
3839
if ($data != '') {
3940
$database = ReflectedDatabase::fromJson(json_decode(gzuncompress($data)));
4041
} else {
4142
$database = ReflectedDatabase::fromReflection($this->db->reflection());
4243
$data = gzcompress(json_encode($database, JSON_UNESCAPED_UNICODE));
43-
$this->cache->set('ReflectedDatabase', $data, $this->ttl);
44+
$this->cache->set($key, $data, $this->ttl);
4445
}
4546
return $database;
4647
}
4748

4849
private function loadTable(string $tableName, bool $useCache): ReflectedTable
4950
{
50-
$data = $useCache ? $this->cache->get("ReflectedTable($tableName)") : '';
51+
$key = sprintf('%s-ReflectedTable(%s)', $this->db->getCacheKey(), $tableName);
52+
$data = $useCache ? $this->cache->get($key) : '';
5153
if ($data != '') {
5254
$table = ReflectedTable::fromJson(json_decode(gzuncompress($data)));
5355
} else {
5456
$tableType = $this->database()->getType($tableName);
5557
$table = ReflectedTable::fromReflection($this->db->reflection(), $tableName, $tableType);
5658
$data = gzcompress(json_encode($table, JSON_UNESCAPED_UNICODE));
57-
$this->cache->set("ReflectedTable($tableName)", $data, $this->ttl);
59+
$this->cache->set($key, $data, $this->ttl);
5860
}
5961
return $table;
6062
}

src/Tqdev/PhpCrudApi/Database/GenericDB.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,15 @@ private function query(string $sql, array $parameters): \PDOStatement
306306
$stmt->execute($parameters);
307307
return $stmt;
308308
}
309+
310+
public function getCacheKey(): string
311+
{
312+
return md5(json_encode([
313+
$this->driver,
314+
$this->address,
315+
$this->port,
316+
$this->database,
317+
$this->username
318+
]));
319+
}
309320
}

0 commit comments

Comments
 (0)