FromTable.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Anton E. Lebedevich                        *
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: FromTable.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     final class FromTable implements Aliased, SQLTableName
00019     {
00020         private $table  = null;
00021         private $alias  = null;
00022         private $schema = null;
00023         
00024         public function __construct($table, $alias = null)
00025         {
00026             if (
00027                 !$alias
00028                 &&
00029                     (
00030                         $table instanceof SelectQuery
00031                         || $table instanceof LogicalObject
00032                         || $table instanceof SQLFunction
00033                     )
00034             )
00035                 throw new WrongArgumentException(
00036                     'you should specify alias, when using '.
00037                     'SelectQuery or LogicalObject as table'
00038                 );
00039 
00040             if (is_string($table) && strpos($table, '.') !== false)
00041                 list($this->schema, $this->table) = explode('.', $table, 2);
00042             else
00043                 $this->table = $table;
00044             
00045             $this->alias = $alias;
00046         }
00047         
00048         public function getAlias()
00049         {
00050             return $this->alias;
00051         }
00052 
00053         public function toDialectString(Dialect $dialect)
00054         {
00055             if ($this->table instanceof Query)
00056                 return
00057                     "({$this->table->toDialectString($dialect)}) AS "
00058                     .$dialect->quoteTable($this->alias);
00059             elseif ($this->table instanceof DialectString)
00060                 return
00061                     $this->table->toDialectString($dialect).' AS '
00062                     .$dialect->quoteTable($this->alias);
00063             else
00064                 return
00065                     (
00066                         $this->schema
00067                             ? $dialect->quoteTable($this->schema)."."
00068                             : null
00069                     )
00070                     .$dialect->quoteTable($this->table)
00071                     .(
00072                         $this->alias
00073                             ? ' AS '.$dialect->quoteTable($this->alias)
00074                             : null
00075                     );
00076         }
00077 
00078         public function getTable()
00079         {
00080             return $this->alias ? $this->alias : $this->table;
00081         }
00082     }
00083 ?>

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