/**
* Build and execute a flow query chain
*
* @param array $chain
* @return void
*/
public function flowQueryAction(array $chain)
{
$createContext = array_shift($chain);
$finisher = array_pop($chain);
$flowQuery = new FlowQuery(array_map(function ($envelope) {
return $this->nodeService->getNodeFromContextPath($envelope['$node']);
}, $createContext['payload']));
foreach ($chain as $operation) {
$flowQuery = call_user_func_array([$flowQuery, strtolower($operation['type'])], $operation['payload']);
}
if ('GET' === $finisher['type']) {
$result = $flowQuery->get();
}
$nodeInfoHelper = new NodeInfoHelper();
return json_encode($nodeInfoHelper->renderNodes($result, $this->getControllerContext()));
}