Doctrine 1.2.4
Doctrine_Lib Class Reference

Static Public Member Functions

static copyDirectory ($source, $dest)
 
static formatSql ($sql)
 
static getCollectionAsString (Doctrine_Collection $collection)
 
static getConnectionAsString (Doctrine_Connection $connection)
 
static getConnectionStateAsString ($state)
 
static getRecordAsString (Doctrine_Record $record)
 
static getRecordStateAsString ($state)
 
static getTableAsString (Doctrine_Table $table)
 
static isValidClassName ($className)
 
static makeDirectories ($path, $mode=0777)
 
static removeDirectories ($folderPath)
 

Detailed Description

Definition at line 33 of file Lib.php.

Member Function Documentation

static Doctrine_Lib::copyDirectory (   $source,
  $dest 
)
static

Copy all directory content in another one.

This method recursively copies all $source files and subdirs in $dest. If $source is a file, only it will be copied in $dest.

Parameters
string$sourcea directory path
string$desta directory path
Returns

Definition at line 338 of file Lib.php.

{
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if ( ! is_dir($dest)) {
mkdir($dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
if ($dest !== "$source/$entry") {
self::copyDirectory("$source/$entry", "$dest/$entry");
}
}
// Clean up
$dir->close();
return true;
}
static Doctrine_Lib::formatSql (   $sql)
static

Generates a colored sql query.

This methods parses a plain text query and generates the html needed for visual formatting.

Todo:
: What about creating a config varialbe for the color?
Parameters
string$sqlplain text query
Returns
string the formatted sql code

Definition at line 163 of file Lib.php.

{
$e = explode("\n",$sql);
$color = "367FAC";
$l = $sql;
$l = str_replace("SELECT ", "<font color='$color'><b>SELECT </b></font><br > ",$l);
$l = str_replace("FROM ", "<font color='$color'><b>FROM </b></font><br >",$l);
$l = str_replace(" LEFT JOIN ", "<br ><font color='$color'><b> LEFT JOIN </b></font>",$l);
$l = str_replace(" INNER JOIN ", "<br ><font color='$color'><b> INNER JOIN </b></font>",$l);
$l = str_replace(" WHERE ", "<br ><font color='$color'><b> WHERE </b></font>",$l);
$l = str_replace(" GROUP BY ", "<br ><font color='$color'><b> GROUP BY </b></font>",$l);
$l = str_replace(" HAVING ", "<br ><font color='$color'><b> HAVING </b></font>",$l);
$l = str_replace(" AS ", "<font color='$color'><b> AS </b></font><br > ",$l);
$l = str_replace(" ON ", "<font color='$color'><b> ON </b></font>",$l);
$l = str_replace(" ORDER BY ", "<font color='$color'><b> ORDER BY </b></font><br >",$l);
$l = str_replace(" LIMIT ", "<font color='$color'><b> LIMIT </b></font><br >",$l);
$l = str_replace(" OFFSET ", "<font color='$color'><b> OFFSET </b></font><br >",$l);
$l = str_replace(" ", "<dd>",$l);
return $l;
}
static Doctrine_Lib::getCollectionAsString ( Doctrine_Collection  $collection)
static

Generates a string representation of a collection.

This method returns an html dump of a collection of records, containing all data.

Parameters
Doctrine_Collection$collection
Returns
string

Definition at line 194 of file Lib.php.

{
$r[] = "<pre>";
$r[] = get_class($collection);
$r[] = 'data : ' . Doctrine_Core::dump($collection->getData(), false);
//$r[] = 'snapshot : ' . Doctrine_Core::dump($collection->getSnapshot());
$r[] = "</pre>";
return implode("\n",$r);
}
static Doctrine_Lib::getConnectionAsString ( Doctrine_Connection  $connection)
static

Generates a string representation of a connection.

This method returns an html dump of a connection, containing state, open transactions and loaded tables.

Parameters
Doctrine_Connection$connection
Returns
string

Definition at line 122 of file Lib.php.

{
$r[] = '<pre>';
$r[] = 'Doctrine_Connection object';
$r[] = 'State : ' . Doctrine_Lib::getConnectionStateAsString($connection->transaction->getState());
$r[] = 'Open Transactions : ' . $connection->transaction->getTransactionLevel();
$r[] = 'Table in memory : ' . $connection->count();
$r[] = 'Driver name : ' . $connection->getAttribute(Doctrine_Core::ATTR_DRIVER_NAME);
$r[] = "</pre>";
return implode("\n",$r)."<br>";
}
static Doctrine_Lib::getConnectionStateAsString (   $state)
static

Generates a human readable representation of a connection's state.

This method translates a Doctrine_Connection state (integer constant) in a english description.

See Also
Doctrine_Transaction::STATE_* constants
Parameters
integer$statestate of the connection as a string
Returns
string

Definition at line 98 of file Lib.php.

{
switch ($state) {
return "open";
break;
return "busy";
break;
return "active";
break;
}
}
static Doctrine_Lib::getRecordAsString ( Doctrine_Record  $record)
static

Dumps a record.

This method returns an html representation of a given record, containing keys, state and data.

Parameters
Doctrine_Record$record
Returns
string

Definition at line 75 of file Lib.php.

{
$r[] = '<pre>';
$r[] = 'Component : ' . $record->getTable()->getComponentName();
$r[] = 'ID : ' . Doctrine_Core::dump($record->identifier());
$r[] = 'References : ' . count($record->getReferences());
$r[] = 'State : ' . Doctrine_Lib::getRecordStateAsString($record->state());
$r[] = 'OID : ' . $record->getOID();
$r[] = 'data : ' . Doctrine_Core::dump($record->getData(), false);
$r[] = '</pre>';
return implode("\n",$r)."<br />";
}
static Doctrine_Lib::getRecordStateAsString (   $state)
static

Generates a human readable representation of a record's state.

This method translates a Doctrine_Record state (integer constant) in an english string.

See Also
Doctrine_Record::STATE_* constants
Parameters
integer$statethe state of record
Returns
string description of given state

Definition at line 45 of file Lib.php.

{
switch ($state) {
return "proxy";
break;
return "persistent clean";
break;
return "persistent dirty";
break;
return "transient dirty";
break;
return "transient clean";
break;
}
}
static Doctrine_Lib::getTableAsString ( Doctrine_Table  $table)
static

Generates a string representation of a table.

This method returns an html dump of a table, containing component name and table physical name.

Parameters
Doctrine_Table$table
Returns
string

Definition at line 143 of file Lib.php.

{
$r[] = "<pre>";
$r[] = "Component : ".$table->getComponentName();
$r[] = "Table : ".$table->getTableName();
$r[] = "</pre>";
return implode("\n",$r)."<br>";
}
static Doctrine_Lib::isValidClassName (   $className)
static

Checks for a valid class name for Doctrine coding standards.

This methods tests if $className is a valid class name for php syntax and for Doctrine coding standards. $className must use camel case naming and underscores for directory separation.

Parameters
string$classname
Returns
boolean

Definition at line 380 of file Lib.php.

{
if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $className)) {
return false;
}
return true;
}
static Doctrine_Lib::makeDirectories (   $path,
  $mode = 0777 
)
static

Makes the directories for a path recursively.

This method creates a given path issuing mkdir commands for all folders that do not exist yet. Equivalent to 'mkdir -p'.

Parameters
string$path
integer$modean integer (octal) chmod parameter for the created directories
Returns
boolean true if succeeded

Definition at line 282 of file Lib.php.

{
if ( ! $path) {
return false;
}
if (is_dir($path) || is_file($path)) {
return true;
}
return mkdir(trim($path), $mode, true);
}
static Doctrine_Lib::removeDirectories (   $folderPath)
static

Removes a non empty directory.

This method recursively removes a directory and all its descendants. Equivalent to 'rm -rf'.

Parameters
string$folderPath
Returns
boolean success of the operation

Definition at line 304 of file Lib.php.

{
if (is_dir($folderPath))
{
foreach (scandir($folderPath) as $value)
{
if ($value != '.' && $value != '..')
{
$value = $folderPath . "/" . $value;
if (is_dir($value)) {
self::removeDirectories($value);
} else if (is_file($value)) {
unlink($value);
}
}
}
return rmdir($folderPath);
} else {
return false;
}
}

The documentation for this class was generated from the following file: