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);
Actions