Skip to content

Commit

Permalink
Implementing a way of iterating and replacing parts inside a
Browse files Browse the repository at this point in the history
QueryExpression
  • Loading branch information
lorenzo committed Mar 9, 2013
1 parent 53717fc commit 1f39853
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/Cake/Model/Datasource/Database/Expression/QueryExpression.php
Expand Up @@ -440,6 +440,28 @@ public function traverse(callable $callable) {
}
}

/**
* Executes a callable function for each of the parts that form this expression
* Callable function is required to return a value, which will the one with
* which the currently visited part will be replaced. If the callable function
* returns null then the part will be discarded completely from this expression
*
* @param callable $callable
* @return QueryExpression
*/
public function iterateParts(callable $callable) {
$parts = [];
foreach ($this->_conditions as $c) {
$part = $callable($c);
if ($part !== null) {
$parts[] = $part;
}
}
$this->_conditions = $parts;

return $this;
}

/**
* Sets the unique identifier string for this object, which is used for generating
* placeholders. If called with no arguments it will return the currently defined
Expand Down

0 comments on commit 1f39853

Please sign in to comment.