gremo/captcha-form-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

gremo/captcha-form-bundle

Composer 安装命令:

composer require gremo/captcha-form-bundle

包简介

Symfony bundle that provides CAPTCHA form field and supports multiple adapters.

README 文档

README

Latest stable Downloads total

Symfony bundle that provides CAPTCHA form field to solve challenge-response tests. Supports multiple adapters as well as custom ones. Built-in adapter for:

New contributors are welcome!

Installation

composer require gremo/captcha-form-bundle

Then enable the bundle:

<?php
// config/bundles.php

return [
    // ...
    Gremo\CaptchaFormBundle\GremoCaptchaFormBundle::class => ['all' => true],
];

If you are using a previous version of Symfony:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Gremo\CaptchaFormBundle\GremoCaptchaFormBundle(),
    );
}

Configuration

gremo_captcha_form:
    # Default template, change only if you know what your are doing
    template: 'GremoCaptchaFormBundle::default.html.twig'

    # Default adapter (default to the first adapter)
    default_adapter: ~

    # Adapters (one or more) configuration
    adapters:
        # Adapter key and its options
        adapter_key1: []

        # ... and another adapter
        adapter_key2: []

In order to use the CAPTCHA form you need to configure at least one adapter (see "Adapters" section).

Usage

You can use the generic form type instead of the form provided by each adapter. This is more maintainable as you depends only on one form type.

The generic type use the default adapter and options provided in the configuration. An example usage:

// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class
use Gremo\CaptchaFormBundle\Form\Type\CaptchaType;

$builder->add('captcha', CaptchaType::class, [
    // Pass custom options to override defaults from configuration
]);

// For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string
$builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\CaptchaType', [
    // Pass custom options to override defaults from configuration
]);

// For Symfony < 2.8
$builder->add('captcha', 'gremo_captcha', [
    // Pass custom options to override defaults from configuration
]);

Adapters

At least one adapter must be configured.

Google reCAPTCHA v2 adapter

Adapter key: recaptcha Form Type: Gremo\CaptchaFormBundle\Form\Type\RecaptchaType

Add the google/recaptcha library to your project:

composer require google/recaptcha^1

Configure the adapter (options explanation):

# ...
adapters:
    # ...
    recaptcha:
        # Mandatory options
        key:              ~ # string
        secret:           ~ # string

        # Not mandatory options
        theme:            ~ # string
        type:             ~ # string
        size:             ~ # string
        tabindex:         ~ # integer
        callback:         ~ # string
        expired_callback: ~ # string

Finally, add the reCAPTCHA <script> tag to your base template:

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

Tip: add the hl parameter to the script in order to localize the CAPTCHA, i.e. in Twig hl={{ app.request.locale }}.

Example usage:

// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class
use Gremo\CaptchaFormBundle\Form\Type\RecaptchaType;

$builder->add('captcha', RecaptchaType::class, [
    // Pass custom options to override defaults from configuration
]);

// For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string
$builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\RecaptchaType', [
    // Pass custom options to override defaults from configuration
]);

// For Symfony < 2.8
$builder->add('captcha', 'gremo_captcha_recaptcha', [
    // Pass custom options to override defaults from configuration
]);

Google reCAPTCHA v3 adapter

Adapter key: recaptcha_v3 Form Type: Gremo\CaptchaFormBundle\Form\Type\RecaptchaV3Type

Add the google/recaptcha library to your project:

composer require google/recaptcha^1

Configure the adapter (options explanation):

# ...
adapters:
    # ...
    recaptcha_v3:
        # Mandatory options
        key:              ~ # string
        secret:           ~ # string

        # Not mandatory options
        score_threshold:  ~ # float

There is no need to add any <script> tag because the form theme will do it for you.

Example usage:

// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class
use Gremo\CaptchaFormBundle\Form\Type\RecaptchaV3Type;

$builder->add('captcha', RecaptchaV3Type::class, [
    // For options
]);

// For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string
$builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\RecaptchaV3Type', [
    // For options
]);

// For Symfony < 2.8
$builder->add('captcha', 'gremo_captcha_recaptcha_v3', [
    // For options
]);

Gregwar captcha adapter

Adapter key: gregwar_captcha Form Type: Gremo\CaptchaFormBundle\Form\Type\GregwarCaptchaType

Add the gregwar/recaptcha library to your project:

composer require gregwar/recaptcha^1

Configure the adapter (options explanation):

# ...
adapters:
    # ...
    gregwar_captcha:
        # Not mandatory options
        storage_key:        _gregwar_captcha
        width:              ~ # integer
        height:             ~ # integer
        quality:            ~ # integer
        font:               ~ # string
        distorsion:         ~ # boolean
        interpolation:      ~ # boolean
        ignore_all_effects: ~ # boolean
        orc:                ~ # boolean

Example usage:

// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class
use Gremo\CaptchaFormBundle\Form\Type\GregwarCaptchaType;

$builder->add('captcha', GregwarCaptchaType::class, [
    // Pass custom options to override defaults from configuration
]);

// For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string
$builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\GregwarCaptchaType', [
    // Pass custom options to override defaults from configuration
]);

// For Symfony < 2.8
$builder->add('captcha', 'gremo_captcha_gregwar', [
    // Pass custom options to override defaults from configuration
]);

Honeypot adapter

Adapter key: honeypot Form Type: Gremo\CaptchaFormBundle\Form\Type\HoneypotType

Configure the adapter:

# ...
adapters:
    # ...
    honeypot:
        # Mandatory options
        type: ~ # string, "text" or "hidden" or their FQCN (Symfony >= 2.8)

Example usage:

// For Symfony >= 2.8 and PHP >= 5.5 use the class name resolution via ::class
use Gremo\CaptchaFormBundle\Form\Type\HoneypotType;

$builder->add('captcha', HoneypotType::class, [
    // Pass custom options to override defaults from configuration
]);

// For Symfony >= 2.8 and PHP < 5.5 use the fully-qualified class name as string
$builder->add('captcha', 'Gremo\CaptchaFormBundle\Form\Type\HoneypotType', [
    // Pass custom options to override defaults from configuration
]);

// For Symfony < 2.8
$builder->add('captcha', 'gremo_captcha_honeypot', [
    // Pass custom options to override defaults from configuration
]);

gremo/captcha-form-bundle 适用场景与选型建议

gremo/captcha-form-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.07k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「recaptcha」 「spam」 「captcha」 「bot」 「Abuse」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 gremo/captcha-form-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: ISC
  • 更新时间: 2016-02-28