Bug #31179
injectSettings is called more than once for object instantiation
Status: | Resolved | Start date: | 2011-10-21 | |
---|---|---|---|---|
Priority: | Must have | Due date: | ||
Assigned To: | Christian Müller | % Done: | 100% |
|
Category: | Configuration | |||
Target version: | TYPO3 Flow Base Distribution - 1.1 RC2 | |||
PHP Version: | Complexity: | |||
Has patch: | No | Affected Flow version: | FLOW3 1.0.0 |
Description
When defining injectSettings
in a class, one expects it to be called once per instantiation. In fact it is called as often as the class hierarchy is deep, i.e. when StandardController extends AbstractController extends ActionController the injectSettings
method of StandardController will be called three times.
Associated revisions
[BUGFIX] Injections only on last level of class hierarchy
Property injections are no longer called for every level of your
class hierarchy, which means they are only executed once now.
Change-Id: I5f7dd422b3d7fb5004b3e4a887ec64da59c57c84
Fixes: #31179
Releases: 1.0, 1.1, 1.2
[BUGFIX] Injections only on last level of class hierarchy
Property injections are no longer called for every level of your
class hierarchy, which means they are only executed once now.
Change-Id: I5f7dd422b3d7fb5004b3e4a887ec64da59c57c84
Fixes: #31179
Releases: 1.0, 1.1, 1.2
[BUGFIX] Injections only on last level of class hierarchy
Property injections are no longer called for every level of your
class hierarchy, which means they are only executed once now.
Change-Id: I5f7dd422b3d7fb5004b3e4a887ec64da59c57c84
Fixes: #31179
Releases: 1.0, 1.1, 1.2
History
#1 Updated by Fernando Arconada almost 4 years ago
It is called as many times as classes in your class hierachy with different settings array
#2 Updated by Karsten Dambekalns almost 4 years ago
- Project changed from TYPO3 Flow Base Distribution to TYPO3.Flow
- Status changed from New to Accepted
- Assigned To set to Karsten Dambekalns
PoC code at http://pastebin.com/0nDS7nsN
#3 Updated by Karsten Dambekalns almost 4 years ago
- Category set to Configuration
- Has patch set to No
#4 Updated by Karsten Dambekalns almost 4 years ago
- Status changed from Accepted to Needs Feedback
parent::injectSettings
, three calls are made:
- the call to the implementation in StandardController, it get's the settings for your package injected
- the call to the implementation in your AbstractController, resulting from parent::injectSettings, again, your settings injected
- the call to the implementation in FLOW3's AbstractController, resulting from parent::injectSettings, this time with the FLOW3 settings injected
Solution: in "your topmost class", never call parent::injectSettings
...
#5 Updated by Fernando Arconada almost 4 years ago
note: the "echo" is called three times and should be called once.
#6 Updated by Karsten Dambekalns almost 4 years ago
Hi Fernando.
Fernando Arconada wrote:
note: the "echo" is called three times and should be called once.
On my way home I already had that thought gnawing at me: "probably BS you wrote there...". Of course you are right. The three calls I laid out would be correct, but of course only in one the echo
is contained. Anyway, the problem is caused by __construct
being called multiple times in the inheritance chain, and each is calling injectProperties
which then calls injectSettings
...
#7 Updated by Karsten Dambekalns almost 4 years ago
- File injectSettings__call_1.jpg added
- File injectSettings__call_2.jpg added
- File injectSettings__call_3.png added
- Status changed from Needs Feedback to Accepted
#8 Updated by Karsten Dambekalns almost 4 years ago
- Subject changed from override injectSettings doesnt resolve your package settings to injectSettings is called more than once for object instantiation
The cause of this is the way calls to injectSettings
are woven into injectProperties
, which is called in every __construct
method of the built proxies. Since each of them calls the implementation furthest down the inheritance chain, the calls add up, but with varying input, depending on the caller.
On the originally reported problem: Fernando, I changed the description from your original
If you try to override injectSettings($settings) in your controller, for example to map settings to class properties... It doesnt resolve your package settings. $settings is loaded with FLOW3 settings
In the last call the settings of your package will arrive in injectSettings
, so all should work as expected. If needed add some safeguards, e.g. to avoid access to some array indexes not defined in early calls. Of course the behavior needs to be fixed, but if your expected settings do not appear at all, take a look at the Settings.yaml
to make sure everything is correct there.
#9 Updated by Christian Müller about 3 years ago
- Assigned To changed from Karsten Dambekalns to Christian Müller
I just ran into this too and will see if this is to be solved somehow. Would be great for https://review.typo3.org/#/c/11283
#10 Updated by Gerrit Code Review about 3 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11432
#11 Updated by Gerrit Code Review about 3 years ago
Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11432
#12 Updated by Gerrit Code Review about 3 years ago
Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11432
#13 Updated by Karsten Dambekalns about 3 years ago
- Target version set to 1.1
#14 Updated by Gerrit Code Review about 3 years ago
Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11432
#15 Updated by Gerrit Code Review about 3 years ago
Patch set 5 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11432
#16 Updated by Gerrit Code Review about 3 years ago
Patch set 6 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11432
#17 Updated by Gerrit Code Review about 3 years ago
Patch set 7 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11432
#18 Updated by Gerrit Code Review about 3 years ago
Patch set 1 for branch FLOW3-1.1 has been pushed to the review server.
It is available at http://review.typo3.org/12814
#19 Updated by Gerrit Code Review about 3 years ago
Patch set 1 for branch FLOW3-1.0 has been pushed to the review server.
It is available at http://review.typo3.org/12815
#20 Updated by Christian Müller about 3 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset f9330b400d4fe8cac7e486becef043a9f82e1dca.
#21 Updated by Karsten Dambekalns about 3 years ago
- Target version changed from 1.1 to 1.1 RC2
#22 Updated by Gerrit Code Review about 3 years ago
- Status changed from Resolved to Under Review
Patch set 2 for branch FLOW3-1.1 has been pushed to the review server.
It is available at http://review.typo3.org/12814
#23 Updated by Karsten Dambekalns about 3 years ago
- Status changed from Under Review to Resolved