承接 instacar/extra-filters-bundle 相关项目开发

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

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

instacar/extra-filters-bundle

Composer 安装命令:

composer require instacar/extra-filters-bundle

包简介

A Symfony bundle for Api Platform with a composable and adaptative filter

README 文档

README

A Symfony Bundle for API Platform to add a powerful filter based on Symfony Expressions, with support for virtual fields and composable filters.

Upgrading

This version is for API Platform 2.7 and 3.0 with PHP 8.1 and Symfony 6.1. If you use API Platform 2.6, PHP 7.4 or Symfony 5.4, you must use the v1 of this package.

Before you go

This is a WIP (Work-In-Progress), so you must expect breaking changes with the release of a new version. This software will try to stick with the semver conventions (trying to don't introduce backward-incompatible changes with the release of new patch version), but I don't provide support for old versions.

Scope

This bundle is NOT:

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

composer require instacar/extra-filters-bundle

That's all! You can jump right to "Configuration".

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require instacar/extra-filters-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    Instacar\ExtraFiltersBundle\InstacarExtraFiltersBundle::class => ['all' => true],
];

Configuration

By default, the ExpressionFilter enable the API Platform filters by default (excluding OrderFilter), but you can enable your own filters using updating the configuration. Example:

# config/packages/instacar_extra_filters.yml
instacar_extra_filters:
  doctrine:
    filters:
      App\Filter\CustomFilter: true

You can also disable the API Platforms filters for the ExpressionFilter setting the value of the filter to "false". Example with all the available filters:

# config/packages/instacar_extra_filters.yml
instacar_extra_filters:
  doctrine:
    filters:
      ApiPlatform\Doctrine\Orm\Filter\SearchFilter: false
      ApiPlatform\Doctrine\Orm\Filter\RangeFilter: false
      ApiPlatform\Doctrine\Orm\Filter\DateFilter: false
      ApiPlatform\Doctrine\Orm\Filter\BooleanFilter: false
      ApiPlatform\Doctrine\Orm\Filter\NumericFilter: false
      ApiPlatform\Doctrine\Orm\Filter\ExistsFilter: false

Usage

You can implement the ExpressionFilter as a normal filter for API Platform. For example:

// src/Entity/Book.php

use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Doctrine\ORM\Mapping as ORM;
use Instacar\ExtraFiltersBundle\Doctrine\Orm\Filter\ExpressionFilter;

#[ApiResource]
#[ApiFilter(ExpressionFilter::class, properties: [
    'search' => 'orWhere(search("name", "partial"), search("author.name", "partial"), search("year", "partial"))',
])]
#[ORM\Entity]
class Book {
    // real implementation
}

The expression syntax are the following:

['filter-property' => 'operator(filter1(property, strategy, value), filter2(property, strategy, value), ..., filterN(property, strategy, value))'];

Where:

  • filter-property: The property used for filter in your API. You can use a virtual property (a property that is not present in your entity).
  • operator: A supported operator.
  • filter: A supported filter.
  • property: The name of the property from the entity. You can use "property" if you want to use the same name from the filter-property.
  • strategy: The strategy from the documented values in the filter's documentation. Optional. You can use "null" for use the follow parameter.
  • value: The value passed to the filter. Optional. You can manipulate the value before pass it to the filter with this property, for example with the DateFilter you can search old dates with {before: value}.

Allowed values

  • user: Equal to the current Symfony user.
  • token: Equal to the curren Symfony security token.

Supported operators

  • andWhere: Equal to the SQL operator "AND".
  • orWhere: Equal to the SQL operator "OR".
  • notWhere: Equal to the SQL operator "NOT".

Supported filters

  • All the filters for API Platform for the ORM (currently tested SearchFilter and DateFilter).
  • Custom filters that implement the interface FilterInterface for the ORM. Note: The filter's name for the expression is in camelCase without the "Filter" suffix (for example, SearchFilter is converted to search).

Limitations

  • It only works with the ORM filters.
  • It does not generate a tailored documentation for API Platform, it only generates a generic property with the "string" value.

Future work

These are the list of the ideas that I have for this bundle. If you have another idea, let me know in the "Issues" tab.

  • Working ODM filters with this filter.

Licensing

This bundle is licensed under the GNU LGPLv3. For a quick resume of the permissions with this license see the GNU LGPLv3 in choosealicense.com.

See the LICENSE file for more details.

instacar/extra-filters-bundle 适用场景与选型建议

instacar/extra-filters-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.67k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2022 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 instacar/extra-filters-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 instacar/extra-filters-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 instacar/extra-filters-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2022-06-25