@@ -154,7 +154,7 @@ class Doctrine_Import_Schema
154
154
155
155
/**
156
156
* Returns an array of definition keys that can be applied at the global level.
157
- *
157
+ *
158
158
* @return array
159
159
*/
160
160
public static function getGlobalDefinitionKeys ()
@@ -165,7 +165,7 @@ public static function getGlobalDefinitionKeys()
165
165
/**
166
166
* getOption
167
167
*
168
- * @param string $name
168
+ * @param string $name
169
169
* @return void
170
170
*/
171
171
public function getOption ($ name )
@@ -188,8 +188,8 @@ public function getOptions()
188
188
/**
189
189
* setOption
190
190
*
191
- * @param string $name
192
- * @param string $value
191
+ * @param string $name
192
+ * @param string $value
193
193
* @return void
194
194
*/
195
195
public function setOption ($ name , $ value )
@@ -198,11 +198,11 @@ public function setOption($name, $value)
198
198
$ this ->_options [$ name ] = $ value ;
199
199
}
200
200
}
201
-
201
+
202
202
/**
203
203
* setOptions
204
204
*
205
- * @param string $options
205
+ * @param array $options
206
206
* @return void
207
207
*/
208
208
public function setOptions ($ options )
@@ -230,7 +230,7 @@ public function buildSchema($schema, $format)
230
230
$ e = explode ('. ' , $ s );
231
231
if (end ($ e ) === $ format ) {
232
232
$ array = array_merge ($ array , $ this ->parseSchema ($ s , $ format ));
233
- }
233
+ }
234
234
} else if (is_dir ($ s )) {
235
235
$ it = new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($ s ),
236
236
RecursiveIteratorIterator::LEAVES_ONLY );
@@ -270,20 +270,20 @@ public function importSchema($schema, $format = 'yml', $directory = null, $model
270
270
$ builder = new Doctrine_Import_Builder ();
271
271
$ builder ->setTargetPath ($ directory );
272
272
$ builder ->setOptions ($ this ->getOptions ());
273
-
273
+
274
274
$ array = $ this ->buildSchema ($ schema , $ format );
275
275
276
- if (count ($ array ) == 0 ) {
276
+ if (count ($ array ) == 0 ) {
277
277
throw new Doctrine_Import_Exception (
278
278
sprintf ('No ' . $ format . ' schema found in ' . implode (", " , $ schema ))
279
- );
279
+ );
280
280
}
281
281
282
282
foreach ($ array as $ name => $ definition ) {
283
283
if ( ! empty ($ models ) && !in_array ($ definition ['className ' ], $ models )) {
284
284
continue ;
285
285
}
286
-
286
+
287
287
$ builder ->buildRecord ($ definition );
288
288
}
289
289
}
@@ -313,7 +313,7 @@ public function parseSchema($schema, $type)
313
313
'package ' => null ,
314
314
'inheritance ' => array (),
315
315
'detect_relations ' => false );
316
-
316
+
317
317
$ array = Doctrine_Parser::load ($ schema , $ type );
318
318
319
319
// Loop over and build up all the global values and remove them from the array
@@ -431,14 +431,14 @@ public function parseSchema($schema, $type)
431
431
$ build [$ className ][$ key ] = isset ($ build [$ className ][$ key ]) ? $ build [$ className ][$ key ]:$ defaultValue ;
432
432
}
433
433
}
434
-
434
+
435
435
$ build [$ className ]['className ' ] = $ className ;
436
436
$ build [$ className ]['tableName ' ] = $ tableName ;
437
437
$ build [$ className ]['columns ' ] = $ columns ;
438
-
438
+
439
439
// Make sure that anything else that is specified in the schema makes it to the final array
440
440
$ build [$ className ] = Doctrine_Lib::arrayDeepMerge ($ table , $ build [$ className ]);
441
-
441
+
442
442
// We need to keep track of the className for the connection
443
443
$ build [$ className ]['connectionClassName ' ] = $ build [$ className ]['className ' ];
444
444
}
@@ -448,11 +448,11 @@ public function parseSchema($schema, $type)
448
448
449
449
/**
450
450
* _processInheritance
451
- *
451
+ *
452
452
* Perform some processing on inheritance.
453
453
* Sets the default type and sets some default values for certain types
454
454
*
455
- * @param string $array
455
+ * @param string $array
456
456
* @return void
457
457
*/
458
458
protected function _processInheritance ($ array )
@@ -472,9 +472,9 @@ protected function _processInheritance($array)
472
472
if ($ array [$ className ]['inheritance ' ]['type ' ] == 'column_aggregation ' ) {
473
473
// Set the keyField to 'type' by default
474
474
if ( ! isset ($ array [$ className ]['inheritance ' ]['keyField ' ])) {
475
- $ array [$ className ]['inheritance ' ]['keyField ' ] = 'type ' ;
475
+ $ array [$ className ]['inheritance ' ]['keyField ' ] = 'type ' ;
476
476
}
477
-
477
+
478
478
// Set the keyValue to the name of the child class if it does not exist
479
479
if ( ! isset ($ array [$ className ]['inheritance ' ]['keyValue ' ])) {
480
480
$ array [$ className ]['inheritance ' ]['keyValue ' ] = $ className ;
@@ -510,22 +510,22 @@ protected function _processInheritance($array)
510
510
511
511
// Populate the parents subclasses
512
512
if ($ definition ['inheritance ' ]['type ' ] == 'column_aggregation ' ) {
513
- // Fix for 2015: loop through superclasses' inheritance to the base-superclass to
514
- // make sure we collect all keyFields needed (and not only the first)
515
- $ inheritanceFields = array ($ definition ['inheritance ' ]['keyField ' ] => $ definition ['inheritance ' ]['keyValue ' ]);
513
+ // Fix for 2015: loop through superclasses' inheritance to the base-superclass to
514
+ // make sure we collect all keyFields needed (and not only the first)
515
+ $ inheritanceFields = array ($ definition ['inheritance ' ]['keyField ' ] => $ definition ['inheritance ' ]['keyValue ' ]);
516
516
517
- $ superClass = $ definition ['inheritance ' ]['extends ' ];
518
- $ multiInheritanceDef = $ array [$ superClass ];
517
+ $ superClass = $ definition ['inheritance ' ]['extends ' ];
518
+ $ multiInheritanceDef = $ array [$ superClass ];
519
519
520
- while (count ($ multiInheritanceDef ['inheritance ' ]) > 0 && array_key_exists ('extends ' , $ multiInheritanceDef ['inheritance ' ]) && $ multiInheritanceDef ['inheritance ' ]['type ' ] == 'column_aggregation ' ) {
520
+ while (count ($ multiInheritanceDef ['inheritance ' ]) > 0 && array_key_exists ('extends ' , $ multiInheritanceDef ['inheritance ' ]) && $ multiInheritanceDef ['inheritance ' ]['type ' ] == 'column_aggregation ' ) {
521
521
$ superClass = $ multiInheritanceDef ['inheritance ' ]['extends ' ];
522
-
522
+
523
523
// keep original keyField with it's keyValue
524
- if ( ! isset ($ inheritanceFields [$ multiInheritanceDef ['inheritance ' ]['keyField ' ]])) {
524
+ if ( ! isset ($ inheritanceFields [$ multiInheritanceDef ['inheritance ' ]['keyField ' ]])) {
525
525
$ inheritanceFields [$ multiInheritanceDef ['inheritance ' ]['keyField ' ]] = $ multiInheritanceDef ['inheritance ' ]['keyValue ' ];
526
- }
527
- $ multiInheritanceDef = $ array [$ superClass ];
528
- }
526
+ }
527
+ $ multiInheritanceDef = $ array [$ superClass ];
528
+ }
529
529
530
530
$ array [$ parent ]['inheritance ' ]['subclasses ' ][$ definition ['className ' ]] = $ inheritanceFields ;
531
531
}
@@ -555,10 +555,10 @@ protected function _findBaseSuperClass($array, $class)
555
555
* buildRelationships
556
556
*
557
557
* Loop through an array of schema information and build all the necessary relationship information
558
- * Will attempt to auto complete relationships and simplify the amount of information required
558
+ * Will attempt to auto complete relationships and simplify the amount of information required
559
559
* for defining a relationship
560
560
*
561
- * @param string $array
561
+ * @param string $array
562
562
* @return void
563
563
*/
564
564
protected function _buildRelationships ($ array )
@@ -591,18 +591,18 @@ protected function _buildRelationships($array)
591
591
if ( ! isset ($ properties ['relations ' ])) {
592
592
continue ;
593
593
}
594
-
594
+
595
595
$ className = $ properties ['className ' ];
596
596
$ relations = $ properties ['relations ' ];
597
-
597
+
598
598
foreach ($ relations as $ alias => $ relation ) {
599
599
$ class = isset ($ relation ['class ' ]) ? $ relation ['class ' ]:$ alias ;
600
600
if ( ! isset ($ array [$ class ])) {
601
601
continue ;
602
602
}
603
603
$ relation ['class ' ] = $ class ;
604
604
$ relation ['alias ' ] = isset ($ relation ['alias ' ]) ? $ relation ['alias ' ] : $ alias ;
605
-
605
+
606
606
// Attempt to guess the local and foreign
607
607
if (isset ($ relation ['refClass ' ])) {
608
608
$ relation ['local ' ] = isset ($ relation ['local ' ]) ? $ relation ['local ' ]:Doctrine_Inflector::tableize ($ name ) . '_id ' ;
@@ -611,11 +611,11 @@ protected function _buildRelationships($array)
611
611
$ relation ['local ' ] = isset ($ relation ['local ' ]) ? $ relation ['local ' ]:Doctrine_Inflector::tableize ($ relation ['class ' ]) . '_id ' ;
612
612
$ relation ['foreign ' ] = isset ($ relation ['foreign ' ]) ? $ relation ['foreign ' ]:'id ' ;
613
613
}
614
-
614
+
615
615
if (isset ($ relation ['refClass ' ])) {
616
616
$ relation ['type ' ] = 'many ' ;
617
617
}
618
-
618
+
619
619
if (isset ($ relation ['type ' ]) && $ relation ['type ' ]) {
620
620
$ relation ['type ' ] = $ relation ['type ' ] === 'one ' ? Doctrine_Relation::ONE :Doctrine_Relation::MANY ;
621
621
} else {
@@ -625,26 +625,26 @@ protected function _buildRelationships($array)
625
625
if (isset ($ relation ['foreignType ' ]) && $ relation ['foreignType ' ]) {
626
626
$ relation ['foreignType ' ] = $ relation ['foreignType ' ] === 'one ' ? Doctrine_Relation::ONE :Doctrine_Relation::MANY ;
627
627
}
628
-
628
+
629
629
$ relation ['key ' ] = $ this ->_buildUniqueRelationKey ($ relation );
630
-
630
+
631
631
$ this ->_validateSchemaElement ('relation ' , array_keys ($ relation ), $ className . '->relation-> ' . $ relation ['alias ' ]);
632
-
632
+
633
633
$ this ->_relations [$ className ][$ alias ] = $ relation ;
634
634
}
635
635
}
636
-
636
+
637
637
// Now we auto-complete opposite ends of relationships
638
638
$ this ->_autoCompleteOppositeRelations ();
639
-
639
+
640
640
// Make sure we do not have any duplicate relations
641
641
$ this ->_fixDuplicateRelations ();
642
642
643
643
// Set the full array of relationships for each class to the final array
644
644
foreach ($ this ->_relations as $ className => $ relations ) {
645
645
$ array [$ className ]['relations ' ] = $ relations ;
646
646
}
647
-
647
+
648
648
return $ array ;
649
649
}
650
650
@@ -663,22 +663,22 @@ protected function _autoCompleteOppositeRelations()
663
663
if ((isset ($ relation ['equal ' ]) && $ relation ['equal ' ]) || (isset ($ relation ['autoComplete ' ]) && $ relation ['autoComplete ' ] === false )) {
664
664
continue ;
665
665
}
666
-
666
+
667
667
$ newRelation = array ();
668
668
$ newRelation ['foreign ' ] = $ relation ['local ' ];
669
669
$ newRelation ['local ' ] = $ relation ['foreign ' ];
670
670
$ newRelation ['class ' ] = isset ($ relation ['foreignClass ' ]) ? $ relation ['foreignClass ' ]:$ className ;
671
671
$ newRelation ['alias ' ] = isset ($ relation ['foreignAlias ' ]) ? $ relation ['foreignAlias ' ]:$ className ;
672
672
$ newRelation ['foreignAlias ' ] = $ alias ;
673
-
673
+
674
674
// this is so that we know that this relation was autogenerated and
675
675
// that we do not need to include it if it is explicitly declared in the schema by the users.
676
- $ newRelation ['autogenerated ' ] = true ;
677
-
676
+ $ newRelation ['autogenerated ' ] = true ;
677
+
678
678
if (isset ($ relation ['refClass ' ])) {
679
679
$ newRelation ['refClass ' ] = $ relation ['refClass ' ];
680
680
$ newRelation ['type ' ] = isset ($ relation ['foreignType ' ]) ? $ relation ['foreignType ' ]:$ relation ['type ' ];
681
- } else {
681
+ } else {
682
682
if (isset ($ relation ['foreignType ' ])) {
683
683
$ newRelation ['type ' ] = $ relation ['foreignType ' ];
684
684
} else {
@@ -720,7 +720,7 @@ protected function _fixDuplicateRelations()
720
720
}
721
721
}
722
722
}
723
-
723
+
724
724
$ this ->_relations [$ className ] = $ uniqueRelations ;
725
725
}
726
726
}
@@ -731,7 +731,7 @@ protected function _fixDuplicateRelations()
731
731
* Build a unique key to identify a relationship by
732
732
* Md5 hash of all the relationship parameters
733
733
*
734
- * @param string $relation
734
+ * @param string $relation
735
735
* @return void
736
736
*/
737
737
protected function _buildUniqueRelationKey ($ relation )
@@ -742,8 +742,8 @@ protected function _buildUniqueRelationKey($relation)
742
742
/**
743
743
* _validateSchemaElement
744
744
*
745
- * @param string $name
746
- * @param string $value
745
+ * @param string $name
746
+ * @param string $value
747
747
* @return void
748
748
*/
749
749
protected function _validateSchemaElement ($ name , $ element , $ path )
@@ -768,4 +768,4 @@ protected function _validateSchemaElement($name, $element, $path)
768
768
}
769
769
}
770
770
}
771
- }
771
+ }
0 commit comments