| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/dbal/src/exception/lmbDbException.class.php'); 10 11 /** 12 * abstract class lmbDbTableInfo. 13 * 14 * @package dbal 15 * @version $Id: lmbDbTableInfo.class.php 5945 2007-06-06 08:31:43Z pachanga $ 16 */ 17 abstract class lmbDbTableInfo 18 { 19 protected $name; 20 protected $columns = array(); 21 protected $canonicalHandler; 22 protected $cached_columns = array(); 23 24 function __construct($name, $canonicalHandler = null) 25 { 26 $this->name = $this->canonicalizeIdentifier($name); 27 28 if($canonicalHandler !== null && 29 $canonicalHandler != 'strtolower' && 30 $canonicalHandler != 'strtoupper') 31 { 32 throw new lmbDbException("Invalid identifier compatability function '$canonicalHandler'"); 33 } 34 $this->canonicalHandler = $canonicalHandler; 35 } 36 37 function canonicalizeIdentifier($id) 38 { 39 if(!is_null($this->canonicalHandler)) 40 return $this->canonicalHandler($id); 41 42 return $id; 43 } 44 45 function getCanonicalColumnName($name) 46 { 47 $name = $this->canonicalizeIdentifier($name); 48 // quick check if they happen to use the same case. 49 if(array_key_exists($name, $this->columns)) 50 return $name; 51 52 // slow check 53 foreach(array_keys($this->columns) as $key) 54 { 55 if(strcasecmp($name, $key) == 0) 56 return $key; 57 } 58 return $name; 59 } 60 61 function getName() 62 { 63 return $this->name; 64 } 65 66 abstract function loadColumns(); 67 68 function hasColumn($name) 69 { 70 $old_name = $name; 71 if(isset($this->cached_columns[$old_name])) 72 return true; 73 74 $this->loadColumns(); 75 $name = $this->getCanonicalColumnName($name); 76 if(array_key_exists($name, $this->columns)) 77 { 78 $this->cached_columns[$old_name] = $this->columns[$name]; 79 return true; 80 } 81 else 82 return false; 83 } 84 85 function getColumn($name) 86 { 87 $old_name = $name; 88 if(isset($this->cached_columns[$old_name])) 89 return $this->cached_columns[$old_name]; 90 91 $this->loadColumns(); 92 $name = $this->getCanonicalColumnName($name); 93 if(!array_key_exists($name, $this->columns)) 94 { 95 throw new lmbDbException("Column '$name' does not exist"); 96 } 97 98 $this->cached_columns[$old_name] = $this->columns[$name]; 99 return $this->cached_columns[$old_name]; 100 } 101 102 function getColumnList() 103 { 104 $this->loadColumns(); 105 $result = array(); 106 foreach(array_keys($this->columns) as $name) 107 $result[$name] = $name; 108 return $result; 109 } 110 } 111 112 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Aug 29 04:49:26 2008 | Cross-referenced by PHPXref 0.7 |