public static function buildCondition($criteria, $concat = " && ")
{
$fn = array();
foreach ($criteria as $key => $value) {
switch ($key) {
case '$and':
$_fn = array();
foreach ($value as $v) {
$_fn[] = '(' . self::buildCondition($v, ' && ') . ')';
}
$fn[] = implode(' || ', $_fn);
break;
case '$or':
$_fn = array();
foreach ($value as $v) {
$_fn[] = '(' . self::buildCondition($v, ' || ') . ')';
}
$fn[] = implode(' || ', $_fn);
break;
default:
$d = '$document';
if (strpos($key, ".") !== false) {
$keys = explode('.', $key);
foreach ($keys as $k) {
$d .= '["' . $k . '"]';
}
} else {
$d .= '["' . $key . '"]';
}
$fn[] = is_array($value) ? "\\MongoLite\\UtilArrayQuery::check((isset({$d}) ? {$d} : null), " . var_export($value, true) . ")" : "(isset({$d}) && {$d}==" . (is_string($value) ? "'{$value}'" : var_export($value, true)) . ")";
}
}
return count($fn) ? trim(implode($concat, $fn)) : 'true';
}