. */ /** * @package Doctrine ORM * @url www.phpdoctrine.com * @license LGPL * * Doctrine_Lib has not commonly used static functions, mostly for debugging purposes */ class Doctrine_Lib { /** * @param integer $state the state of record * @see Doctrine_Record::STATE_* constants * @return string string representation of given state */ public static function getRecordStateAsString($state) { switch($state): case Doctrine_Record::STATE_PROXY: return "proxy"; break; case Doctrine_Record::STATE_CLEAN: return "persistent clean"; break; case Doctrine_Record::STATE_DIRTY: return "persistent dirty"; break; case Doctrine_Record::STATE_TDIRTY: return "transient dirty"; break; case Doctrine_Record::STATE_TCLEAN: return "transient clean"; break; endswitch; } /** * returns a string representation of Doctrine_Record object * @param Doctrine_Record $record * @return string */ public static function getRecordAsString(Doctrine_Record $record) { $r[] = "
"; $r[] = "Component : ".$record->getTable()->getComponentName(); $r[] = "ID : ".$record->obtainIdentifier(); $r[] = "References : ".count($record->getReferences()); $r[] = "State : ".Doctrine_Lib::getRecordStateAsString($record->getState()); $r[] = "OID : ".$record->getOID(); $r[] = ""; return implode("\n",$r)."
"; $r[] = "Doctrine_Connection object"; $r[] = "State : ".Doctrine_Lib::getConnectionStateAsString($connection->getState()); $r[] = "Open Transactions : ".$connection->getTransactionLevel(); $r[] = "Open Factories : ".$connection->count(); $sum = 0; $rsum = 0; $csum = 0; foreach($connection->getTables() as $objTable) { if($objTable->getCache() instanceof Doctrine_Cache_File) { $sum += array_sum($objTable->getCache()->getStats()); $rsum += $objTable->getRepository()->count(); $csum += $objTable->getCache()->count(); } } $r[] = "Cache Hits : ".$sum." hits "; $r[] = "Cache : ".$csum." objects "; $r[] = "Repositories : ".$rsum." objects "; $queries = false; if($connection->getDBH() instanceof Doctrine_DB) { $handler = "Doctrine Database Handler"; $queries = count($connection->getDBH()->getQueries()); $sum = array_sum($connection->getDBH()->getExecTimes()); } elseif($connection->getDBH() instanceof PDO) { $handler = "PHP Native PDO Driver"; } else $handler = "Unknown Database Handler"; $r[] = "DB Handler : ".$handler; if($queries) { $r[] = "Executed Queries : ".$queries; $r[] = "Sum of Exec Times : ".$sum; } $r[] = ""; return implode("\n",$r)."
"; $r[] = "Component : ".$table->getComponentName(); $r[] = "Table : ".$table->getTableName(); $r[] = ""; return implode("\n",$r)."
"; $r[] = get_class($collection); foreach($collection as $key => $record) { $r[] = "Key : ".$key." ID : ".$record->obtainIdentifier(); } $r[] = ""; return implode("\n",$r); } }