芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/vendor/yiisoft/yii2-debug/src/components/search/Filter.php
* @since 2.0 */ class Filter extends Component { /** * @var array rules for matching filters in the way: [:fieldName => [rule1, rule2,..]] */ protected $rules = []; /** * Adds data filtering rule. * * @param string $name attribute name * @param MatcherInterface $rule */ public function addMatcher($name, MatcherInterface $rule) { if ($rule->hasValue()) { $this->rules[$name][] = $rule; } } /** * Applies filter on a given array and returns filtered data. * * @param array $data data to filter * @return array filtered data */ public function filter(array $data) { $filtered = []; foreach ($data as $row) { if ($this->passesFilter($row)) { $filtered[] = $row; } } return $filtered; } /** * Checks if the given data satisfies filters. * * @param array $row data * @return bool if data passed filtering */ private function passesFilter(array $row) { foreach ($row as $name => $value) { if (isset($this->rules[$name])) { // check all rules for a given attribute foreach ($this->rules[$name] as $rule) { /* @var $rule MatcherInterface */ if (!$rule->match($value)) { return false; } } } } return true; } }