protected function createFilterEvaluator($chainSource, Closure $predicate, EntityMetadata $sourceEntityMetaSource, $targetValue)
{
$evaluator = function ($element, $chain = null, EntityMetadata $sourceEntityMeta = null) use(&$evaluator, $predicate, $chainSource, $sourceEntityMetaSource, $targetValue) {
if (!$chain) {
$sourceEntityMeta = $sourceEntityMetaSource;
$chain = $chainSource;
}
$column = array_shift($chain);
$propertyMeta = $sourceEntityMeta->getProperty($column);
// check if property exists
$value = $element->hasValue($column) ? $element->getValue($column) : null;
if (!$chain) {
if ($column === 'id' && count($sourceEntityMeta->getPrimaryKey()) > 1 && !isset($targetValue[0][0])) {
$targetValue = [$targetValue];
}
return $predicate($this->normalizeValue($value, $propertyMeta), $this->normalizeValue($targetValue, $propertyMeta));
}
$targetEntityMeta = $this->metadataStorage->get($propertyMeta->relationship->entity);
if ($value === null) {
return false;
} elseif ($value instanceof IRelationshipCollection) {
foreach ($value as $node) {
if ($evaluator($node, $chain, $targetEntityMeta)) {
return true;
}
}
return false;
} else {
return $evaluator($value, $chain, $targetEntityMeta);
}
};
return $evaluator;
}