forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfiguration.php
285 lines (260 loc) · 7.69 KB
/
Configuration.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ODM\MongoDB;
use Doctrine\ODM\MongoDB\Mapping\Driver\Driver,
Doctrine\ODM\MongoDB\Mapping\Driver\PHPDriver,
Doctrine\Common\Cache\Cache;
/**
* Configuration class for the DocumentManager. When setting up your DocumentManager
* you can optionally specify an instance of this class as the second argument.
* If you do not pass a configuration object, a blank one will be created for you.
*
* <?php
*
* $config = new Configuration();
* $em = DocumentManager::create(new Mongo(), $config);
*
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 1.0
* @version $Revision$
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class Configuration
{
/**
* Array of attributes for this configuration instance.
*
* @var array $_attributes
*/
private $_attributes = array();
/**
* Create a new Configuration instance.
*/
public function __construct()
{
$this->_attributes['metadataDriverImpl'] = new PHPDriver();
$this->_attributes['dbPrefix'] = null;
$this->_attributes['dbSuffix'] = null;
}
/**
* Sets the cache driver implementation that is used for metadata caching.
*
* @param Driver $driverImpl
* @todo Force parameter to be a Closure to ensure lazy evaluation
* (as soon as a metadata cache is in effect, the driver never needs to initialize).
*/
public function setMetadataDriverImpl(Driver $driverImpl)
{
$this->_attributes['metadataDriverImpl'] = $driverImpl;
}
/**
* Gets the cache driver implementation that is used for the mapping metadata.
*
* @return Mapping\Driver\Driver
*/
public function getMetadataDriverImpl()
{
return isset($this->_attributes['metadataDriverImpl']) ?
$this->_attributes['metadataDriverImpl'] : null;
}
/**
* Gets the cache driver implementation that is used for metadata caching.
*
* @return \Doctrine\Common\Cache\Cache
*/
public function getMetadataCacheImpl()
{
return isset($this->_attributes['metadataCacheImpl']) ?
$this->_attributes['metadataCacheImpl'] : null;
}
/**
* Sets the cache driver implementation that is used for metadata caching.
*
* @param \Doctrine\Common\Cache\Cache $cacheImpl
*/
public function setMetadataCacheImpl(Cache $cacheImpl)
{
$this->_attributes['metadataCacheImpl'] = $cacheImpl;
}
/**
* Sets the directory where Doctrine generates any necessary proxy class files.
*
* @param string $dir
*/
public function setProxyDir($dir)
{
$this->_attributes['proxyDir'] = $dir;
}
/**
* Gets the directory where Doctrine generates any necessary proxy class files.
*
* @return string
*/
public function getProxyDir()
{
return isset($this->_attributes['proxyDir']) ?
$this->_attributes['proxyDir'] : null;
}
/**
* Gets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @return boolean
*/
public function getAutoGenerateProxyClasses()
{
return isset($this->_attributes['autoGenerateProxyClasses']) ?
$this->_attributes['autoGenerateProxyClasses'] : true;
}
/**
* Sets a boolean flag that indicates whether proxy classes should always be regenerated
* during each script execution.
*
* @param boolean $bool
*/
public function setAutoGenerateProxyClasses($bool)
{
$this->_attributes['autoGenerateProxyClasses'] = $bool;
}
/**
* Gets the namespace where proxy classes reside.
*
* @return string
*/
public function getProxyNamespace()
{
return isset($this->_attributes['proxyNamespace']) ?
$this->_attributes['proxyNamespace'] : null;
}
/**
* Sets the namespace where proxy classes reside.
*
* @param string $ns
*/
public function setProxyNamespace($ns)
{
$this->_attributes['proxyNamespace'] = $ns;
}
/**
* Sets the default DB to use for all Documents that do not specify
* a database.
*
* @param string $defaultDB
*/
public function setDefaultDB($defaultDB)
{
$this->_attributes['defaultDB'] = $defaultDB;
}
/**
* Gets the default DB to use for all Documents that do not specify a database.
*
* @return string $defaultDB
*/
public function getDefaultDB()
{
return isset($this->_attributes['defaultDB']) ?
$this->_attributes['defaultDB'] : null;
}
/**
* Sets the environment
*
* @param string $environment
*/
public function setEnvironment($environment)
{
$this->_attributes['environment'] = $environment;
}
/**
* Gets the environment
*
* @return string $environment
*/
public function getEnvironment()
{
return isset($this->_attributes['environment']) ?
$this->_attributes['environment'] : null;
}
/**
* Gets prefix for environment
*
* @return string $envPrefix
*/
public function getEnvironmentPrefix()
{
return isset($this->_attributes['environment']) ?
sprintf('%s_', $this->_attributes['environment']) : null;
}
/**
* Set the logger callable.
*
* @param mixed $loggerCallable The logger callable.
*/
public function setLoggerCallable($loggerCallable)
{
$this->_attributes['loggerCallable'] = $loggerCallable;
}
/**
* Gets the logger callable.
*
* @return mixed $loggerCallable The logger callable.
*/
public function getLoggerCallable()
{
return isset($this->_attributes['loggerCallable']) ?
$this->_attributes['loggerCallable'] : null;
}
/**
* Set prefix for db name
*
* @param string $prefix The prefix for names of databases
*/
public function setDBPrefix($prefix = null)
{
$this->_attributes['dbPrefix'] = $prefix;
}
/**
* Get prefix for db name
*
* @return string
*/
public function getDBPrefix()
{
return $this->_attributes['dbPrefix'];
}
/**
* Set suffix for db name
*
* @param string $suffix The suffix for names of tables
*/
public function setDBSuffix($suffix = null)
{
$this->_attributes['dbSuffix'] = $suffix;
}
/**
* Get suffix for db name
*
* @return string
*/
public function getDBSuffix()
{
return $this->_attributes['dbSuffix'];
}
}