Bug #31179

injectSettings is called more than once for object instantiation

Added by Fernando Arconada almost 4 years ago. Updated about 3 years ago.

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.

injectSettings__call_1.jpg (459.4 kB) Karsten Dambekalns, 2011-10-24 21:38

injectSettings__call_2.jpg (450 kB) Karsten Dambekalns, 2011-10-24 21:38

injectSettings__call_3.png (421.7 kB) Karsten Dambekalns, 2011-10-24 21:38

Associated revisions

Revision f9330b40
Added by Christian Müller about 3 years ago

[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

Revision 5a6703dc
Added by Christian Müller about 3 years ago

[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

Revision 9ca9ac54
Added by Christian Müller about 3 years ago

[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

#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
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 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

#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

#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

Also available in: Atom PDF