arnaud-ritti/mosparo-bundle
Composer 安装命令:
composer require arnaud-ritti/mosparo-bundle
包简介
A Symfony bundle for mosparo spam protection
README 文档
README
Symfony Bundle
This bundle adds the required functionality to use mosparo in your Symfony form.
Description
With this PHP library you can connect to a mosparo installation and verify the submitted data.
Requirements
To use the plugin, you must meet the following requirements:
- A mosparo project
- Symfony 5.4 or greater
- PHP 8.0 or greater
Installation
Install this bundle by using composer:
composer require arnaud-ritti/mosparo-bundle
Configuration
1. Register the bundle
Register bundle into config/bundles.php:
return [ //... Mosparo\MosparoBundle\MosparoBundle::class => ['all' => true], ];
2. Add configuration files
Setup bundle's config into config/packages/mosparo.yaml:
mosparo: instance_url: '%env(MOSPARO_INSTANCE_URL)%' uuid: '%env(MOSPARO_UUID)%' public_key: '%env(MOSPARO_PUBLIC_KEY)%' private_key: '%env(MOSPARO_PRIVATE_KEY)%'
Add your variables to your .env file:
###> mosparo/mosparo-bundle ###
MOSPARO_INSTANCE_URL=https://example.com
MOSPARO_UUID=<your-project-uuid>
MOSPARO_PUBLIC_KEY=<your-project-public-key>
MOSPARO_PRIVATE_KEY=<your-project-private-key>
###< mosparo/mosparo-bundle ###
Handle multiples configurations
Into your configuration file. ex: config/packages/mosparo.yaml:
mosparo: default_project: '%env(MOSPARO_DEFAULT)%' projects: forms: instance_url: '%env(MOSPARO_FORMS_INSTANCE_URL)%' uuid: '%env(MOSPARO_FORMS_UUID)%' public_key: '%env(MOSPARO_FORMS_PUBLIC_KEY)%' private_key: '%env(MOSPARO_FORMS_PRIVATE_KEY)%' login: instance_url: '%env(MOSPARO_LOGIN_INSTANCE_URL)%' uuid: '%env(MOSPARO_LOGIN_UUID)%' public_key: '%env(MOSPARO_LOGIN_PUBLIC_KEY)%' private_key: '%env(MOSPARO_LOGIN_PRIVATE_KEY)%'
Inside your .env files
###> mosparo/mosparo-bundle ###
MOSPARO_DEFAULT=<your-default-config>
MOSPARO_FORMS_INSTANCE_URL=<your-forms-project-instance>
MOSPARO_FORMS_UUID=<your-forms-project-uuid>
MOSPARO_FORMS_PUBLIC_KEY=<your-forms-project-public-key>
MOSPARO_FORMS_PRIVATE_KEY=<your-forms-project-private-key>
MOSPARO_LOGIN_INSTANCE_URL=<your-login-project-instance>
MOSPARO_LOGIN_UUID=<your-login-project-uuid>
MOSPARO_LOGIN_PUBLIC_KEY=<your-login-project-public-key>
MOSPARO_LOGIN_PRIVATE_KEY=<your-login-project-private-key>
###< mosparo/mosparo-bundle ###
Usage
How to integrate mosparo in Symfony form:
<?php use Mosparo\MosparoBundle\Form\Type\MosparoType; class TaskType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('mosparo', MosparoType::class, [ 'project' => 'default', 'allowBrowserValidation' => false, 'cssResourceUrl' => '', 'designMode' => false, 'inputFieldSelector' => '[name]:not(.mosparo__ignored-field)', 'loadCssResource' => true, 'requestSubmitTokenOnInit' => true, ]); } }
Additional options
| Parameter | Type | Default value | Description |
|---|---|---|---|
project |
String | default |
Defines the mosparo project to use for validation. See Handle multiples configurations |
allowBrowserValidation |
Boolean | false | Specifies whether browser validation should be active. |
cssResourceUrl |
String | empty | Defines the address at which the browser can load the CSS resources. You can use it if the correct resource address is cached. |
designMode |
Boolean | false | Used to display the mosparo box in the different states in the mosparo backend. The mosparo box is not functional if this option is set to true. |
inputFieldSelector |
String | [name]:not(.mosparo__ignored-field) |
Defines the selector with which the fields are searched. |
loadCssResource |
Boolean | true | Determines whether the script should also load the CSS resources during initialization. |
requestSubmitTokenOnInit |
Boolean | true |
Specifies whether a submit token should be automatically requested during initialization. If, for example, the form is reset directly after initialization (with reset()), there is no need for a submit token during initialization, as a new code is requested with the reset. |
Ignored fields
Automatically ignored fields
mosparo automatically ignores the following fields:
- All fields which do not have a name (attribute
name) - HTML field type
- password
- file
- hidden
- checkbox
- radio
- submit
- reset
- HTML button type
- submit
- button
- Fields containing
_mosparo_in the name
Manually ignored fields
CSS class
If you give a form field the CSS class mosparo__ignored-field, the field will not be processed by mosparo.
JavaScript initialisation
When initializing the JavaScript functionality, you can define the selector with which the fields are searched (see Parameters of the mosparo field).
Override allowed and verifiable field types
You can also register event listeners (or subscribers) to add or remove field types.
We use here a listener for example.
// src/EventListener/FilterFieldTypesListener.php namespace App\EventListener; use Mosparo\MosparoBundle\Event\FilterFieldTypesEvent; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; #[AsEventListener] class FilterFieldTypesListener { public function __invoke(FilterFieldTypesEvent $event): FilterFieldTypesEvent { // Remove PasswordType from the ignored list $event->setIgnoredFieldTypes(array_diff( $event->getIgnoredFieldTypes(), [ PasswordType::class ] )); // Add PasswordType to the verifiable list $event->setVerifiableFieldTypes(array_merge( $event->getVerifiableFieldTypes(), [ PasswordType::class ] )); return $event; } }
How to deal with functional and e2e testing:
Mosparo won't allow you to test your app efficiently unless you disable it for the environment you are testing against.
# config/packages/mosparo.yaml mosparo: enabled: '%env(bool:MOSPARO_ENABLED)%'
#.env.test or an environment variable
MOSPARO_ENABLED=0
How to disable SSL verification:
In order to support invalid SSL certificats you will need to disable the SSL check.
# config/packages/mosparo.yaml mosparo: ... verify_ssl: '%env(bool:MOSPARO_VERIFY_SSL)%'
#.env or an environment variable
MOSPARO_VERIFY_SSL=0
For multiples configurations:
# config/packages/mosparo.yaml mosparo: projects: forms: ... verify_ssl: '%env(bool:MOSPARO_FORMS_VERIFY_SSL)%' login: ... verify_ssl: '%env(bool:MOSPARO_LOGIN_VERIFY_SSL)%'
#.env or an environment variable
MOSPARO_FORMS_VERIFY_SSL=0
MOSPARO_LOGIN_VERIFY_SSL=0
License
mosparo is open-sourced software licensed under the MIT License. Please see the LICENSE file for the full license.
Contributing
See CONTRIBUTING
arnaud-ritti/mosparo-bundle 适用场景与选型建议
arnaud-ritti/mosparo-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.45k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2023 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「recaptcha」 「spam protection」 「mosparo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arnaud-ritti/mosparo-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arnaud-ritti/mosparo-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arnaud-ritti/mosparo-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple captcha generator
reCAPTCHA library
The bundle for easy using json-rpc api on your project
Client library for reCAPTCHA with proxy support, a free service that protects websites from spam and abuse.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A simple and easy to use Google ReCaptcha v3 package for Laravel
统计信息
- 总下载量: 1.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-29