Skip to content
Permalink
Browse files

Adding more docs and making it possible to get the stack of map-reducers

  • Loading branch information...
lorenzo committed Aug 20, 2013
1 parent 813e22a commit f97e490e1e4be258e40b192b3c5b7610ecf9c745
Showing with 29 additions and 1 deletion.
  1. +29 −1 lib/Cake/ORM/Query.php
@@ -526,14 +526,42 @@ public function applyOptions(array $options) {
return $this;
}
/**
* Register a new MapReduce routine to be executed on top of the database results
* Both the mapper and caller callable should be invokable objects.
*
* The MapReduce routing will only be ran when the query is executed and the first
* result is attempted to be fetched.
*
* If the first argument is set to null, it will return the list of previously
* registered map reduce routines.
*
* If the third argument is set to true, it will erase previous map reducers
* and replace it with the arguments passed.
*
* @param callable $mapper
* @param callable $reducer
* @param boolean $overwrite
* @return Cake\ORM\Query|array
*/
public function mapReduce(callable $mapper = null, callable $reducer = null, $overwrite = false) {
if ($overwrite) {
$this->_mapReduce = [];
}
$this->_mapReduce[] = compact('mapper', 'reducer');
if ($mapper === null) {
return $this->_mapReduce;
}
$this->_mapReduce[] = array_filter(compact('mapper', 'reducer'));
return $this;
}
/**
* Decorates the ResultSet iterator with MapReduce routines
*
* @param $results Cake\ORM\ResultCollectionTrait original results
* @return Cake\ORM\ResultCollectionTrait
*/
protected function _applyFormatters($result) {
foreach ($this->_mapReduce as $mappers) {
$result = new MapReduce($result, $mappers);

0 comments on commit f97e490

Please sign in to comment.
You can’t perform that action at this time.