@@ -52,7 +52,14 @@ class CreateCollection implements Executable
52
52
*
53
53
* * storageEngine (document): Storage engine options.
54
54
*
55
+ * * validationAction (string): Validation action.
56
+ *
57
+ * * validationLevel (string): Validation level.
58
+ *
59
+ * * validator (document): Validation rules or expressions.
60
+ *
55
61
* @see http://source.wiredtiger.com/2.4.1/struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb
62
+ * @see https://docs.mongodb.org/manual/core/document-validation/
56
63
* @param string $databaseName Database name
57
64
* @param string $collectionName Collection name
58
65
* @param array $options Command options
@@ -92,6 +99,18 @@ public function __construct($databaseName, $collectionName, array $options = [])
92
99
throw new InvalidArgumentTypeException ('"storageEngine" option ' , $ options ['storageEngine ' ], 'array or object ' );
93
100
}
94
101
102
+ if (isset ($ options ['validationAction ' ]) && ! is_string ($ options ['validationAction ' ])) {
103
+ throw new InvalidArgumentTypeException ('"validationAction" option ' , $ options ['validationAction ' ], 'string ' );
104
+ }
105
+
106
+ if (isset ($ options ['validationLevel ' ]) && ! is_string ($ options ['validationLevel ' ])) {
107
+ throw new InvalidArgumentTypeException ('"validationLevel" option ' , $ options ['validationLevel ' ], 'string ' );
108
+ }
109
+
110
+ if (isset ($ options ['validator ' ]) && ! is_array ($ options ['validator ' ]) && ! is_object ($ options ['validator ' ])) {
111
+ throw new InvalidArgumentTypeException ('"validator" option ' , $ options ['validator ' ], 'array or object ' );
112
+ }
113
+
95
114
$ this ->databaseName = (string ) $ databaseName ;
96
115
$ this ->collectionName = (string ) $ collectionName ;
97
116
$ this ->options = $ options ;
@@ -120,20 +139,24 @@ private function createCommand()
120
139
{
121
140
$ cmd = ['create ' => $ this ->collectionName ];
122
141
123
- foreach (['autoIndexId ' , 'capped ' , 'flags ' , 'max ' , 'maxTimeMS ' , 'size ' ] as $ option ) {
142
+ foreach (['autoIndexId ' , 'capped ' , 'flags ' , 'max ' , 'maxTimeMS ' , 'size ' , ' validationAction ' , ' validationLevel ' ] as $ option ) {
124
143
if (isset ($ this ->options [$ option ])) {
125
144
$ cmd [$ option ] = $ this ->options [$ option ];
126
145
}
127
146
}
128
147
129
- if ( ! empty ($ this ->options ['indexOptionDefaults ' ])) {
148
+ if (isset ($ this ->options ['indexOptionDefaults ' ])) {
130
149
$ cmd ['indexOptionDefaults ' ] = (object ) $ this ->options ['indexOptionDefaults ' ];
131
150
}
132
151
133
- if ( ! empty ($ this ->options ['storageEngine ' ])) {
152
+ if (isset ($ this ->options ['storageEngine ' ])) {
134
153
$ cmd ['storageEngine ' ] = (object ) $ this ->options ['storageEngine ' ];
135
154
}
136
155
156
+ if (isset ($ this ->options ['validator ' ])) {
157
+ $ cmd ['validator ' ] = (object ) $ this ->options ['validator ' ];
158
+ }
159
+
137
160
return new Command ($ cmd );
138
161
}
139
162
}
0 commit comments