Project

General

Profile

Actions

Bug #97522

closed

Word "new" in command "description" breaks DI

Added by Mathias Brodala almost 2 years ago. Updated almost 2 years ago.

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:

https://github.com/TYPO3/typo3/blob/6f7514f51634fd98a4d4def818c3f16e28aff538/typo3/sysext/core/Classes/DependencyInjection/ContainerBuilder.php#L166

$code = preg_replace('/new ([^\(\s]+)\(/', '\\TYPO3\\CMS\\Core\\Utility\\GeneralUtility::makeInstanceForDi(\\1::class, ', $code);

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #95607: Keyword "new" leads to corrupt DependencyInjectionContainer_...phpClosedBenjamin Franzke2021-10-12

Actions
Actions #1

Updated by Oliver Bartsch almost 2 years ago

  • Related to Bug #95607: Keyword "new" leads to corrupt DependencyInjectionContainer_...php added
Actions #2

Updated by Simon Gilli almost 2 years ago

  • Status changed from New to Needs Feedback

What's your exact version? It should be fixed since 11.5.2.

Actions #3

Updated by Mathias Brodala almost 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

Also available in: Atom PDF