DBSchema.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     final class DBSchema extends QueryIdentification
00016     {
00017         private $tables = array();
00018         private $order  = array();
00019         
00020         public function getTables()
00021         {
00022             return $this->tables;
00023         }
00024         
00025         public function getTableNames()
00026         {
00027             return $this->order;
00028         }
00029         
00034         public function addTable(DBTable $table)
00035         {
00036             $name = $table->getName();
00037             
00038             Assert::isFalse(
00039                 isset($this->tables[$name]),
00040                 "table '{$name}' already exist"
00041             );
00042             
00043             $this->tables[$table->getName()] = $table;
00044             $this->order[] = $name;
00045             
00046             return $this;
00047         }
00048         
00053         public function getTableByName($name)
00054         {
00055             if (!isset($this->tables[$name]))
00056                 throw new MissingElementException(
00057                     "table '{$name}' does not exist"
00058                 );
00059             
00060             return $this->tables[$name];
00061         }
00062         
00063         public function toDialectString(Dialect $dialect)
00064         {
00065             $out = array();
00066             
00067             foreach ($this->order as $name) {
00068                 $out[] = $this->tables[$name]->toDialectString($dialect);
00069             }
00070             
00071             return implode("\n\n", $out);
00072         }
00073     }
00074 ?>