dms/dms-filter-bundle
Composer 安装命令:
composer require dms/dms-filter-bundle
包简介
DMS Filter Bundle, makes Annotation based entity filtering available in Symfony
README 文档
README
This bundle makes DMS/Filter available for use in your application for input filtering.
Install
1. Import libraries
Option A) Use Composer.
composer require dms/dms-filter-bundle
2. Enable Bundle
Add this to your config/bundles.php
DMS\Bundle\FilterBundle\DMSFilterBundle::class => ['all' => true]
3. Configure
This bundle can now automatically filter your forms if it finds a annotated entity attached.
This is the default behaviour, if you want to disable it add this to your config.yml
dms_filter:
auto_filter_forms: false
Usage
Adding Annotations
To add attributes to your entity, import the namespace and add them like this:
<?php namespace App\Entity; //Import Attributes use DMS\Filter\Rules as Filter; class User { #[Filter\StripTags] #[Filter\Trim] #[Filter\StripNewlines] public string $name; #[Filter\StripTags] #[Filter\Trim] #[Filter\StripNewlines] public string $email; }
Manual Filtering
Use the dms.filter.inner.filter service along with attributes in the Entity to filter data.
public function userAction(#[Autowire(service: 'dms.filter.inner.filter')] Filter $filter): Response { $user = new User(); $user->setName("My <b>name</b>"); $user->setEmail(" email@mail.com"); //Get a Filter $newUser = $filter->filterEntity($car); return new Response( $newUser->getModel() ); }
Auto filtering
This bundle can now automatically filter your forms if it finds a annotated entity attached. If enabled entities will be filtered before they are validated.
Cascade Filtering
This Bundle automatically cascades filtering into all embedded forms that return valid entities. If you wish child
entities to be ignored, set the cascade_filter option on the form to false.
class TaskType extends AbstractType { // ... public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'cascade_filter' => false, )); } // ... }
Service based method
If you need to filter content using a method in a service, you do not need to create your own Annotations, you can simply use the Service Filter, designed specifically for Symfony Services.
See below the usage example of the annotation, it takes 2 options: service and method.
<?php namespace App\Entity; //Import Atributes use DMS\Filter\Rules as Filter; //Import Symfony Rules use DMS\Bundle\FilterBundle\Rule as SfFilter; class User { #[Filter\StripTags] #[SfFilter\Service(service: 'dms.sample', method: 'filterIt')] public $name; }
The filterIt method can have any name, but it must take one paramter (the value) and return the filtered value.
Compatibility
This is compatible with Symfony 6.4 and above and PHP 8.2 and above
Contributing
Given you have composer, cloned the project repository and have a terminal open on it:
composer.phar install --prefer-source --dev
vendor/bin/phpunit
vendor/bin/phpcs
The tests should be passing and you are ready to make contributions.
dms/dms-filter-bundle 适用场景与选型建议
dms/dms-filter-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 355.65k 次下载、GitHub Stars 达 78, 最近一次更新时间为 2012 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「filter」 「dms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dms/dms-filter-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dms/dms-filter-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dms/dms-filter-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nova searchable filter for belongsTo relationships.
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
Symfony DataGridBundle
统计信息
- 总下载量: 355.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 79
- 点击次数: 33
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-01-27