mcaskill / charcoal-recaptcha
Google reCAPTCHA for Charcoal.
Installs: 1 904
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.0 || >=7.0
- google/recaptcha: ^1.1
- locomotivemtl/charcoal-config: ~0.8
- pimple/pimple: ^3.0
- psr/http-message: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.7 || ^6.5
- slim/slim: ^3.4
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-22 02:40:35 UTC
README
A Charcoal service provider for the Google reCAPTCHA client Library.
This package can be used as a PSR-7 middleware or as an object in your service layer.
Installation
composer require mcaskill/charcoal-recaptcha
See composer.json
for depenencides.
What's inside?
Charcoal\ReCaptcha\CaptchaServiceProvider
: Pimple service provider.Charcoal\ReCaptcha\CaptchaConfig
: Configuring the CAPTCHA service.Charcoal\ReCaptcha\CaptchaAwareTrait
: Convenient trait for interfacing with the CAPTCHA service.Charcoal\ReCaptcha\Captcha
: Service that handles the reCAPTCHA client.Charcoal\ReCaptcha\LocalizedCaptcha
: Translator-aware variant of the service.
Usage
use Charcoal\ReCaptcha\Captcha; $captcha = new Captcha([ 'config' => [ 'public_key' => '…', 'private_key' => '…', ] ]); // As middleware $app->post('/signup', '…')->add($captcha); // As standalone, with direct user input $captcha->verify($input, $ip); // With a PSR-7 request $captcha->verifyRequest($request); // Display the widget in your views echo $captcha->display( [ 'data-theme' => 'dark', 'data-type' => 'audio', ], [ 'hl' => 'fr' ] );
By default, the Captcha
adapter will defer the instantiation of ReCaptcha
until the first verification request.
Custom ReCaptcha Class
The ReCaptcha
class be swapped using the client_class
option.
use Charcoal\ReCaptcha\Captcha; use MyApp\ MyCustomReCaptcha; $captcha = new Captcha([ 'config' => [ 'public_key' => '…', 'private_key' => '…', ], 'client_class' => MyCustomReCaptcha::class ]);
Custom ReCaptcha Instance
An instance of the ReCaptcha
class can be assigned using the client
option.
use Charcoal\ReCaptcha\Captcha; use ReCaptcha\ReCaptcha; use ReCaptcha\RequestMethod\CurlPost; $client = new ReCaptcha('…', new CurlPost()); $captcha = new Captcha([ 'config' => [ 'public_key' => '…', 'private_key' => '…', ], 'client' => $client ]);
Service Provider
If CaptchaServiceProvider
is used, the following are provided.
Parameters
- charcoal/captcha/config: An instance of
CaptchaConfig
.
Services
- charcoal/captcha: An instance of
Captcha
.
Registering
Via Charcoal configuration file:
{ "apis": { "google": { "recaptcha": { "public_key": "…", "private_key": "…" } }, }, "service_providers": { "charcoal/re-captcha/captcha": {} } }
Via PHP:
$container->register(new Charcoal\ReCaptcha\CaptchaServiceProvider(), [ 'charcoal/captcha/config' => [ 'public_key' => '…', 'private_key' => '…' ] ]);
Acknowledgements
This package is inspired by: