|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File was created 01.03.2016 12:16 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace PeekAndPoke\Component\Slumber\Annotation\Slumber\Store; |
|
7
|
|
|
|
|
8
|
|
|
use PeekAndPoke\Component\Slumber\Annotation\IndexDefinition; |
|
9
|
|
|
use PeekAndPoke\Component\Slumber\Annotation\SlumberAnnotation; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @api |
|
13
|
|
|
* |
|
14
|
|
|
* @author Karsten J. Gerber <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AbstractIndexDefinition extends SlumberAnnotation implements IndexDefinition |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* If {@literal true} the index will be created in the background. |
|
20
|
|
|
* |
|
21
|
|
|
* A background index will not lock / block the database while constructing the index |
|
22
|
|
|
* |
|
23
|
|
|
* @see http://docs.mongodb.org/manual/core/indexes/#background-construction |
|
24
|
|
|
* |
|
25
|
|
|
* @var boolean |
|
26
|
|
|
*/ |
|
27
|
|
|
public $background = false; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* If set to true reject all documents that contain a duplicate value for the indexed field. |
|
31
|
|
|
* |
|
32
|
|
|
* @see http://docs.mongodb.org/manual/core/index-unique/ |
|
33
|
|
|
* |
|
34
|
|
|
* @var boolean |
|
35
|
|
|
*/ |
|
36
|
|
|
public $unique = false; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Where to drop duplicates on creating the index |
|
40
|
|
|
* |
|
41
|
|
|
* @see http://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping |
|
42
|
|
|
* |
|
43
|
|
|
* @var boolean |
|
44
|
|
|
*/ |
|
45
|
|
|
public $dropDups = false; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* The direction of the index is important for sorting big amounts of data. |
|
49
|
|
|
* |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
public $direction = self::ASCENDING; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* If set to true index will skip over any document that is missing the indexed field. |
|
56
|
|
|
* |
|
57
|
|
|
* @see http://docs.mongodb.org/manual/core/index-sparse/ |
|
58
|
|
|
* |
|
59
|
|
|
* @var boolean |
|
60
|
|
|
*/ |
|
61
|
|
|
public $sparse = false; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* The index name to be used. |
|
65
|
|
|
* |
|
66
|
|
|
* This will only be used if the index is defined on a root level document, but not when it is defined on a nested |
|
67
|
|
|
* sub-document. |
|
68
|
|
|
* |
|
69
|
|
|
* When left empty an index name will be generated by default. |
|
70
|
|
|
* |
|
71
|
|
|
* @var string |
|
72
|
|
|
*/ |
|
73
|
|
|
public $name; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Configures the number of seconds after which the collection should expire. Defaults to -1 for no expiry. |
|
77
|
|
|
* |
|
78
|
|
|
* @see http://docs.mongodb.org/manual/tutorial/expire-data/ |
|
79
|
|
|
* |
|
80
|
|
|
* @var int |
|
81
|
|
|
*/ |
|
82
|
|
|
public $expireAfterSeconds = -1; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return boolean |
|
86
|
|
|
*/ |
|
87
|
|
|
public function isBackground() |
|
88
|
|
|
{ |
|
89
|
|
|
return (bool) $this->background; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return boolean |
|
94
|
|
|
*/ |
|
95
|
|
|
public function isUnique() |
|
96
|
|
|
{ |
|
97
|
|
|
return (bool) $this->unique; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return boolean |
|
102
|
|
|
*/ |
|
103
|
|
|
public function isDropDups() |
|
104
|
|
|
{ |
|
105
|
|
|
return (bool) $this->dropDups; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getDirection() |
|
112
|
|
|
{ |
|
113
|
|
|
return (string) $this->direction; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return boolean |
|
118
|
|
|
*/ |
|
119
|
|
|
public function isSparse() |
|
120
|
|
|
{ |
|
121
|
|
|
return (bool) $this->sparse; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getName() |
|
128
|
|
|
{ |
|
129
|
|
|
return (string) $this->name; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @return int |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getExpireAfterSeconds() |
|
136
|
|
|
{ |
|
137
|
|
|
return (int) $this->expireAfterSeconds; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|