-
Notifications
You must be signed in to change notification settings - Fork 384
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
Implement dependency resolution for services #6484
Conversation
Plugin builds for 953a039 are ready 🛎️!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, but I defer to @schlessera for his final word.
codecov: | ||
notify: | ||
# Wait for Jest & PHPUnit $ Behat reports before notifying | ||
after_n_builds: 3 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this no longer needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov waits for all 3 coverage reports before posting the summary for the PR; problem is that we are now skipping some PR checks which means it's no longer guaranteed 3 coverage reports will be uploaded, so Codecov will be waiting for reports that it will potentially never receive.
src/Admin/PairedBrowsing.php
Outdated
/** | ||
* Get the list of service IDs required for this service to be registered. | ||
* | ||
* @return array<string> List of required services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means the same thing, but any reason for/against?
* @return array<string> List of required services. | |
* @return string[] List of required services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either works, just a little copypasta 😄.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll commit the suggestion since it's what's more prominent in the codebase.
/* | ||
* Move the service to the end of the array. | ||
* | ||
* Note: Unsetting the key advances the internal array pointer to the next array item, so | ||
* the current array item will have to be temporarily stored so that it can be re-added later. | ||
*/ | ||
$delayed_service = [ key( $services ) => current( $services ) ]; | ||
unset( $services[ key( $services ) ] ); | ||
$services[ key( $delayed_service ) ] = current( $delayed_service ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever!
Co-authored-by: Weston Ruter <[email protected]>
Any objections to copy this for the Web Stories plugin? :-) |
None at all 😄. |
…ssing requirements
@pierlon I made changes to this to add a more robust mechanism to deal with the load order. Please review these changes and let me know your thoughts. |
@schlessera Thanks for making those changes. I've reviewed and tested the updates regarding delayed services and it works as expected 👍. |
Co-authored-by: Pierre Gordon <[email protected]> Co-authored-by: Alain Schlesser <[email protected]>
Summary
Fixes #6459
This PR implements a simple way for services to resolve their dependent services so that it is guaranteed that those services exist before retrieving them from the service container.
In order to accomplish this, the
AmpProject\AmpWP\Infrastructure\ServiceBasedPlugin::register_services()
method has been modified to check if a service implements theAmpProject\AmpWP\Infrastructure\HasRequirements
interface, and if it does, it then retrieves the list of service identifiers it requires in order for the service to be registered. If any of the required service IDs do not exist in the service container, the registration of the service will be delayed (moved to the end of the to-be-registered services list) to allow for other services to be registered in the mean time.Testing
To test that this fixes #6459:
Checklist