@param array $data   Data to filter
@param mixed $filter Filter options

@return array
970149
public static function filter(array $data, $filter): array
    {
        if (!$filter) {
            return $data;
        }

        if (is_callable($filter)) {
            return array_filter($data, $filter);
        }

        if ($filter & self::FILTER_NULL) {
            return array_filter(
                $data,
                function ($value) {
                    return $value !== null;
                }
            );
        } elseif ($filter & self::FILTER_EMPTY) {
            return array_filter(
                $data,
                function ($value) {
                    return isset($value[0]);
                }
            );
        } elseif ($filter & self::FILTER_PHP) {
            return array_filter($data);
        }

        return $data;
    }
1166107
public function getData(array $arr, $filter = null)
    {
        $data = [];
        foreach ($arr as $val) {
            $data[$val] = $this->body->{$val};
            if ($filter) {
                $data[$val] = Filter::factory($data[$val], $filter);
            }
        }
        return $data;
    }
567914
static function GetData($name, $filter = FILTER_DEFAULT, $options = null)
    {
        return filter_input(INPUT_GET, $name, $filter, $options);
    }
798276
private function doFilter(TokenFilterInterface $filter, array $tokens): array
    {
        $result = [];
        foreach ($tokens as $token) {
            $result = array_merge($result, $filter->filter($token));
        }

        return $result;
    }
104607
private function scrub($data, $filter = DEFAULT_FILTER, array $options = [])
    {
        //To filter a large array;
        if (is_array($data)) {
            $definedOptions = array_intersect_key($data, $options);
            if (count($data) == count($definedOptions)) {
                return $this->filterArray($data, $options);
            } else {
                $sanitized = [];
                foreach ($data as $key => $variable) {
                    $type = gettype($variable);

                    switch ($type) {
                        case "integer":
                            $sanitized[$key] = $this->int($variable);
                            break;
                        case "float":
                        case "double":
                            $sanitized[$key] = $this->float($variable);
                            break;
                        case "string":
                            $sanitized[$key] = $this->string($variable);
                            break;
                        case "object": //@TODO maybe serialize?,
                        case "resource":
                            //there is not much to be done with objects;
                            //maybe should come up with a way to check how safe they are;
                            $this->sanitized = true;
                            $sanitized[$key] = $variable;
                            break;
                        case "NULL":
                        case "unknown type":
                        default:
                            $sanitized[$key] = $this->filter($variable, static::FILTER_RAW, $options);
                            break;
                    }
                }

                return $sanitized;
            }
        }

        //bitwise disjunction of flags
        $options['flags'] = implode("|", $options['flags']);

        return $this->filter($data, $filter, $options);
    }
373679
public function getParamsWith($filter)
    {
        // Convert $filter to array if necessary
        if (!is_array($filter)) {
            $filter = preg_split("/, */", $filter, -1, PREG_SPLIT_NO_EMPTY);
        }

        $params = $this->getParams();
        $filter = array_flip($filter);

        return array_intersect_key($params, $filter);
    }
1048110
public static function validateSerialized($data, callable $filter=null) {
        $decoded = @unserialize($data);
        if ( $decoded === false && $data != @serialize(false) ) return false;
        return self::applyFilter($data, $filter);
    }
166744
public function find($filter = null)
    {
        if (is_string($filter)) {
            json_decode($filter);
            $isJson = (json_last_error() === JSON_ERROR_NONE) ? true :false;
            if ($isJson) {
                $filter = new Filter($filter);
                return $this->_getObjectsByFilter($filter);
            } else {
                return $this->_getObject($filter);
            }
        } else if (is_object($filter) && $filter instanceof Filter) {
            return $this->_getObjectsByFilter($filter);
        }
        return [];
    }
412717
public static function getItems($filter = []): array
    {
        $res = [];

        /* @var $class LightModel */
        $className = get_called_class();
        $class = new $className;

        $sql = 'SELECT * FROM ' . $class->getTableName() . ' WHERE 1=1';
        $params = self::handleFilter($sql, $filter, $class);

        $query = DB::getConnection()->prepare($sql);
        $query->execute($params);

        foreach ($query->fetchAll(PDO::FETCH_CLASS, $className) as $item)
        {
            $res[] = self::typeCastModel($item);
        }

        return $res;
    }
118830
public function filter(array $data)
    {
        $filtered = [];

        foreach ($data as $row) {
            if ($this->passesFilter($row)) {
                $filtered[] = $row;
            }
        }

        return $filtered;
    }
353087
private function applyFilter(Filter $filter)
    {
        list($filtered, $errors) = $filter->apply($this->value);
        if (count($errors) === 0) {
            return $filtered;
        }

        foreach ($errors as $error) {
            $this->paramErrors->append($this->paramName, $error);
        }

        return null;
    }
413827
private function getParamsFromFilter(FilterBuilder $filter)
    {
        $result  = [];
        $must    = [];
        $mustNot = [];

        $params = $filter->getParams();

        if ($params['entities']) {
            $result['index'] = $params['entities'];
        }

        if (isset($params['keyword'])) {
            $must[] = new MultiMatchQuery($params['keyword']['value'], $params['keyword']['fields']);
        }

        foreach ($params['params'] ?? [] as $param) {
            list($query, $operator) = $param->createFilter();

            if ($operator == FilterOperators::IN) {
                $must[] = $query;
            } else {
                $mustNot[] = $query;
            }

        }

        if ($mustNot || $must) {

            $query = new QueryBuilder();
            if ($mustNot) {
                $query->setMustNot(new MustNotQuery($mustNot));
            }
            if ($must) {
                $query->setMust(new MustQuery($must));
            }

            $result['query'] = $query->toArray();
        }

        return $result;
    }
310584
protected function filterFields(array $data): array
    {
        $fields = $this->getFilterFields();

        if ($fields === null) {
            return $data;
        }

        return array_intersect_key(
            $data,
            array_flip(
                iterator_to_array($fields)
            )
        );
    }
346059
public static function filterByString($filter)
    {
        $operator = Arr::get($filter, 'operator');
        $method = Arr::get($filter, 'method');
        $arguments = Arr::get($filter, 'arguments');
        $value_one = Arr::get($filter, 'value_one');
        $value_two = Arr::get($filter, 'value_two');
        $settings = Arr::get($filter, 'settings');
        $positive = Arr::get($filter, 'positive');

        switch ($operator) {
            case '=':
            case '!=':
                $arguments = [$operator, $value_one];
                break;
            case '*=*':
            case '*!=*':
                $operator = (stripos($operator, '!') !== false) ? 'not ' : '';
                $operator .= 'like';
                $arguments = [$operator, '%'.$value_one.'%'];
                break;
            case '*=':
            case '*!=':
                $operator = (stripos($operator, '!') !== false) ? 'not ' : '';
                $operator .= 'like';
                $arguments = [$operator, '%'.$value_one];
                break;
            case '=*':
            case '!=*':
                $operator = (stripos($operator, '!') !== false) ? 'not ' : '';
                $operator .= 'like';
                $arguments = [$operator, $value_one.'%'];
                break;
            case 'EMPTY':
                $method = 'whereRaw';
                $arguments = "%s = ''";
                break;
            case 'NOT_EMPTY':
                $method = 'whereRaw';
                $arguments = "%s != ''";
                break;
            case 'IN':
                $method = 'whereIn';
                $arguments = [static::getListFromString($value_one)];
                break;
            case 'NOT_IN':
                $method = 'whereNotIn';
                $arguments = [static::getListFromString($value_one)];
                break;
            case 'NULL':
                $method = 'whereNull';
                break;
            case 'NOT_NULL':
                $method = 'whereNotNull';
                break;
        }

        return [
            'operator'  => $operator,
            'method'    => $method,
            'arguments' => $arguments,
            'value_one' => $value_one,
            'value_two' => $value_two,
            'settings'  => $settings,
            'positive'  => $positive,
        ];
    }
979909
public static function getOptionValues($filter = array())
    {
        $filter = Filter::create($filter);
        return self::getCollection('/options/values' . $filter->toQuery(), 'OptionValue');
    }
194624
public function toArray(
        array $columns = [],
        $filter = null
    ): array {
        $data = [];
        foreach ($this as $key => $item) {
            $data[$key] = $item;
        }
        unset($data['_keyMap']);
        if (!empty($this->_keyMap)) {
            foreach ($this->_keyMap as $beanKey => $dataKey) {
                if (array_key_exists($beanKey, $data)) {
                    $data[$dataKey] = $data[$beanKey];
                    unset($data[$beanKey]);
                }
            }
        }

        empty($columns) || $data = array_intersect_key(
            $data,
            array_flip($columns)
        );
        if ($filter === static::FILTER_NOT_NULL) {
            return array_filter($data, function ($val) {
                return !is_null($val);
            });
        } else if ($filter === static::FILTER_NOT_EMPTY) {
            return array_filter($data, function ($val) {
                if ($val === 0 || $val === '0') {
                    return true;
                } else {
                    return !empty($val);
                }
            });
        } else if (is_callable($filter)) {
            return array_filter($data, $filter);
        }
        return $data;
    }
885536
protected function selfToArray(Array $filter = array())
    {
        $filter = array_flip($filter);
        $hasFilter = count($filter) > 0;
        $values = array();
        foreach ($this as $key => $value) {
            if (!$hasFilter || isset($filter[$key])) {
                $values[$key] = $this->$key;
            }
        }
        return $values;
    }