Skip to content

Commit 5fe0e1e

Browse files
authored
Merge pull request #14 from congpeijun/master
Support column collation
2 parents cb27207 + e12917c commit 5fe0e1e

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/Loader/BaseLoader.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
namespace DbTk\SchemaLoader\Loader;
44

5-
use DbTk\SchemaLoader\Exception\FileNotFoundException;
65
use DbTk\SchemaLoader\Exception\UnsupportedFieldTypeException;
7-
use Doctrine\DBAL\Types\Type;
86
use Doctrine\DBAL\Schema\Column;
9-
use Doctrine\DBAL\Schema\Index;
107
use 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
*/
1514
abstract 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

Comments
 (0)