@@ -50,7 +50,12 @@ class Field implements Buildable
50
50
/**
51
51
* @var FieldBuilder
52
52
*/
53
- protected $ builder ;
53
+ protected $ fieldBuilder ;
54
+
55
+ /**
56
+ * @var ClassMetadataBuilder
57
+ */
58
+ protected $ metaDatabuilder ;
54
59
55
60
/**
56
61
* @var ClassMetadataInfo
@@ -70,15 +75,16 @@ class Field implements Buildable
70
75
/**
71
76
* Protected constructor to force usage of factory method.
72
77
*
73
- * @param FieldBuilder $builder
74
- * @param ClassMetadataInfo $classMetadata
75
- * @param Type $type
76
- * @param string $name
78
+ * @param FieldBuilder $fieldBuilder
79
+ * @param ClassMetadataBuilder $builder
80
+ * @param Type $type
81
+ * @param string $name
77
82
*/
78
- protected function __construct (FieldBuilder $ builder , ClassMetadataInfo $ classMetadata , Type $ type , $ name )
83
+ protected function __construct (FieldBuilder $ fieldBuilder , ClassMetadataBuilder $ builder , Type $ type , $ name )
79
84
{
80
- $ this ->builder = $ builder ;
81
- $ this ->classMetadata = $ classMetadata ;
85
+ $ this ->fieldBuilder = $ fieldBuilder ;
86
+ $ this ->metaDatabuilder = $ builder ;
87
+ $ this ->classMetadata = $ builder ->getClassMetadata ();
82
88
$ this ->type = $ type ;
83
89
$ this ->name = $ name ;
84
90
}
@@ -98,7 +104,7 @@ public static function make(ClassMetadataBuilder $builder, $type, $name)
98
104
99
105
$ field = $ builder ->createField ($ name , $ type ->getName ());
100
106
101
- return new static ($ field , $ builder-> getClassMetadata () , $ type , $ name );
107
+ return new static ($ field , $ builder , $ type , $ name );
102
108
}
103
109
104
110
/**
@@ -157,7 +163,7 @@ public function autoIncrement()
157
163
*/
158
164
public function generatedValue (callable $ callback = null )
159
165
{
160
- $ generatedValue = new GeneratedValue ($ this ->builder , $ this ->classMetadata );
166
+ $ generatedValue = new GeneratedValue ($ this ->fieldBuilder , $ this ->classMetadata );
161
167
162
168
if ($ callback ) {
163
169
$ callback ($ generatedValue );
@@ -176,7 +182,7 @@ public function generatedValue(callable $callback = null)
176
182
*/
177
183
public function unsigned ()
178
184
{
179
- $ this ->builder ->option ('unsigned ' , true );
185
+ $ this ->fieldBuilder ->option ('unsigned ' , true );
180
186
181
187
return $ this ;
182
188
}
@@ -191,7 +197,7 @@ public function unsigned()
191
197
*/
192
198
public function fixed ($ fixed )
193
199
{
194
- $ this ->builder ->option ('fixed ' , $ fixed );
200
+ $ this ->fieldBuilder ->option ('fixed ' , $ fixed );
195
201
196
202
return $ this ;
197
203
}
@@ -205,7 +211,7 @@ public function fixed($fixed)
205
211
*/
206
212
public function comment ($ comment )
207
213
{
208
- $ this ->builder ->option ('comment ' , $ comment );
214
+ $ this ->fieldBuilder ->option ('comment ' , $ comment );
209
215
210
216
return $ this ;
211
217
}
@@ -219,7 +225,7 @@ public function comment($comment)
219
225
*/
220
226
public function collation ($ collation )
221
227
{
222
- $ this ->builder ->option ('collation ' , $ collation );
228
+ $ this ->fieldBuilder ->option ('collation ' , $ collation );
223
229
224
230
return $ this ;
225
231
}
@@ -229,7 +235,28 @@ public function collation($collation)
229
235
*/
230
236
public function primary ()
231
237
{
232
- $ this ->builder ->makePrimaryKey ();
238
+ $ this ->fieldBuilder ->makePrimaryKey ();
239
+
240
+ return $ this ;
241
+ }
242
+
243
+ /**
244
+ * @param string|null $name
245
+ *
246
+ * @return Field
247
+ */
248
+ public function index ($ name = null )
249
+ {
250
+ $ index = new Index (
251
+ $ this ->metaDatabuilder ,
252
+ [$ this ->getName ()]
253
+ );
254
+
255
+ if ($ name !== null ) {
256
+ $ index ->name ($ name );
257
+ }
258
+
259
+ $ this ->callbackAndQueue ($ index );
233
260
234
261
return $ this ;
235
262
}
@@ -239,7 +266,7 @@ public function primary()
239
266
*/
240
267
public function useForVersioning ()
241
268
{
242
- $ this ->builder ->isVersionField ();
269
+ $ this ->fieldBuilder ->isVersionField ();
243
270
244
271
return $ this ;
245
272
}
@@ -249,7 +276,7 @@ public function useForVersioning()
249
276
*/
250
277
public function build ()
251
278
{
252
- $ this ->builder ->build ();
279
+ $ this ->fieldBuilder ->build ();
253
280
254
281
$ this ->buildQueued ();
255
282
@@ -261,7 +288,7 @@ public function build()
261
288
*/
262
289
public function getBuilder ()
263
290
{
264
- return $ this ->builder ;
291
+ return $ this ->fieldBuilder ;
265
292
}
266
293
267
294
/**
@@ -303,7 +330,7 @@ public function __call($method, $args)
303
330
*/
304
331
protected function setDefault ($ default )
305
332
{
306
- $ this ->builder ->option ('default ' , $ default );
333
+ $ this ->fieldBuilder ->option ('default ' , $ default );
307
334
308
335
return $ this ;
309
336
}
0 commit comments