Skip to content
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

!!!TASK: Bootstrap instantiates request handlers internally #3371

Open
wants to merge 1 commit into
base: 9.0
Choose a base branch
from

Conversation

kitsunet
Copy link
Member

@kitsunet kitsunet commented Jun 22, 2024

It seems unnecessarily complex to have code register a request handler as build instance. Instead it is now registered by class name. The Flow Bootstrap will then create instances while determining the best matching request handler. To facilitate this being lazy the RequestHandlerInterface::getPriority method is now declared static so that we can decide beforehand if the priority is higher than any previously found best match.
Depending on possibly request handlers and specifically in all preselected cases this all reduces the amount of created objects and possibly the amount of canHandle calls. A microptimization but which affects all requests. Primary concern was to make registration easier and internalize instantiation.

As small simplification the
Bootstrap->setPreselectedRequestHandlerClassName will also register the given class name as possible request handler removing one step.

This is breaking if you have your own request handler implementation. The getPrioritty method needs to declare an int return type and must be static. Additionally the registration happens via Bootstrap->registerRequestHandlerClassName(YourRequestHandler::class).
Also the RequestHandler now needs a static constructor
RequestHandlerInterface::fromBootstrap(Bootstrap $bootstrap): self that the Bootstrap will call when instantiating one.

If the RequestHandler for some reason was used as a bridge to the outside world and the instance carried more information besides the bootstrap, you can "sneak in" your instance with anything you want by setting it via
Bootstrap->setEarlyInstance(YourRequestHandler::class, $yourInstance) and this will be used instead of creating a new instance via the static constructor. You still need to register the class as possible request handler though.

@kitsunet kitsunet requested a review from mhsdesign June 22, 2024 22:06
@github-actions github-actions bot added the 9.0 label Jun 22, 2024
@kitsunet kitsunet force-pushed the task/90-bootstrap-requesthandler branch from de760a5 to 6c611a6 Compare June 22, 2024 22:09
@kitsunet
Copy link
Member Author

kitsunet commented Jun 22, 2024

This cannot ever be green on CI as the necessary changes to the BuildEssentials (register/preselect testing request handlers) are a hard block in either direction, whichever comes first breaks it.

So you would have to run tests locally or trust me and we fix anything that comes up after....

Copy link
Member

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

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

thanks for this ;) We also stumbled upon this complexity for the neos/setup part ... this change does make things easier. Though we do have to live with the fact that the 6.0.0 tag of neos/setup will not be compatible with Flow 9.0 anymore which it is currently and tagged: https://github.com/neos/setup/blob/ecd193d814aea502aad71b0907f193de08fc9d0d/composer.json#L8 (im stupid sorry lol).

Neos.Flow/Classes/Core/Bootstrap.php Outdated Show resolved Hide resolved
It seems unnecessarily complex to have code register a request handler
as build instance. Instead it is now registered by class name.
The Flow Bootstrap will then create instances while determining the
best matching request handler. To facilitate this being lazy the
RequestHandlerInterface::getPriority method is now declared static so
that we can decide beforehand if the priority is higher than any
previously found best match.
Depending on possibly request handlers and specifically in all preselected
cases this all reduces the amount of created objects and possibly the
amount of canHandle calls. A microptimization but which affects all
requests. Primary concern was to make registration easier and internalize
instantiation.

As small simplification the
`Bootstrap->setPreselectedRequestHandlerClassName` will also register
the given class name as possible request handler removing one step.

This is breaking if you have your own request handler implementation.
The `getPrioritty` method needs to declare an `int` return type and
must be static. Additionally the registration happens via
`Bootstrap->registerRequestHandlerClassName(YourRequestHandler::class)`.
@kitsunet kitsunet force-pushed the task/90-bootstrap-requesthandler branch from 6c611a6 to ae54ccd Compare June 23, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants