yamilovs/color-captcha-bundle
A Symfony bundle that adds a color-based CAPTCHA to your forms. Users select colors to prove they are human, providing a lightweight, visually intuitive alternative to traditional text captchas. Simple to install and configure.
This is a Symfony bundle that wraps the yamilovs/color-captcha image generator (a “pick/name the color” CAPTCHA) and exposes it as a route + form type + validator. Treat it as legacy code: last release was January 2019, zero dependents, and it targets the Symfony 3.4/4.x era. Verify everything you read below against the actual package on install — class names and service IDs should be confirmed, not assumed.
Minimal path to a working captcha:
composer require yamilovs/color-captcha-bundle
Then:
new Yamilovs\ColorCaptchaBundle\ColorCaptchaBundle() in AppKernel::registerBundles(). In 4.2+: add it to config/bundles.php. Confirm the real namespace with composer show yamilovs/color-captcha-bundle — the vendor prefix may be Yamilovs\Bundle\....bin/console debug:router | grep -i captcha to find the name). Import with the pre-Symfony-5 @ColorCaptchaBundle/Resources/config/routing.xml notation, or copy the route definition into your own config/routes.yaml — you will likely have to do the latter on modern Symfony.php -m | grep -i gd first; a missing extension is the single most common “blank captcha” cause.color_captcha: key (key name to be confirmed from the bundle’s DependencyInjection/Configuration.php): width/height, color palette, background, and font if applicable.ColorCaptchaType) to your FormType, render form_row(), and let the bundled constraint validate the submitted value against the session-stored answer.Before writing any code, read vendor/yamilovs/color-captcha-bundle/ in this order: DependencyInjection/Configuration.php → Resources/config/services.* → Form/ → Validator/ → Controller/. That’s the whole bundle; it’s small enough to read end-to-end in fifteen minutes, which is exactly what you should do given how little documentation survives.
Form-type integration (the happy path). The package is designed around a Symfony form type plus a validator constraint. You add the field, Symfony renders the <img> pointing at the bundle route, the user answers, and the constraint compares the submission to the value cached in the session. This is the only pattern with any real chance of working out of the box on an old Symfony install.
Manual controller integration. For login forms or non-form flows, point an <img src="{{ path('...captcha_route') }}"> at the bundle route and validate the POST manually — pull the expected answer from the session yourself, or reuse the constraint through $this->validator->validate($value, new ColorCaptcha()) if the constraint is standalone. This is useful when you can’t use Symfony Forms (e.g. a hand-rolled login).
Refresh-on-click. The image URL is stateless from the browser’s point of view, but the answer lives in the session. Add a cache-busting query string (?t= + timestamp) on a “reload” button so the browser re-fetches and the session answer regenerates. Don’t rely on Cache-Control alone.
Per-form configuration. Instantiate the form type with options (palette, dimensions) rather than relying on global config, so a compact login captcha and a larger registration captcha can coexist. This requires the generator service to accept runtime overrides — check whether the bundle’s service is shared: false or factory-built; if it isn’t, you’ll need to define your own service definition.
Test environment bypass. Add an env check in the validator (or swap the constraint for a no-op via a service override in config/services_test.yaml) so functional tests and CI don’t need to OCR an image. Because the answer is session-backed, tests can also seed the session with the expected value directly — cleaner than disabling validation.
Swapping the generator. The bundle is a thin adapter over yamilovs/color-captcha. If you keep this package long-term, decorate or replace the generator service with your own implementation of the library’s interface — that’s the cleanest extension point and it isolates you from future (or abandoned) releases.
@Bundle/Resources/... notation (removed in 5.0), removed Symfony\Component\HttpKernel\Bundle\Bundle helpers, and PHP 8 issues (dynamic properties, each(), implicit nullable params). Budget for forking or vendoring rather than assuming composer require just works.<?php, or a debug toolbar injecting output), or headers overwritten. Test the image route directly in a browser before blaming the form.Cache-Control: no-store, no-cache, must-revalidate and consider a nonce in the URL.bin/console debug:router | grep -i captcha, bin/console debug:container | grep -i captcha, and bin/console debug:config color_captcha (if the extension is registered) will reveal the actual service IDs and route names far faster than reading stale docs. Enable twig debug and inspect the rendered <img src>.services.yaml, (3) override the bundle’s templates by placing files under templates/bundles/ColorCaptchaBundle/. Avoid patching vendor/ directly — use composer.json repositories with a VCS fork, or cweagans/composer-patches if you need a one-line fix.yamilovs/color-captcha and write ~50 lines of Symfony glue yourself — you’ll own the code, control the Symfony version compatibility, and avoid a dead bundle in your dependency tree.How can I help you explore Laravel packages today?