/** * Where statement * Limits query result using expression */ function execute() { $query = $this->getQuery(); $args = $this->getArguments(); $name = $args[0]; $section = null; if (strpos($name, '.') !== false) { list($section, $name) = explode('.', $name); } $value = null; if (isset($args[1])) { $value = $args[1]; } $query->attach(xral\Stream\Query::COMPLETE, function ($s, $e) use($name, $value, $section) { $result = $e['result']; if (!is_null($section)) { if (isset($result[$section])) { $result = new qinq\Collection([$section => $result[$section]]); } } $result->where(function ($data) use($name, $value) { if (!is_null($value)) { return array_key_exists($name, $data) && $data[$name] == $value; } else { return array_key_exists($name, $data); } }); $e['result'] = $result; }); }
/** * Finish join * @param \qinq\Object\Query\callable $callable * @return \qinq\Collection */ public function to(callable $callable) { $result = $this->computeGroupResult($callable); $query = $this->getQuery(); $collection = $this->getCollection(); if ($query instanceof qinq\Query\Immutable) { $collection = new qinq\Collection($result); } elseif ($query instanceof qinq\Query\Mutable) { $collection->from($result); } return $collection; }
function testIntegratedSearch() { $numbers = new qinq\Collection([1, 2, [3, 4, [5, 6]], 7, [8, [9, 10]]]); foreach ($numbers->search(function ($value) { return $value & 1 ? true : false; })->flatten() as $number) { $this->assertEquals(1, $number & 1); } }