Bug #67274
closed
initializeObject() called before dependency injection
Added by Morton Jonuschat about 9 years ago.
Updated almost 7 years ago.
Sprint Focus:
Stabilization Sprint
Description
Given typical extbase controller actions:
public function listAction() {
$records = $this->modelRepository->findAll();
$this->view->assign('records', $records);
}
public function showAction(Model $model) {
$this->view->assign('model', $model);
}
The method initializeObject() on the Models is called before the dependency injection has been performed. According to http://wiki.typo3.org/Dependency_Injection#initializeObject.28.29_as_object_lifecycle_method `initializeObject()` is called after DI has been done.
Tested on 6.2.12
On 6.2.13-dev initializeObject() is not being called anymore - see #67272.
Seems to be related to the Doctrine Migrator changes.
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914
- Target version set to 6.2.13
- Sprint Focus set to Stabilization Sprint
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
- Status changed from Resolved to Under Review
Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/40056
- Status changed from Under Review to Needs Feedback
Morton Jonuschat wrote:
On 6.2.13-dev initializeObject() is not being called anymore - see #67272.
Seems to be related to the Doctrine Migrator changes.
If you tested that on 6.2.12, how can this be related to Doctrine Instantiator changes? These were not included in that release.
Can be please be very clear about that? Your issue is present before the Doctrine instatiator change, right?
Helmut Hummel wrote:
Morton Jonuschat wrote:
On 6.2.13-dev initializeObject() is not being called anymore - see #67272.
Seems to be related to the Doctrine Migrator changes.
If you tested that on 6.2.12, how can this be related to Doctrine Instantiator changes? These were not included in that release.
Can be please be very clear about that? Your issue is present before the Doctrine instatiator change, right?
This very bug has nothing to do with the Doctrine instatiator change. Even before the initializeObject was called in __wakeup of domain objects and DI was done after that (since very long already)
To be very clear:
Given the following Class:
class Event extends AbstractEntity {
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
*/
protected $configurationManager;
/**
* inject the configurationManager
*
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
* @return void
*/
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) {
print "<pre>injectConfigurationManager</pre>";
$this->configurationManager = $configurationManager;
}
/**
* Tasks to perform on object initialization
*
* @return void
*/
public function initializeObject() {
print "<pre>initializeObject</pre>";
$this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
}
}
On 6.2.12
Output:
initializeObject
followed by a PHP Fatal error since $this->configurationManager has not been injected yet
This is what THIS bug report was about
On 6.2.13-dev
I'd get the following Output:
initializeObject
Later on $this->settings would be empty since initializeObject() has not been called at all.
The comment you quoted is related to the observation that there is a different bug on 6.2.13-dev that skips initializeObject() alltogether - #67272
I was asked to verify this against 6.2.13-dev on Slack to see if the switch to Doctrine Instantiator fixed it.
Sorry, on 6.2.13-dev the output was
injectConfigurationManager
Dumb copy&paste error
- Target version changed from 6.2.13 to 6.2.14
After Reverting DI in 6.2.13, is this issue still valid?
Yes, this issue ist still valid as nothing has changed in 6.2.13 in this regard (The switch to doctrine instantiator has been reverted, so initializeObject() is being called in __wakeup() which happens before the dependency injection).
- Status changed from Needs Feedback to New
- Status changed from New to Resolved
the issue is fixed in master and will not be fixed / changed in 6.2
- Status changed from Resolved to Closed
Also available in: Atom
PDF