Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

aledeg
Copy link
Member

@aledeg aledeg commented Sep 30, 2025

Changes proposed in this pull request:

  • add an enum to handle hook types (enum are available since PHP 8.1)
  • change hook calls from string value to enum value

How to test the feature manually:

  1. load extensions
  2. validate they are working the same way

Pull request checklist:

  • clear commit messages
  • code manually tested
  • unit tests written (optional if too hard)
  • documentation updated

Additional information can be found in the documentation.

@aledeg aledeg requested a review from Alkarex September 30, 2025 12:24
@Alkarex Alkarex added this to the 1.28.0 milestone Sep 30, 2025
@aledeg
Copy link
Member Author

aledeg commented Sep 30, 2025

@Alkarex I think this could improve our code by removing manual validation of the hook type strings. Do you think it's worth continuing the work on that?

I was thinking about #7110 and how we could accommodate such changes and I though this might be the first step toward that.

What do you think?


/** @var string|null $urlHooked */
$urlHooked = Minz_ExtensionManager::callHook('check_url_before_add', $url);
$urlHooked = Minz_ExtensionManager::callHook(Minz_HookType::CheckUrlBeforeAdd->value, $url);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$urlHooked = Minz_ExtensionManager::callHook(Minz_HookType::CheckUrlBeforeAdd->value, $url);
$urlHooked = Minz_ExtensionManager::callHook(Minz_HookType::CheckUrlBeforeAdd, $url);

Suggestion, and for all similar calls. Requires function signature update. See below

Copy link
Member Author

Choose a reason for hiding this comment

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

That was my ultimate goal. But I did not want to spend too much time if this was not the way to follow.

* @param mixed ...$args additional parameters (for signature, please see Minz_HookType enum).
* @return mixed|void|null final result of the called hook.
*/
public static function callHook(string $hook_name, ...$args) {
Copy link
Member

@Alkarex Alkarex Sep 30, 2025

Choose a reason for hiding this comment

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

Suggested change
public static function callHook(string $hook_name, ...$args) {
public static function callHook(Minz_HookType|string $hook_name, ...$args) {
if ($hook_name instanceof Minz_HookType) {
$hook_name = $hook_name->value;
}

@Alkarex
Copy link
Member

Alkarex commented Sep 30, 2025

I think that looks like a good step 👍🏻
After that, I think we should offer a strong-typed version of the calls and deprecate the callHook(string, ...mixed): mixed approach.

@aledeg
Copy link
Member Author

aledeg commented Sep 30, 2025

Thank you for your input.

I'll continue in that direction and I'll polish this PR.

@aledeg aledeg force-pushed the extension/add-hooks-enum branch 4 times, most recently from 185c841 to cf7a4bb Compare September 30, 2025 16:56
Change hard-coded string values to enums. This will allow a more robust
code and a better understanding of the hook processes.
@aledeg aledeg changed the title Replace hook type strings by hook type enum Add hook enums Sep 30, 2025
@aledeg aledeg marked this pull request as ready for review September 30, 2025 17:01
@aledeg
Copy link
Member Author

aledeg commented Sep 30, 2025

@Alkarex Whenever you have time!

@aledeg
Copy link
Member Author

aledeg commented Sep 30, 2025

@Alkarex Should I sign my commits? This will rewrite the history though.

@Alkarex
Copy link
Member

Alkarex commented Sep 30, 2025

Should I sign my commits? This will rewrite the history though.

No need for this one, but would be nice for future ones

@Alkarex Alkarex merged commit 7288481 into FreshRSS:edge Sep 30, 2025
1 check passed
@aledeg aledeg deleted the extension/add-hooks-enum branch September 30, 2025 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants