Bug #31179

injectSettings is called more than once for object instantiation

Added by Fernando Arconada about 9 years ago. Updated over 8 years ago.

Status:
Resolved
Priority:
Must have
Category:
Configuration
Start date:
2011-10-21
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

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.


Files

injectSettings__call_1.jpg (459 KB) injectSettings__call_1.jpg Karsten Dambekalns, 2011-10-24 21:38
injectSettings__call_2.jpg (450 KB) injectSettings__call_2.jpg Karsten Dambekalns, 2011-10-24 21:38
injectSettings__call_3.png (422 KB) injectSettings__call_3.png Karsten Dambekalns, 2011-10-24 21:38
#1

Updated by Fernando Arconada about 9 years ago

It is called as many times as classes in your class hierachy with different settings array

#2

Updated by Karsten Dambekalns about 9 years ago

  • Project changed from TYPO3 Flow Base Distribution to TYPO3.Flow
  • Status changed from New to Accepted
  • Assignee set to Karsten Dambekalns
#3

Updated by Karsten Dambekalns about 9 years ago

  • Category set to Configuration
  • Has patch set to No
#4

Updated by Karsten Dambekalns about 9 years ago

  • Status changed from Accepted to Needs Feedback
All correct... Since you call parent::injectSettings, three calls are made:
  1. the call to the implementation in StandardController, it get's the settings for your package injected
  2. the call to the implementation in your AbstractController, resulting from parent::injectSettings, again, your settings injected
  3. 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 about 9 years ago

note: the "echo" is called three times and should be called once.

#6

Updated by Karsten Dambekalns about 9 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...

#8

Updated by Karsten Dambekalns about 9 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 over 8 years ago

  • Assignee 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 over 8 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 over 8 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 over 8 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 over 8 years ago

  • Target version set to 1.1
#14

Updated by Gerrit Code Review over 8 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 over 8 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 over 8 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 over 8 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 over 8 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 over 8 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 over 8 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#21

Updated by Karsten Dambekalns over 8 years ago

  • Target version changed from 1.1 to 1.1 RC2
#22

Updated by Gerrit Code Review over 8 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 over 8 years ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF