本文整理汇总了PHP中Cake\ORM\Query::mapReduce方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::mapReduce方法的具体用法?PHP Query::mapReduce怎么用?PHP Query::mapReduce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Query
的用法示例。
在下文中一共展示了Query::mapReduce方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findEditable
public function findEditable(Query $query, array $options = [])
{
$mapper = function ($setting, $path, $mapReduce) {
$type = 'editable';
if ($setting->hidden == true) {
$type = 'hidden';
}
$mapReduce->emitIntermediate($setting, $type);
};
$reducer = function ($articles, $type, $mapReduce) {
$mapReduce->emit($articles, $type);
};
return $query->mapReduce($mapper, $reducer);
}
示例2: testResultsAreWrappedInMapReduce
/**
* Tests that multiple map reducers can be stacked
*
* @return void
*/
public function testResultsAreWrappedInMapReduce()
{
$table = TableRegistry::get('articles', ['table' => 'articles']);
$query = new Query($this->connection, $table);
$query->select(['a' => 'id'])->limit(2)->order(['id' => 'ASC']);
$query->mapReduce(function ($v, $k, $mr) {
$mr->emit($v['a']);
});
$query->mapReduce(function ($v, $k, $mr) {
$mr->emitIntermediate($v, $k);
}, function ($v, $k, $mr) {
$mr->emit($v[0] + 1);
});
$this->assertEquals([2, 3], iterator_to_array($query->all()));
}