1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of Phpfastcache. |
5
|
|
|
* |
6
|
|
|
* @license MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. |
9
|
|
|
* |
10
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
11
|
|
|
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Phpfastcache\Drivers\Firestore; |
17
|
|
|
|
18
|
|
|
use Phpfastcache\Config\ConfigurationOption; |
19
|
|
|
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; |
20
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @see https://github.com/arangodb/arangodb-php/blob/devel/examples/init.php |
24
|
|
|
* @SuppressWarnings(PHPMD.TooManyFields) |
25
|
|
|
*/ |
26
|
|
|
class Config extends ConfigurationOption |
27
|
|
|
{ |
28
|
|
|
protected ?string $googleCloudProject = null; |
29
|
|
|
|
30
|
|
|
protected ?string $googleApplicationCredential = null; |
31
|
|
|
|
32
|
|
|
protected bool $allowEnvCredentialOverride = false; |
33
|
|
|
|
34
|
|
|
protected string $collection; |
35
|
|
|
|
36
|
|
|
public function __construct(array $parameters = []) |
37
|
|
|
{ |
38
|
|
|
parent::__construct($parameters); |
39
|
|
|
$this->googleCloudProject = $this->getSuperGlobalAccessor()('SERVER', 'GOOGLE_CLOUD_PROJECT'); |
40
|
|
|
$this->googleApplicationCredential = $this->getSuperGlobalAccessor()('SERVER', 'GOOGLE_APPLICATION_CREDENTIALS'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function getCollection(): string |
47
|
|
|
{ |
48
|
|
|
return $this->collection; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $collection |
53
|
|
|
* @return Config |
54
|
|
|
* @throws PhpfastcacheLogicException |
55
|
|
|
*/ |
56
|
|
|
public function setCollection(string $collection): Config |
57
|
|
|
{ |
58
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
59
|
|
|
$this->collection = $collection; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string|null |
65
|
|
|
*/ |
66
|
|
|
public function getGoogleCloudProject(): ?string |
67
|
|
|
{ |
68
|
|
|
return $this->googleCloudProject; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string|null $googleCloudProject |
73
|
|
|
* @return Config |
74
|
|
|
* @throws PhpfastcacheLogicException |
75
|
|
|
*/ |
76
|
|
|
public function setGoogleCloudProject(?string $googleCloudProject): Config |
77
|
|
|
{ |
78
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
79
|
|
|
if ($googleCloudProject !== null) { |
80
|
|
|
if (!$this->isAllowEnvCredentialOverride()) { |
81
|
|
|
throw new PhpfastcacheLogicException('You are not allowed to override GCP environment variables.'); |
82
|
|
|
} |
83
|
|
|
\putenv("GOOGLE_CLOUD_PROJECT=$googleCloudProject"); |
84
|
|
|
$this->googleApplicationCredential = $googleCloudProject; |
85
|
|
|
} |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string|null |
91
|
|
|
*/ |
92
|
|
|
public function getGoogleApplicationCredential(): ?string |
93
|
|
|
{ |
94
|
|
|
return $this->googleApplicationCredential; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string|null $googleApplicationCredential |
99
|
|
|
* @return Config |
100
|
|
|
* @throws PhpfastcacheLogicException |
101
|
|
|
*/ |
102
|
|
|
public function setGoogleApplicationCredential(?string $googleApplicationCredential): Config |
103
|
|
|
{ |
104
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
105
|
|
|
if ($googleApplicationCredential !== null) { |
106
|
|
|
if (!$this->isAllowEnvCredentialOverride()) { |
107
|
|
|
throw new PhpfastcacheLogicException('You are not allowed to override GCP environment variables.'); |
108
|
|
|
} |
109
|
|
|
\putenv("GOOGLE_APPLICATION_CREDENTIALS=$googleApplicationCredential"); |
110
|
|
|
$this->googleApplicationCredential = $googleApplicationCredential; |
111
|
|
|
} |
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return bool |
117
|
|
|
*/ |
118
|
|
|
public function isAllowEnvCredentialOverride(): bool |
119
|
|
|
{ |
120
|
|
|
return $this->allowEnvCredentialOverride; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param bool $allowEnvCredentialOverride |
125
|
|
|
* @return Config |
126
|
|
|
*/ |
127
|
|
|
public function setAllowEnvCredentialOverride(bool $allowEnvCredentialOverride): Config |
128
|
|
|
{ |
129
|
|
|
$this->allowEnvCredentialOverride = $allowEnvCredentialOverride; |
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|