承接 bermudaphp/filter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bermudaphp/filter

最新稳定版本:v1.0

Composer 安装命令:

composer require bermudaphp/filter

包简介

README 文档

README

This library provides a robust and extensible set of filters to process and filter iterable data sources in PHP. Its design follows a consistent interface that makes it easy to apply custom filtering logic to collections (arrays, Traversable, etc.). With immutable filter instances and a fluent API, you can chain and compose filters to build complex filtering rules easily.

Features

Flexible Filtering Interface: The library defines a common FilterInterface that extends both \IteratorAggregate and Arrayable, so you can directly iterate over filtered results and convert them to arrays.

Abstract Base Class: The AbstractFilter class implements most of the common functionality, including a generator-based iterator (getIterator()) and an immutable withIterable() method for setting the data source.

Wide Range of Built-in Filters: The library includes filters for various use cases, including:

Value-based Filters: EqualsFilter, NotEqualsFilter, EmptyFilter, NotEmptyFilter, StringEqualsFilter, and many more.

Numeric Filters: GreaterThanFilter, LessThanFilter, GreaterThanEqualsFilter, LessThanEqualsFilter, as well as range filters.

Array Filters: Filters using PHP’s built-in functions such as array_intersect, array_diff, etc.

Key-based Filters: Filters that compare only the element's key (e.g., KeyIntersectFilter, KeyContainsFilter, KeyRegexFilter, etc.).

Object Property Filters: e.g. PropertyExistsFilter.

Composite Filters: Easily combine multiple filters using a composite pattern (e.g., ChanableFilter).

Easy to Extend: Creating a custom filter is as simple as extending the AbstractFilter class and implementing the accept() method.

Installation

composer require bermudaphp/filter

Usage

$nonFiltered = [1, 2, 3, null, 4, 5, null, 6, 7, 8, 9, new StdClass];

        $filter = new OneOfFilter([
            new ChainableFilter([
                new NumericFilter(),
                new EvenNumberFilter,
            ]),
            new ObjectFilter()
        ], $nonFiltered);

        dd($filter->toArray());

^ array:5 [▼
  0 => 2
  1 => 4
  2 => 6
  3 => 8
  4 => {#356}
]

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-05