Cake\ORM\Table::_setFieldMatchers PHP Method

_setFieldMatchers() protected method

This is an auxiliary function used for result formatters that can accept composite keys when comparing values.
protected _setFieldMatchers ( array $options, array $keys ) : array
$options array the original options passed to a finder
$keys array the keys to check in $options to build matchers from the associated value
return array
    protected function _setFieldMatchers($options, $keys)
    {
        foreach ($keys as $field) {
            if (!is_array($options[$field])) {
                continue;
            }
            if (count($options[$field]) === 1) {
                $options[$field] = current($options[$field]);
                continue;
            }
            $fields = $options[$field];
            $options[$field] = function ($row) use($fields) {
                $matches = [];
                foreach ($fields as $field) {
                    $matches[] = $row[$field];
                }
                return implode(';', $matches);
            };
        }
        return $options;
    }