Skip to content

Add action and condition shorthands to simplify the configuration #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sebastianfeldmann
Copy link
Collaborator

@sebastianfeldmann sebastianfeldmann commented Jul 25, 2025

Over the last couple of versions I tried to slim the minimal required configuration down a bit.

But for internal features the action configuration still feels a bit messy.

I want to move from

{
    "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Beams"
}

To this

{
    "action": "CaptainHook.Message.MustFollowBeamsRules",
}

Similarly for the internal Conditions.

What do you think? Unnecessary or cool feature?
Feedback welcome :)

@heiglandreas
Copy link
Contributor

Nice feature!

But:
Why? To use that new feature I have to know the "simplified" shorthand. Unless there is a user-readable registry that has the shorthand connected with my specific class, I will have to check Shorthand::$map constantly. And keeping that in sync with the code is an accident waiting to happen as the mapping is a manual process in a different file.

I would probably see things slightly differently when the shorthand would somehow be extracted from the fully qualified class name so that the FQCN and the shorthand van be converted into one another by a ruleset rather than a mapping.

Or when the shorthand would be defined in the respective class e.g. via a getShorthand method.

In both cases the shorthand documentation could be automatically generated without forgetting a manual process when introducing the next rule.

Also:

Why

{
    "action": "CaptainHook.Message.MustFollowBeamsRules",
}

and not

{
    "action": "CaptainHook.App.Hook.Message.Action.Beams"
}

Kind of the same as now but without the clunky backslashes...

Just my 0.02€

@sebastianfeldmann
Copy link
Collaborator Author

Very good points, especially the manual sync and how to find the shorthand.

I would update the documentation and all the examples to mainly include the shorthands, but you are right, if you don't want to look it up and see the class file it's kind of annoying to check the Shorthand::$map for clues :/

If we add the shorthand to the class, an idea that I like, how do we find the class efficiently without instantiating all the classes, on the other hand I don't want people to think they can add shorthands to their Actions and it magically works ;)

Do you think adding something like that to every Action and Condition class would "solve" or at least partially mitigate the issue?

/**
 * Example configuration:
 *
 * "action": "some-action"
 * "conditions": [
 *   {"exec": "CaptainHook.Config.CustomValueIsFalsy",
 *    "args": [
 *      "NAME_OF_CUSTOM_VALUE"
 *    ]}
 * ]

Regarding CaptainHook.App.Hook.Message.Action.Beams

Honestly my intend was to create a disconnect between namespace and shorthand, so I can move namespaces around without worrying too much. Since they are a kind of implementation detail I'm exposing right now.
And now I have to live with my bad naming ... for ever and ever :/

@sebastianfeldmann
Copy link
Collaborator Author

This is how an example configuration would look in our favorite IDE ;)

Bildschirmfoto 2025-07-25 um 20 38 20

@sebastianfeldmann sebastianfeldmann force-pushed the feature/config-shorthands branch from 330e984 to 92b3e0f Compare July 26, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants