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 /* $Id: DBSchema.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4