-
Notifications
You must be signed in to change notification settings - Fork 1
/
Config.php
192 lines (168 loc) · 5.13 KB
/
Config.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?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\Extensions\Drivers\Ravendb;
use Phpfastcache\Config\ConfigurationOption;
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
use RavenDB\Auth\AuthOptions;
class Config extends ConfigurationOption
{
/**
* @var array<string>
*/
protected array $hosts = [];
protected string $username = '';
protected string $password = '';
protected bool $serializeData = false;
protected ?AuthOptions $authOptions = null;
protected string $databaseName = Driver::RAVENDB_DEFAULT_DB_NAME;
protected string $collectionName = Driver::RAVENDB_DEFAULT_COLLECTION_NAME;
protected string $documentPrefix = Driver::RAVENDB_DOCUMENT_PREFIX;
/**
* @return string
*/
public function getDatabaseName(): string
{
return $this->databaseName;
}
/**
* @param string $databaseName
* @return Config
* @throws PhpfastcacheInvalidArgumentException
* @throws PhpfastcacheLogicException
*/
public function setDatabaseName(string $databaseName): static
{
if (\preg_match('#^[A-z][A-z0-9-.]+$#', $databaseName)) {
return $this->setProperty('databaseName', $databaseName);
}
throw new PhpfastcacheInvalidArgumentException(sprintf("Error: Illegal database name: '%s'.
Only lowercase characters (a-z), digits (0-9), and any of the characters _-. are allowed. Must begin with a letter.", $databaseName));
}
/**
* @return string
*/
public function getCollectionName(): string
{
return $this->collectionName;
}
/**
* @param string $collectionName
* @return Config
* @throws PhpfastcacheInvalidArgumentException
* @throws PhpfastcacheLogicException
*/
public function setCollectionName(string $collectionName): static
{
if (\preg_match('#^[A-z][A-z0-9-.]+$#', $collectionName)) {
return $this->setProperty('collectionName', $collectionName);
}
throw new PhpfastcacheInvalidArgumentException(sprintf("Error: Illegal collection name: '%s'.
Only lowercase characters (a-z), digits (0-9), and any of the characters _-. are allowed. Must begin with a letter.", $collectionName));
}
/**
* @return string
*/
public function getDocumentPrefix(): string
{
return $this->documentPrefix;
}
/**
* @param string $documentPrefix
* @return Config
* @throws PhpfastcacheInvalidArgumentException
* @throws PhpfastcacheLogicException
*/
public function setDocumentPrefix(string $documentPrefix): static
{
if (\preg_match('#^[A-z][A-z0-9-./]+$#', $documentPrefix)) {
return $this->setProperty('documentPrefix', $documentPrefix);
}
throw new PhpfastcacheInvalidArgumentException(sprintf("Error: Illegal document prefix: '%s'.
Only lowercase characters (a-z), digits (0-9), and any of the characters _-., and / are allowed. Must begin with a letter.", $documentPrefix));
}
/**
* @return string[]
*/
public function getHost(): array
{
return $this->hosts;
}
/**
* @param string[] $hosts
* @return self
* @throws PhpfastcacheLogicException
*/
public function setHost(array $hosts): static
{
return $this->setProperty('hosts', $hosts);
}
/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* @param string $username
* @return self
* @throws PhpfastcacheLogicException
*/
public function setUsername(string $username): static
{
return $this->setProperty('username', $username);
}
/**
* @return string
*/
public function getPassword(): string
{
return $this->password;
}
/**
* @param string $password
* @return self
* @throws PhpfastcacheLogicException
*/
public function setPassword(string $password): static
{
return $this->setProperty('password', $password);
}
/**
* @return bool
*/
public function isSerializeData(): bool
{
return $this->serializeData;
}
/**
* @param bool $serializeData
* @return self
* @throws PhpfastcacheInvalidArgumentException
* @throws PhpfastcacheLogicException
*/
public function setSerializeData(bool $serializeData): static
{
return $this->setProperty('serializeData', $serializeData);
}
public function getAuthOptions(): ?AuthOptions
{
return $this->authOptions;
}
public function setAuthOptions(?AuthOptions $authOptions): static
{
return $this->setProperty('authOptions', $authOptions);
}
}