Actions
Bug #97522
closedWord "new" in command "description" breaks DI
Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Miscellaneous
Target version:
-
Start date:
2022-04-29
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
Description
Given a command definition like this ...
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Acme\Foo\:
resource: '../Classes/*'
Acme\Foo\Command\BarCommand:
tags:
- name: console.command
command: example:bar
description: Build a new bar
schedulable: false
Acme\Foo\Command\QuxCommand:
tags:
- name: console.command
command: example:qux
description: Do something
schedulable: false
... you get an error like this:
[ ParseError ] syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting '(' Exception trace: #0 () var/cache/code/di/DependencyInjectionContainer_<hash>.php:<line> ...
The generated service in the DI cache file:
/**
* Gets the public 'Acme\Foo\Command\BarCommand' shared autowired service.
*
* @return \Acme\Foo\Command\BarCommand
*/
protected function getBarCommandService()
{
$this->services['Acme\\Foo\\Command\\BarCommand'] = $instance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceForDi(\Acme\Foo\Command\BarCommand::class, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceForDi(\Acme\Foo\Security\BarDependency::class));
$instance->setName('example:bar');
$instance->setDescription('Build a \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceForDi(bar');
return $instance;
}
/**
* Gets the public 'Acme\Foo\Command\QuxCommand' shared autowired service.
*
* @return \Acme\Foo\Command\QuxCommand
*/
protected function getQuxCommandService::class)
{
# ...
}
This is very likely caused by the rather simple replacement here:
$code = preg_replace('/new ([^\(\s]+)\(/', '\\TYPO3\\CMS\\Core\\Utility\\GeneralUtility::makeInstanceForDi(\\1::class, ', $code);
Updated by Oliver Bartsch over 2 years ago
- Related to Bug #95607: Keyword "new" leads to corrupt DependencyInjectionContainer_...php added
Updated by Simon Gilli over 2 years ago
- Status changed from New to Needs Feedback
What's your exact version? It should be fixed since 11.5.2.
Updated by Mathias Brodala over 2 years ago
- Status changed from Needs Feedback to Closed
- TYPO3 Version changed from 11 to 10
Yes, this was in fact tested on TYPO3v10 which does not have this fix.
Actions