/
CachedPlatform.php
79 lines (56 loc) · 1.64 KB
/
CachedPlatform.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php declare(strict_types = 1);
namespace Nextras\Dbal\Bridges\NetteCaching;
use Nette\Caching\Cache;
use Nextras\Dbal\Platforms\IPlatform;
class CachedPlatform implements IPlatform
{
private const CACHE_VERSION = 'v2';
/** @var IPlatform */
private $platform;
/** @var Cache */
private $cache;
public function __construct(IPlatform $platform, Cache $cache)
{
$this->platform = $platform;
$this->cache = $cache;
}
public function getName(): string
{
return $this->platform->getName();
}
/** @inheritDoc */
public function getTables(?string $schema = null): array
{
return $this->cache->load(self::CACHE_VERSION . '.tables.' . $schema, function () use ($schema): array {
return $this->platform->getTables($schema);
});
}
/** @inheritDoc */
public function getColumns(string $table): array
{
return $this->cache->load(self::CACHE_VERSION . '.columns.' . $table, function () use ($table): array {
return $this->platform->getColumns($table);
});
}
/** @inheritDoc */
public function getForeignKeys(string $table): array
{
return $this->cache->load(self::CACHE_VERSION . '.foreign_keys.' . $table, function () use ($table): array {
return $this->platform->getForeignKeys($table);
});
}
public function getPrimarySequenceName(string $table): ?string
{
return $this->cache->load(self::CACHE_VERSION . '.sequence.' . $table, function () use ($table): array {
return [$this->platform->getPrimarySequenceName($table)];
})[0];
}
public function isSupported(int $feature): bool
{
return $this->platform->isSupported($feature);
}
public function clearCache(): void
{
$this->cache->clean();
}
}