| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: PeerInfo.php 64 2005-05-13 02:43:56Z root $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://propel.phpdb.org>. 20 */ 21 22 /** 23 * Peer Helper Class 24 * 25 * Handle Dynamic Peer Access. Trying to solve the problems associated 26 * with looking at constants, calling methods on static Peer Objects 27 * 28 * @author David Giffin <david@giffin.org> 29 * @copyright Copyright (c) 2000-2003 David Giffin : LGPL - See LICENCE 30 * @package propel.util 31 */ 32 class PeerInfo 33 { 34 /** Propel Object Peers */ 35 private static $peers = array(); 36 37 /** Reflection Objects of the Propel Peers */ 38 private static $reflections = array(); 39 40 /** Table Maps of the Propel Peers */ 41 private static $maps = array(); 42 43 44 /** 45 * Add a Peer to the list of Peers 46 * 47 * @param string $peer The Propel Peer to add 48 */ 49 private static function addPeer($peer) 50 { 51 52 53 $peers = array_keys(self::$peers); 54 55 if (!in_array($peer, $peers)) { 56 57 self::$peers[$peer] = self::loadPeer($peer); 58 self::$reflections[$peer] = new reflectionClass($peer); 59 self::$maps[$peer] = null; 60 61 } 62 } 63 64 65 /** 66 * Get a constant from the Peer Reflector 67 * 68 * @param String The name of the constant 69 * @return String The Constant String 70 */ 71 public static function getPeerConstant($peer, $name) 72 { 73 self::addPeer($peer); 74 return self::$reflections[$peer]->getConstant($name); 75 } 76 77 78 /** 79 * Get a Peer from the Peer List 80 * 81 * @param string $peer The Propel Peer to add 82 */ 83 public static function getPeer($peer) { 84 self::addPeer($peer); 85 return self::$peers[$peer]; 86 } 87 88 89 /** 90 * Load a Peer 91 * 92 * You may wat to override this method if your Peers 93 * are not in the include_path. 94 * 95 * @param string $peerName the name of the Peer 96 */ 97 public static function loadPeer($peerName) 98 { 99 $peerFile = $peerName . ".php"; 100 require_once($peerFile); 101 $peerObject = new $peerName(); 102 return $peerObject; 103 } 104 105 106 /** 107 * Get a Column Constant from a Peer 108 * 109 * @param string The PhpName or DB_NAME for the constant 110 * @return string the Column Constant 111 */ 112 public static function getColumnConstant($peer, $name) 113 { 114 self::addPeer($peer); 115 $map = self::getPeer($peer)->getPhpNameMap(); 116 foreach ($map as $phpName => $dbName) { 117 if ($phpName == $name) { 118 return self::getPeerConstant($peer, $dbName); 119 } else if ($dbName == $name) { 120 return self::getPeerConstant($peer, $dbName); 121 } 122 } 123 return null; 124 } 125 126 127 /** 128 * Get the Primary Key for this Peer 129 * 130 * @param string $peer The name of the Peer 131 * @return string The name of the Primary Key 132 */ 133 public static function getPrimaryKey($peer) 134 { 135 self::addPeer($peer); 136 $tableMap = self::getTableMap($peer); 137 $columns = $tableMap->getColumns(); 138 foreach ($columns as $columnName => $column) { 139 if ($column->isPrimaryKey()) { 140 return $columnName; 141 } 142 } 143 return null; 144 } 145 146 147 /** 148 * Get the Table Map for a Peer 149 * 150 * @param string $peer The name of the Peer 151 * @return TableMap The table map for this Peer 152 */ 153 public static function getTableMap($peer) 154 { 155 self::addPeer($peer); 156 if (!self::$maps[$peer]) { 157 $tableName = self::getTableName($peer); 158 $dbMap = self::getPeer($peer)->getMapBuilder()->getDatabaseMap(); 159 self::$maps[$peer] = $dbMap->getTable($tableName); 160 } 161 return self::$maps[$peer]; 162 } 163 164 165 public static function getTableName($peer) 166 { 167 self::addPeer($peer); 168 return self::getPeerConstant($peer, "TABLE_NAME"); 169 } 170 171 172 /** 173 * Call a Method from the Static Peer Class 174 * 175 * @param string $peer The name of the Peer 176 * @param string $method The name of the method to call 177 * @param array $params The parameters to pass to the method 178 * @return mixed What ever the method returns 179 */ 180 public static function callMethod($peer, $method, $params = null) 181 { 182 if ($params !== null) { 183 return call_user_func_array(array($peer, $method), $params); 184 } 185 return call_user_func(array($peer, $method)); 186 } 187 188 } 189 190 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |