Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Fixed FormAnnotationBuilderFactory::injectFactory() for zend-servicemanager v2 #235

Conversation

weierophinney
Copy link
Member

The patch introduced for 2.7.11 was incorrect in that it was passing the $container argument, and not the $formElementManager argument, to $formElementManager->injectFactory(). This patch updates it to use the correct value, and fixes the related test expectation as well.

cc @boesing

…emanager v2

The patch introduced for 2.7.11 was incorrect in that it was passing the
`$container` argument, and not the `$formElementManager` argument, to
`$formElementManager->injectFactory()`. This patch updates it to use the
correct value, and fixes the related test expectation as well.
@weierophinney
Copy link
Member Author

@boesing — You can test this as follows.

  1. Add a repositories entry for my fork to your composer.json:

    "repositories": [
         { "type": "vcs", "url": "https://github.com/weierophinney/zend-mvc" }
     ]
  2. Add the following require statement in composer.json:

    "zendframework/zend-mvc": "dev-hotfix/annotation-builder as 2.7.12",
  3. Run composer update zenframework/zend-mvc

Let me know if this works for you.

@weierophinney weierophinney added this to the 2.7.12 milestone Apr 27, 2017
@boesing
Copy link
Member

boesing commented Apr 27, 2017

This works for me. Thanks a lot! I am still confused about that self injecting FormElementManager.

@@ -96,7 +96,7 @@ private function injectFactory(
AnnotationBuilder $annotationBuilder
) {
if ($formElementManager instanceof FormElementManagerV2Polyfill) {
$formElementManager->injectFactory($annotationBuilder, $container);
$formElementManager->injectFactory($annotationBuilder, $formElementManager);
Copy link
Member

Choose a reason for hiding this comment

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

Why would the formElementManager inject itself? I still dont get the meaning of this.

Copy link
Member

Choose a reason for hiding this comment

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

The v3 implementation is therefore passing the real container.
You totally irritated me on this now 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a difference in how plugin managers work between version 2 and version 3.

In version 2, plugin managers pass themselves as the $container/$serviceLocator argument to factories and initiailizers. The idea at the time was to keep the plugin managers scoped; they would know nothing about the application-level services. However, we quickly realized this was problematic: most of the time, particularly with custom plugins, you need to access application-level services, such as the database connection, repositories, etc. So we made the plugin managers ServiceLocatorAware, so they would be injected with the parent (application) plugin manager, allowing plugin factories and initializers access to those services.

When we refactored the component for v3, we took this into consideration, and decided that plugin managers should be injected with the parent "context" (usually the application-level service manager), and that the parent context should be passed to plugin factories and initializers. This reduces the amount of boilerplate necessary for the vast majority of these classes, as it addresses the most typical use case.

Obviously, however, that has also meant some interesting migration issues when trying to provide both forwards compatibility with v3 implementations, and backwards compatibility with v2. You just stumbled upon one of the worst. 😁

Copy link
Member

@boesing boesing Apr 27, 2017

Choose a reason for hiding this comment

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

When we refactored the component for v3, we took this into consideration, and decided that plugin managers should be injected with the parent "context" (usually the application-level service manager), and that the parent context should be passed to plugin factories and initializers. This reduces the amount of boilerplate necessary for the vast majority of these classes, as it addresses the most typical use case.

Makes sense, I dont think that anyone wants create another Controller in a ControllerFactory 😁.

Thanks for your patience and for those great insights of what was changed, e.g.

@weierophinney weierophinney merged commit bc09e87 into zendframework:release-2.7 Apr 27, 2017
weierophinney added a commit that referenced this pull request Apr 27, 2017
- What you did
@weierophinney weierophinney deleted the hotfix/annotation-builder branch April 27, 2017 15:44
@weierophinney
Copy link
Member Author

Released as 2.7.12.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants