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

Comprehensive fix for BC breaks introduced since 2.7.1 #67

Merged
merged 3 commits into from
May 1, 2016

Conversation

weierophinney
Copy link
Member

This patch:

Essentially, two principal issues were identified:

  • Invokable classes need to use the new ElementFactory to ensure they are instantiated correctly. Unfortunately, due to the fact that the "auto add invokables" flag is enabled, and that users can call setInvokableClass() or define invokables configuration, any such mappings were leading to the classes getting the base zend-servicemanager behavior instead. This patch solves that by creating polyfill solutions for zend-servicemanager v2 and v3 releases, and overriding the setInvokableClass() implementations under each to ensure they map invokables to the specialized factory and set any needed aliases. (These polyfills also ensure that the version-specific instantiation rules are present.)
  • 2.7.1 specifically broke usage of Zend\Form\Factory when using collections, which fetch their target "element" when it's set via options. The break was due to a change in Zend\Form\Factory::create(), which was passing discovered options to FormElementManager::get(). This led to an order-of-operations issue, as the options were then processed during instantiation, when previously they were processed afterwards, ensuring all setter injections were already complete. The erroneous code was removed.

weierophinney and others added 3 commits May 1, 2016 14:17
- Created `FormElementManager` subcomponent:
  - `FormElementManagerTrait` contains most common logic between v2 and v3, such
    as determining factory based on name, hydrator based on name, overriding
    get(), etc.
  - Distinct `FormElementManager` implementations for zend-servicemanager v2 and
    v3, providing definitions for all services (which cannot be done in a trait,
    as traits cannot override properties from inherited classes),
    version-specific constructors, version-specific initializers, and
    version-specific overrides for `setInvokableClass()`
  - Added polyfill via an autoloader script, which aliases `FormElementManager`
    to the servicemanager version-specific implementation.
- Added tests to ensure behavior works as expected with regards to invokable
  class initialization.
- `AnnotationBuilderFactory` was using v3 signature for `injectFactory()`
  initializer, which causes it to fail under v2. Inlined that logic into the
  factory, which changes some mocking expectations, but not the behavior.
This patch removes the change introduced in 2.7.1's
`Zend\Form\Factory::create()` method that aggregated options and passed
them to the `FormElementManager::get()` call. This usage was incorrect,
as it creates an order-of-operations problem: most instances call their
own `setOptions()` method from the constructor if options are present,
and many of the actions this executes assume things like a populated
`FormElementManager`, using a default instance if none is found!

As such, reverting those changes to pre-2.7.1 usage fixes the issues
reported in zendframework#66. Since the changes were done under an erroneous
assumption, a test related to the incorrect functionality was also
removed.
@weierophinney weierophinney added this to the 2.8.2 milestone May 1, 2016
@weierophinney weierophinney self-assigned this May 1, 2016
@weierophinney weierophinney merged commit 8660a5d into zendframework:master May 1, 2016
weierophinney added a commit that referenced this pull request May 1, 2016
weierophinney added a commit that referenced this pull request May 1, 2016
weierophinney added a commit that referenced this pull request May 1, 2016
@weierophinney weierophinney deleted the hotfix/invokables branch May 1, 2016 19:36
weierophinney added a commit to weierophinney/zend-form that referenced this pull request May 1, 2016
Test is passing, indicating that the fix presented in zendframework#67 fixed this behavior as
well.
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