00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class DBSchema extends QueryIdentification
00017 {
00018 private $tables = array();
00019 private $order = array();
00020
00021 public function getTables()
00022 {
00023 return $this->tables;
00024 }
00025
00026 public function getTableNames()
00027 {
00028 return $this->order;
00029 }
00030
00035 public function addTable(DBTable $table)
00036 {
00037 $name = $table->getName();
00038
00039 Assert::isFalse(
00040 isset($this->tables[$name]),
00041 "table '{$name}' already exist"
00042 );
00043
00044 $this->tables[$table->getName()] = $table;
00045 $this->order[] = $name;
00046
00047 return $this;
00048 }
00049
00054 public function getTableByName($name)
00055 {
00056 if (!isset($this->tables[$name]))
00057 throw new MissingElementException(
00058 "table '{$name}' does not exist"
00059 );
00060
00061 return $this->tables[$name];
00062 }
00063
00064 public function toDialectString(Dialect $dialect)
00065 {
00066 $out = array();
00067
00068 foreach ($this->order as $name) {
00069 $out[] = $this->tables[$name]->toDialectString($dialect);
00070 }
00071
00072 return implode("\n\n", $out);
00073 }
00074 }
00075 ?>