22
33namespace DbTk \SchemaLoader \Loader ;
44
5- use DbTk \SchemaLoader \Exception \FileNotFoundException ;
65use DbTk \SchemaLoader \Exception \UnsupportedFieldTypeException ;
7- use Doctrine \DBAL \Types \Type ;
86use Doctrine \DBAL \Schema \Column ;
9- use Doctrine \DBAL \Schema \Index ;
107use Doctrine \DBAL \Schema \ForeignKeyConstraint ;
8+ use Doctrine \DBAL \Schema \Index ;
9+ use Doctrine \DBAL \Types \Type ;
1110
1211/**
1312 * @author Igor Mukhin <igor.mukhin@gmail.com>
1413 */
1514abstract class BaseLoader
1615{
1716 protected $ extraOptions = array (
18- 'default ' =>'typeaware ' ,
19- 'notnull ' =>'boolean ' ,
20- 'length ' =>'integer ' ,
21- 'precision ' =>'integer ' ,
22- 'scale ' =>'integer ' ,
23- 'fixed ' =>'boolean ' ,
24- 'unsigned ' =>'boolean ' ,
25- 'autoincrement ' =>'boolean ' ,
26- 'comment ' =>'string '
17+ 'default ' => 'typeaware ' ,
18+ 'notnull ' => 'boolean ' ,
19+ 'length ' => 'integer ' ,
20+ 'precision ' => 'integer ' ,
21+ 'scale ' => 'integer ' ,
22+ 'fixed ' => 'boolean ' ,
23+ 'unsigned ' => 'boolean ' ,
24+ 'autoincrement ' => 'boolean ' ,
25+ 'comment ' => 'string ' ,
26+ 'collation ' => 'string ' ,
2727 );
2828
2929 /**
@@ -50,7 +50,12 @@ public function loadColumn($columnNode)
5050 }
5151
5252 $ options = $ this ->getColumnExtraOptions ($ type , $ columnNode );
53- return new Column ((string )$ columnNode ['name ' ], Type::getType ($ type ), $ options );
53+ $ column = new Column ((string ) $ columnNode ['name ' ], Type::getType ($ type ), $ options );
54+
55+ if (($ collation = (string ) $ columnNode ['collation ' ])) {
56+ $ column ->setPlatformOption ('collation ' , $ collation );
57+ }
58+ return $ column ;
5459 }
5560
5661 /**
@@ -61,9 +66,9 @@ public function loadColumn($columnNode)
6166 public function getColumnExtraOptions ($ type , $ columnNode )
6267 {
6368 $ options = array ();
64- foreach ($ this ->extraOptions as $ optionName=> $ optionType ) {
69+ foreach ($ this ->extraOptions as $ optionName => $ optionType ) {
6570 if (isset ($ columnNode [$ optionName ])) {
66- $ options [$ optionName ] = $ this ->convertColumnOptionValue ((string )$ columnNode [$ optionName ], $ type , $ optionType );
71+ $ options [$ optionName ] = $ this ->convertColumnOptionValue ((string ) $ columnNode [$ optionName ], $ type , $ optionType );
6772 }
6873 }
6974 return $ options ;
@@ -82,10 +87,10 @@ protected function convertColumnOptionValue($optionValue, $type, $optionType)
8287 return $ optionValue === 'true ' ? true : false ;
8388
8489 case 'integer ' :
85- return (int )$ optionValue ;
90+ return (int ) $ optionValue ;
8691
8792 case 'string ' :
88- return (string )$ optionValue ;
93+ return (string ) $ optionValue ;
8994
9095 case 'typeaware ' :
9196 if ('null ' == $ optionValue ) {
@@ -98,13 +103,13 @@ protected function convertColumnOptionValue($optionValue, $type, $optionType)
98103 case 'bigint ' :
99104 case 'float ' :
100105 case 'decimal ' :
101- return (int )$ optionValue ;
106+ return (int ) $ optionValue ;
102107
103108 case 'boolean ' :
104109 return $ optionValue === 'true ' ? true : false ;
105110
106111 default :
107- return (string )$ optionValue ;
112+ return (string ) $ optionValue ;
108113 }
109114
110115 default :
0 commit comments