1 | <?php |
||
34 | class PrefixStripper extends Schema |
||
35 | { |
||
36 | |||
37 | private $xPrefix = ''; |
||
38 | private $xDbName = ''; |
||
39 | private $tableList = array(); |
||
40 | |||
41 | /** |
||
42 | * constructor |
||
43 | */ |
||
44 | 11 | public function __construct(array $tables=array(), array $sequences=array(), SchemaConfig $schemaConfig=null) |
|
50 | |||
51 | /** |
||
52 | * set list of tables to limit schema |
||
53 | * |
||
54 | * If no list is specified, all tables will be included |
||
55 | * |
||
56 | * @param array $tableList list of tables to include |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public function setTableFilter(array $tableList) |
||
61 | { |
||
62 | $this->tableList = $tableList; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Add a table object to the schema |
||
67 | * |
||
68 | * @param Table $table table object to add |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | 1 | public function addTable(Table $table) |
|
73 | { |
||
74 | //echo '<h2>addTable()</h2>'; |
||
75 | try { |
||
76 | 1 | $name = $table->getName(); |
|
77 | 1 | $len = strlen($this->xPrefix); |
|
78 | 1 | if (substr_compare($name, $this->xPrefix, 0, $len)===0) { |
|
79 | $name = substr($name, $len); |
||
80 | if (empty($this->tableList) || in_array($name, $this->tableList)) { |
||
81 | $idGeneratorType = 0; // how should we handle this? |
||
82 | $newtable = new Table( |
||
83 | $name, |
||
84 | $table->getColumns(), |
||
85 | $table->getIndexes(), |
||
86 | $table->getForeignKeys(), |
||
87 | $idGeneratorType, |
||
88 | $table->getOptions() |
||
89 | ); |
||
90 | 1 | $this->_addTable($newtable); |
|
91 | } |
||
92 | } |
||
93 | //Debug::dump($table); |
||
94 | } catch (\Exception $e) { |
||
95 | \Xoops::getInstance()->events()->triggerEvent('core.exception', $e); |
||
96 | throw $e; |
||
97 | } |
||
98 | 1 | } |
|
99 | |||
100 | /** |
||
101 | * Add a sequence to the schema |
||
102 | * |
||
103 | * @param Sequence $sequence a sequence |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | 1 | public function addSequence(Sequence $sequence) |
|
118 | } |
||
119 |