1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xoops\Core\Database\Schema;
13:
14: use Doctrine\DBAL\Schema\Table;
15: use Doctrine\DBAL\Schema\Schema;
16: use Doctrine\DBAL\Schema\Column;
17: use Doctrine\DBAL\Schema\ForeignKeyConstraint;
18: use Doctrine\DBAL\Schema\Sequence;
19: use Doctrine\DBAL\Schema\Index;
20: use Doctrine\DBAL\Schema\Visitor\Visitor;
21:
22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
35: class ExportVisitor implements Visitor
36: {
37:
38: protected $schemaArray;
39:
40: 41: 42:
43: public function __construct()
44: {
45: $this->schemaArray = array();
46: }
47:
48: 49: 50: 51: 52:
53: public function getSchemaArray()
54: {
55: return $this->schemaArray;
56: }
57:
58: 59: 60: 61: 62: 63: 64:
65: public function acceptSchema(Schema $schema)
66: {
67:
68: }
69:
70: 71: 72: 73: 74: 75: 76:
77: public function acceptTable(Table $table)
78: {
79: $this->schemaArray['tables'][$table->getName()]['options'] = $table->getOptions();
80: }
81:
82: 83: 84: 85: 86: 87: 88: 89:
90: public function acceptColumn(Table $table, Column $column)
91: {
92: $this->schemaArray['tables'][$table->getName()]['columns'][$column->getName()] = $column->toArray();
93: $this->schemaArray['tables'][$table->getName()]['columns'][$column->getName()]['type'] =
94: $column->getType()->getName();
95: }
96:
97: 98: 99: 100: 101: 102: 103: 104:
105: public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
106: {
107: if (!isset($this->schemaArray['tables'][$localTable->getName()]['constraint'])) {
108: $this->schemaArray['tables'][$localTable->getName()]['constraint']=array();
109: }
110: $this->schemaArray['tables'][$localTable->getName()]['constraint'][] = array(
111: 'name' => $fkConstraint->getName(),
112: 'localcolumns' => $fkConstraint->getLocalColumns(),
113: 'foreigntable' => $fkConstraint->getForeignTableName(),
114: 'foreigncolumns' => $fkConstraint->getForeignColumns(),
115: 'options' => $fkConstraint->getOptions()
116: );
117:
118: }
119:
120: 121: 122: 123: 124: 125: 126: 127:
128: public function acceptIndex(Table $table, Index $index)
129: {
130: $this->schemaArray['tables'][$table->getName()]['indexes'][$index->getName()] = array(
131: 'name' => $index->getName(),
132: 'columns' => $index->getColumns(),
133: 'unique' => $index->isUnique(),
134: 'primary' => $index->isPrimary()
135: );
136: }
137:
138: 139: 140: 141: 142: 143: 144:
145: public function acceptSequence(Sequence $sequence)
146: {
147: $this->schemaArray['sequence'][$sequence->getName()] = array(
148: 'name' => $sequence->getName(),
149: 'allocationsize' => $sequence->getAllocationSize(),
150: 'initialvalue' => $sequence->getInitialValue()
151: );
152: }
153: }
154: