contributions/db.driverswitch/model/base/dbtabledriverswitch.csl.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * Change driver of given DBTable 00004 * 00005 * @author Gerd Riesselmann 00006 * @ingroup DriverSwitch 00007 */ 00008 class DBTableDriverSwitch implements IDBTable { 00009 /** 00010 * Table to change driver for 00011 * 00012 * @var IDBTable 00013 */ 00014 protected $delegate; 00015 /** 00016 * New driver 00017 * 00018 * @var IDBDriver 00019 */ 00020 protected $driver; 00021 00022 /** 00023 * Constructor 00024 * 00025 * @param IDBTable $table The table 00026 * @param IDBDriver $driver 00027 */ 00028 public function __construct(IDBTable $table, $driver) { 00029 $this->delegate = $table; 00030 $this->driver = $driver; 00031 } 00032 00033 /** 00034 * Switch given table to connection 00035 * 00036 * @param string Table or model name 00037 * @param IDBDriver|string Driver or driver name 00038 */ 00039 public static function switch_table($table_name, $driver) { 00040 DB::create($table_name); 00041 $table = DBTableRepository::get($table_name); 00042 $switched = new DBTableDriverSwitch($table, DB::get_connection($driver)); 00043 DBTableRepository::register($switched, $table_name); 00044 } 00045 00046 /** 00047 * Returns name of table 00048 * 00049 * @return string 00050 */ 00051 public function get_table_name() { 00052 return $this->delegate->get_table_name(); 00053 } 00054 00055 /** 00056 * Returns alias of table, if any 00057 * 00058 * @return string 00059 */ 00060 public function get_table_alias() { 00061 return $this->delegate->get_table_alias(); 00062 } 00063 00064 /** 00065 * Returns name of table, but escaped 00066 * 00067 * @return string 00068 */ 00069 public function get_table_name_escaped() { 00070 return $this->get_table_driver()->escape_database_entity($this->get_table_name(), IDBDriver::TABLE); 00071 } 00072 00073 /** 00074 * Returns alias of table, if any - but escaped 00075 * 00076 * @return string 00077 */ 00078 public function get_table_alias_escaped() { 00079 return $this->delegate->get_table_alias_escaped(); 00080 } 00081 00082 /** 00083 * Returns array of columns 00084 * 00085 * @return array Associative array with column name as key and IDBField instance as value 00086 */ 00087 public function get_table_fields() { 00088 return $this->delegate->get_table_fields(); 00089 } 00090 00091 /** 00092 * Returns field for given column 00093 * 00094 * @param string $column Column name 00095 * @return IDBField Either field or false if no such field exists 00096 */ 00097 public function get_table_field($column) { 00098 return $this->delegate->get_table_field($column); 00099 } 00100 00101 /** 00102 * Returns array of keys 00103 * 00104 * @return array Associative array with column name as key and IDField instance as value 00105 */ 00106 public function get_table_keys() { 00107 return $this->delegate->get_table_keys(); 00108 } 00109 00110 /** 00111 * Returns array of relations 00112 * 00113 * @return array Array with IDBRelation instance as value 00114 */ 00115 public function get_table_relations() { 00116 return $this->delegate->get_table_relations(); 00117 } 00118 00119 /** 00120 * Returns relations between two tables 00121 * 00122 * @param IDBTable $other 00123 * @return array Array of IDBRelations 00124 */ 00125 public function get_matching_relations(IDBTable $other) { 00126 return $this->delegate->get_matching_relations($other); 00127 } 00128 00129 /** 00130 * Returns array of constraints 00131 * 00132 * @return array Array with IDBConstraint instance as value 00133 */ 00134 public function get_table_constraints() { 00135 return $this->delegate->get_table_constraints(); 00136 } 00137 00138 /** 00139 * Returns DB driver fro this table 00140 * 00141 * @return IDBDriver 00142 */ 00143 public function get_table_driver() { 00144 return $this->driver; 00145 } 00146 }