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: DBField.class.php 4687 2007-12-09 18:57:18Z voxus $ */ 00012 00018 final class DBField extends Castable implements DialectString, SQLTableName 00019 { 00020 private $field = null; 00021 private $table = null; 00022 00023 public function __construct($field, $table = null) 00024 { 00025 $this->field = $field; 00026 00027 if ($table) 00028 $this->setTable($table); 00029 } 00030 00034 public static function create($field, $table = null) 00035 { 00036 return new self($field, $table); 00037 } 00038 00039 public function toDialectString(Dialect $dialect) 00040 { 00041 $field = 00042 ( 00043 $this->table 00044 ? $this->table->toDialectString($dialect).'.' 00045 : null 00046 ) 00047 .$dialect->quoteField($this->field); 00048 00049 return 00050 $this->cast 00051 ? $dialect->toCasted($field, $this->cast) 00052 : $field; 00053 } 00054 00055 public function getField() 00056 { 00057 return $this->field; 00058 } 00059 00063 public function getTable() 00064 { 00065 return $this->table; 00066 } 00067 00072 public function setTable($table) 00073 { 00074 if ($this->table !== null) 00075 throw new WrongStateException( 00076 'you should not override setted table' 00077 ); 00078 00079 if (!$table instanceof DialectString) 00080 $this->table = new FromTable($table); 00081 else 00082 $this->table = $table; 00083 00084 return $this; 00085 } 00086 } 00087 ?>