Skip to content

[7.0] Move to captcha registry#47939

Open
laoneo wants to merge 6 commits into
joomla:7.0-devfrom
Digital-Peak:captcha
Open

[7.0] Move to captcha registry#47939
laoneo wants to merge 6 commits into
joomla:7.0-devfrom
Digital-Peak:captcha

Conversation

@laoneo

@laoneo laoneo commented Jun 11, 2026

Copy link
Copy Markdown
Member
  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

Makes the final move to the captcha registry and deprecates the whole Captcha facade class.

Testing Instructions

  • Make sure the the Proof of Work captcha is enabled
  • Enable user registration and select the Proof of work captcha
  • Register a new user

Actual result BEFORE applying this Pull Request

Captcha works.

Expected result AFTER applying this Pull Request

Captcha works.

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org: Move to captcha registry Manual#664

  • No documentation changes for manual.joomla.org needed

@joomdonation

Copy link
Copy Markdown
Contributor

This should work but I think it is a bit rush to drop legacy captcha support in J7. We only have Proof of Work captcha from 6.1, and developers have no clue how new captcha plugin looks like before. I think most of captcha plugins still use legacy structure these days and will need to be re-written to be compatible with J7.

@laoneo

laoneo commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

You are right, I changed the code to fallback to the old captcha.

$this->namespace = $this->element['namespace'] ? (string) $this->element['namespace'] : $this->form->getName();

try {
$this->_captcha = Factory::getContainer()->get(CaptchaRegistry::class)->get($plugin);

@Fedik Fedik Jun 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was planned to be used kind of following:

$captcha = new Joomla\CMS\Captcha\Captcha($name, $options);
$captcha->checkAnswer(); // For validation
echo $captcha->display(); // For display

Do not access CaptchaRegistry dirrectly, please.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should then the registry be used? Looks better to use a registry from the DI container than directly creating an instance of Captcha.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can provide registry when you create new instance of the Joomla\CMS\Captcha\Captcha.

$captcha = new Joomla\CMS\Captcha\Captcha($name, [
  'registry' => $myRegistry,
]);

/** @var CaptchaRegistry $registry */
$registry = $options['registry'] ?? Factory::getContainer()->get(CaptchaRegistry::class);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to keep the Captcha class? Looks for me that it doesn't have any meaningful usage. better to drop that class completely and rely only on the registry.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we could drop it, yes.
I would like to keep it as kind of proxy, to simplify future modification when we will be need it.
Also this is much safer for b/c.

I think no need to hurry with removing it.

@laoneo laoneo Jun 15, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't hurry to remove it, all I did was to deprecate it. To use the registry, it is more inline with the rest of our code base.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean I wrote that code to work like I comented before.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your changes you introduce many unnessesary checks and try/catch.
It does not look nice.

As I understand you want to deprecate $namespace property. From what I see this property is ignored in Captcha class already.
I think you can just add deprecation comment and leave rest of the code as it was. We will remove $namespace related code in future when the property will be removed.

@laoneo laoneo added the Architecture Pull requests which improve the architecture. label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Architecture Pull requests which improve the architecture. PR-7.0-dev

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants