switon / captcha
Sessionless image CAPTCHA challenges with shared-store verification for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- psr/event-dispatcher: ^1.0
- switon/binding: ^1.0
- switon/core: ^1.0
- switon/event: ^1.0
- switon/http: ^1.0
- switon/invocation: ^1.0
- switon/redis: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
Suggests
- ext-gd: Required for GD adapter (fallback)
- ext-imagick: Required for ImageMagick adapter (preferred)
README
Switon's CAPTCHA challenge, proof, and action-guard layer.
Highlights
- Challenge and verification flow: generate a CAPTCHA, then verify the returned proof.
- Standard request fields:
CaptchaProofResolverreads the usual CAPTCHA key and code fields. - Protected actions:
#[CaptchaRequired]blocks an action until proof is valid. - Image backends: the package includes GD and Imagick adapters for image generation.
- Observable checks: creation, verification, and failure activity can be observed.
Installation
composer require switon/captcha
Quick Start
use Switon\Captcha\CaptchaInterface; use Switon\Captcha\Attribute\CaptchaRequired; use Switon\Captcha\CaptchaProof; use Switon\Core\Attribute\Autowired; class LoginController { #[Autowired] protected CaptchaInterface $captcha; public function getCaptcha(): array { return $this->captcha->create(); } public function verifyAction(CaptchaProof $proof): void { $this->captcha->verify($proof); } #[CaptchaRequired] public function submitAction(): void { } }
Docs: https://docs.switon.dev/latest/captcha
License
MIT.