-
-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathConfig.php
More file actions
132 lines (116 loc) · 3.79 KB
/
Config.php
File metadata and controls
132 lines (116 loc) · 3.79 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <contact@geolim4.com>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
declare(strict_types=1);
namespace Phpfastcache\Drivers\Firestore;
use Phpfastcache\Config\ConfigurationOption;
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
/**
* @see https://github.com/arangodb/arangodb-php/blob/devel/examples/init.php
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class Config extends ConfigurationOption
{
protected ?string $googleCloudProject = null;
protected ?string $googleApplicationCredential = null;
protected bool $allowEnvCredentialOverride = false;
protected string $collection;
public function __construct(array $parameters = [])
{
parent::__construct($parameters);
$this->googleCloudProject = $this->getSuperGlobalAccessor()('SERVER', 'GOOGLE_CLOUD_PROJECT');
$this->googleApplicationCredential = $this->getSuperGlobalAccessor()('SERVER', 'GOOGLE_APPLICATION_CREDENTIALS');
}
/**
* @return string
*/
public function getCollection(): string
{
return $this->collection;
}
/**
* @param string $collection
* @return Config
* @throws PhpfastcacheLogicException
*/
public function setCollection(string $collection): Config
{
$this->enforceLockedProperty(__FUNCTION__);
$this->collection = $collection;
return $this;
}
/**
* @return string|null
*/
public function getGoogleCloudProject(): ?string
{
return $this->googleCloudProject;
}
/**
* @param string|null $googleCloudProject
* @return Config
* @throws PhpfastcacheLogicException
*/
public function setGoogleCloudProject(?string $googleCloudProject): Config
{
$this->enforceLockedProperty(__FUNCTION__);
if ($googleCloudProject !== null) {
if (!$this->isAllowEnvCredentialOverride()) {
throw new PhpfastcacheLogicException('You are not allowed to override GCP environment variables.');
}
\putenv("GOOGLE_CLOUD_PROJECT=$googleCloudProject");
$this->googleApplicationCredential = $googleCloudProject;
}
return $this;
}
/**
* @return string|null
*/
public function getGoogleApplicationCredential(): ?string
{
return $this->googleApplicationCredential;
}
/**
* @param string|null $googleApplicationCredential
* @return Config
* @throws PhpfastcacheLogicException
*/
public function setGoogleApplicationCredential(?string $googleApplicationCredential): Config
{
$this->enforceLockedProperty(__FUNCTION__);
if ($googleApplicationCredential !== null) {
if (!$this->isAllowEnvCredentialOverride()) {
throw new PhpfastcacheLogicException('You are not allowed to override GCP environment variables.');
}
\putenv("GOOGLE_APPLICATION_CREDENTIALS=$googleApplicationCredential");
$this->googleApplicationCredential = $googleApplicationCredential;
}
return $this;
}
/**
* @return bool
*/
public function isAllowEnvCredentialOverride(): bool
{
return $this->allowEnvCredentialOverride;
}
/**
* @param bool $allowEnvCredentialOverride
* @return Config
*/
public function setAllowEnvCredentialOverride(bool $allowEnvCredentialOverride): Config
{
$this->allowEnvCredentialOverride = $allowEnvCredentialOverride;
return $this;
}
}