Closed rkeet closed 5 years ago
Another solution would be to mark the strategy as not shared in the service configuration.
See shared
section in the documentation: https://docs.zendframework.com/zend-servicemanager/configuring-the-service-manager/
Well.... shit
That was a lot of hours of searching and debugging. I'd been working under the assumption that "shared" was false
by default.
Didn't know about shared_by_default
:|
Thanks though. :)
Possibly a bug, need help.
It's as if all strategies get added by reference, as such, setting the property name on the strategy, sets it for all where this same instance has been added. They all have the same object hash.
Considering the following strategy configuration for a Resource:
To have your information complete, this is the entire custom strategy:
So, when stepping through into the strategy during hydration for Countries, I expect to see that the
collectionName
of$this
(instance ofCollectionUniDirectionalToManyStrategy
), is set tocountries
, however, it is set tocurrencies
. See the debug image below for reference.This is due to how these are set in the
DoctrineHydratorFactory
, here.Following that into the Zend
ServiceManager
we find this (here):This causes that the same instance is always returned. So when later the collection name is applied to 1 of the these "set" instances, it's applied to all of them. Creating the situation in the screenshot.
The bug fix:
Clone the result from the Zend
ServiceManager
to prevent using cached instances.