Doctrine 1.2.4
Doctrine_Formatter Class Reference

Inherits Doctrine_Connection_Module.

Public Member Functions

 convertBooleans ($item)
 
 escapePattern ($text)
 
 fixIndexName ($idx)
 
 fixSequenceName ($sqn)
 
 getConnection ()
 
 getForeignKeyName ($fkey)
 
 getIndexName ($idx)
 
 getModuleName ()
 
 getSequenceName ($sqn)
 
 getTableName ($table)
 
 quote ($input, $type=null)
 
 quoteIdentifier ($str, $checkOption=true)
 
 quoteMultipleIdentifier ($arr, $checkOption=true)
 

Detailed Description

Definition at line 33 of file Formatter.php.

Member Function Documentation

Doctrine_Formatter::convertBooleans (   $item)

convertBooleans some drivers need the boolean values to be converted into integers when using DQL API

This method takes care of that conversion

Parameters
array$item
Returns
void

Definition at line 74 of file Formatter.php.

{
if (is_array($item)) {
foreach ($item as $k => $value) {
if (is_bool($value)) {
$item[$k] = (int) $value;
}
}
} else {
if (is_bool($item)) {
$item = (int) $item;
}
}
return $item;
}
Doctrine_Formatter::escapePattern (   $text)

Quotes pattern (% and _) characters in a string)

EXPERIMENTAL

WARNING: this function is experimental and may change signature at any time until labelled as non-experimental

Parameters
stringthe input string to quote
Returns
string quoted string

Definition at line 47 of file Formatter.php.

{
if ( ! $this->string_quoting['escape_pattern']) {
return $text;
}
$tmp = $this->conn->string_quoting;
$text = str_replace($tmp['escape_pattern'],
$tmp['escape_pattern'] .
$tmp['escape_pattern'], $text);
foreach ($this->wildcards as $wildcard) {
$text = str_replace($wildcard, $tmp['escape_pattern'] . $wildcard, $text);
}
return $text;
}
Doctrine_Formatter::fixIndexName (   $idx)

Removes any formatting in an index name using the 'idxname_format' option

Parameters
string$idxstring that containts name of anl index
Returns
string name of the index with possible formatting removed

Definition at line 218 of file Formatter.php.

{
$indexPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->conn->getAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT)).'$/i';
$indexName = preg_replace($indexPattern, '\\1', $idx);
if ($indexName && ! strcasecmp($idx, $this->getIndexName($indexName))) {
return $indexName;
}
return $idx;
}
Doctrine_Formatter::fixSequenceName (   $sqn)

Removes any formatting in an sequence name using the 'seqname_format' option

Parameters
string$sqnstring that containts name of a potential sequence
Returns
string name of the sequence with possible formatting removed

Definition at line 201 of file Formatter.php.

{
$seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->conn->getAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT)).'$/i';
$seqName = preg_replace($seqPattern, '\\1', $sqn);
if ($seqName && ! strcasecmp($sqn, $this->getSequenceName($seqName))) {
return $seqName;
}
return $sqn;
}
Doctrine_Connection_Module::getConnection ( )
inherited

getConnection returns the connection object this module uses

Returns
Doctrine_Connection

Definition at line 68 of file Module.php.

{
return $this->conn;
}
Doctrine_Formatter::getForeignKeyName (   $fkey)

Formatting a foreign Key name

Parameters
stringname of the foreign key
Returns
string formatted foreign key name

Definition at line 258 of file Formatter.php.

{
return sprintf($this->conn->getAttribute(Doctrine_Core::ATTR_FKNAME_FORMAT),
preg_replace('/[^a-z0-9_\$]/i', '_', $fkey));
}
Doctrine_Formatter::getIndexName (   $idx)

adds index name formatting to a index name

Parameters
stringname of the index
Returns
string formatted index name

Definition at line 246 of file Formatter.php.

{
return sprintf($this->conn->getAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT),
preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
}
Doctrine_Connection_Module::getModuleName ( )
inherited

getModuleName returns the name of this module

Returns
string the name of this module

Definition at line 79 of file Module.php.

{
return $this->moduleName;
}
Doctrine_Formatter::getSequenceName (   $sqn)

adds sequence name formatting to a sequence name

Parameters
stringname of the sequence
Returns
string formatted sequence name

Definition at line 234 of file Formatter.php.

{
return sprintf($this->conn->getAttribute(Doctrine_Core::ATTR_SEQNAME_FORMAT),
preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
}
Doctrine_Formatter::getTableName (   $table)

adds table name formatting to a table name

Parameters
stringname of the table
Returns
string formatted table name

Definition at line 270 of file Formatter.php.

{
$format = $this->conn->getAttribute(Doctrine_Core::ATTR_TBLNAME_FORMAT);
return sprintf($format, str_replace(sprintf($format, null), null, $table));
}
Doctrine_Formatter::quote (   $input,
  $type = null 
)

quote quotes given input parameter

Parameters
mixed$inputparameter to be quoted
string$type
Returns
string

Definition at line 162 of file Formatter.php.

{
if ($type == null) {
$type = gettype($input);
}
switch ($type) {
case 'integer':
case 'double':
case 'float':
case 'bool':
case 'decimal':
case 'int':
return $input;
case 'array':
case 'object':
$input = serialize($input);
case 'date':
case 'time':
case 'timestamp':
case 'string':
case 'char':
case 'varchar':
case 'text':
case 'gzip':
case 'blob':
case 'clob':
case 'enum':
case 'set':
case 'boolean':
return "'" . str_replace("'","''",$input) . "'";
}
}
Doctrine_Formatter::quoteIdentifier (   $str,
  $checkOption = true 
)

Quote a string so it can be safely used as a table or column name

Delimiting style depends on which database driver is being used.

NOTE: just because you CAN use delimited identifiers doesn't mean you SHOULD use them. In general, they end up causing way more problems than they solve.

Portability is broken by using the following characters inside delimited identifiers:

  • backtick (`) – due to MySQL
  • double quote (") – due to Oracle
  • brackets ([ or ]) – due to Access

Delimited identifiers are known to generally work correctly under the following drivers:

  • mssql
  • mysql
  • mysqli
  • oci8
  • pgsql
  • sqlite

InterBase doesn't seem to be able to use delimited identifiers via PHP 4. They work fine under PHP 5.

Parameters
string$stridentifier name to be quoted
bool$checkOptioncheck the 'quote_identifier' option
Returns
string quoted identifier string

Definition at line 122 of file Formatter.php.

{
if ($checkOption && ! $this->conn->getAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER)) {
return $str;
}
$tmp = $this->conn->identifier_quoting;
$str = str_replace($tmp['end'],
$tmp['escape'] .
$tmp['end'], $str);
return $tmp['start'] . $str . $tmp['end'];
}
Doctrine_Formatter::quoteMultipleIdentifier (   $arr,
  $checkOption = true 
)

quoteMultipleIdentifier Quotes multiple identifier strings

Parameters
array$arridentifiers array to be quoted
bool$checkOptioncheck the 'quote_identifier' option
Returns
string quoted identifier string

Definition at line 145 of file Formatter.php.

{
foreach ($arr as $k => $v) {
$arr[$k] = $this->quoteIdentifier($v, $checkOption);
}
return $arr;
}

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