Doctrine 1.2.4
Doctrine_Expression Class Reference

Public Member Functions

 __construct ($expr, $conn=null)
 
 __toString ()
 
 getConnection ()
 
 getSql ()
 
 parseClause ($clause)
 
 parseExpression ($expr)
 
 setExpression ($clause)
 

Detailed Description

Definition at line 36 of file Expression.php.

Constructor & Destructor Documentation

Doctrine_Expression::__construct (   $expr,
  $conn = null 
)

Creates an expression.

The constructor needs the dql fragment that contains one or more dbms functions. $e = new Doctrine_Expression("CONCAT('some', 'one')");

Parameters
string$exprsql fragment
Doctrine_Connection$connthe connection (optional)

Definition at line 54 of file Expression.php.

{
if ($conn !== null) {
$this->_conn = $conn;
}
$this->_tokenizer = new Doctrine_Query_Tokenizer();
$this->setExpression($expr);
}

Member Function Documentation

Doctrine_Expression::__toString ( )

Magic method.

Returns a string representation of this object. Proxies to

See Also
getSql().
Returns
string

Definition at line 154 of file Expression.php.

{
return $this->getSql();
}
Doctrine_Expression::getConnection ( )

Retrieves the connection associated to this expression at creation, or the current connection used if it was not specified.

Returns
Doctrine_Connection The connection

Definition at line 69 of file Expression.php.

{
if ( ! isset($this->_conn)) {
}
return $this->_conn;
}
Doctrine_Expression::getSql ( )

Gets the sql fragment represented.

Returns
string

Definition at line 142 of file Expression.php.

{
return $this->_expression;
}
Doctrine_Expression::parseClause (   $clause)

Parses a set of expressions at once.

See Also
parseExpression()
Parameters
string$clauseThe clause. Can be complex and parenthesised.
Returns
string The parsed clause.

Definition at line 126 of file Expression.php.

{
$e = $this->_tokenizer->bracketExplode($clause, ' ');
foreach ($e as $k => $expr) {
$e[$k] = $this->parseExpression($expr);
}
return implode(' ', $e);
}
Doctrine_Expression::parseExpression (   $expr)

Parses a single expressions and substitutes dql abstract functions with their concrete sql counterparts for the given connection.

Parameters
string$exprThe expression to parse
Returns
string

Definition at line 99 of file Expression.php.

{
$pos = strpos($expr, '(');
$quoted = (substr($expr, 0, 1) === "'" && substr($expr, -1) === "'");
if ($pos === false || $quoted) {
return $expr;
}
// get the name of the function
$name = substr($expr, 0, $pos);
$argStr = substr($expr, ($pos + 1), -1);
// parse args
foreach ($this->_tokenizer->bracketExplode($argStr, ',') as $arg) {
$args[] = $this->parseClause($arg);
}
return call_user_func_array(array($this->getConnection()->expression, $name), $args);
}
Doctrine_Expression::setExpression (   $clause)

Sets the contained expression assuring that it is parsed. $e->setExpression("CONCAT('some', 'one')");

Parameters
string$clauseThe expression to set
Returns
void

Definition at line 87 of file Expression.php.

{
$this->_expression = $this->parseClause($clause);
}

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