Bug #90722

Handle constructor arguments in extension scanner correctly

Added by Oliver Hader 7 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Install Tool
Target version:
-
Start date:
2020-03-10
Due date:
% Done:

100%

TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Handling constructor arguments in extension scanner did not work since constructors are not directly called like a method would be called. Constructors are invoked instead using the new statement. Besides that GeneratorClassResolver only supported string class names (e.g. 'Example\\MyClass') when being invoked via GeneralUtility::makeInstance.

Scanner configurations related to __construct invocation in terms of creating a new class instance are now handled in their own ConstructorArgumentMatcher. Besides that, GeneratorClassResolver supports GeneralUtility::makeInstance(Example\MyClass::class, 123) as well.

scanner.png View (91.5 KB) Oliver Hader, 2020-03-10 20:57


Related issues

Related to TYPO3 Core - Bug #91128: PHP Catchable Fatal Error: Object of class PhpParser\Node\Expr\PropertyFetch could not be converted to string Closed 2020-04-19
Related to TYPO3 Core - Bug #91866: extensionScannerRstFileReferences check throws warnings Closed 2020-07-25

Associated revisions

Revision d6ad3ad1 (diff)
Added by Oliver Hader 7 months ago

[BUGFIX] Handle constructor arguments in extension scanner correctly

Handling constructor arguments in extension scanner did not work since
constructors are not directly called like a method would be called.
Constructors are invoked instead using the `new` statement. Besides
that `GeneratorClassResolver` only supported string class names (like
`'Example\\MyClass'`) when being invoked using
`GeneralUtility::makeInstance`.

Scanner configurations related to `__construct` invocation (in terms
of creating a new class instance) are now handled in a dedicated new
`ConstructorArgumentMatcher`. Besides that, `GeneratorClassResolver` now
supports `GeneralUtility::makeInstance(Example\MyClass::class, 123)`
as well.

`NameResolver` and `GeneratorClassesResolver` are executed in two
consecutive `NodeTraverser` instances - otherwise class names cannot
be resolved in a reliable way.

Resolves: #90722
Releases: master, 9.5
Change-Id: I0154b04674d2637fda817d39a1136c2c8fa389d8
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63676
Tested-by: TYPO3com <>
Tested-by: Andreas Fernandez <>
Tested-by: Benni Mack <>
Reviewed-by: Andreas Fernandez <>
Reviewed-by: Benni Mack <>
Reviewed-by: Georg Ringer <>

Revision e62379cc (diff)
Added by Oliver Hader 7 months ago

[BUGFIX] Handle constructor arguments in extension scanner correctly

Handling constructor arguments in extension scanner did not work since
constructors are not directly called like a method would be called.
Constructors are invoked instead using the `new` statement. Besides
that `GeneratorClassResolver` only supported string class names (like
`'Example\\MyClass'`) when being invoked using
`GeneralUtility::makeInstance`.

Scanner configurations related to `__construct` invocation (in terms
of creating a new class instance) are now handled in a dedicated new
`ConstructorArgumentMatcher`. Besides that, `GeneratorClassResolver` now
supports `GeneralUtility::makeInstance(Example\MyClass::class, 123)`
as well.

`NameResolver` and `GeneratorClassesResolver` are executed in two
consecutive `NodeTraverser` instances - otherwise class names cannot
be resolved in a reliable way.

Resolves: #90722
Releases: master, 9.5
Change-Id: I0154b04674d2637fda817d39a1136c2c8fa389d8
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63683
Tested-by: TYPO3com <>
Tested-by: Oliver Hader <>
Reviewed-by: Oliver Hader <>

History

#1 Updated by Gerrit Code Review 7 months ago

  • 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 https://review.typo3.org/c/Packages/TYPO3.CMS/+/63676

#2 Updated by Gerrit Code Review 7 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63676

#3 Updated by Oliver Hader 7 months ago

Having the patch applied, it should look similar to the following for new and GeneralUtility::makeInstance...

#4 Updated by Gerrit Code Review 7 months ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63676

#5 Updated by Gerrit Code Review 7 months ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63676

#6 Updated by Gerrit Code Review 7 months ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63683

#7 Updated by Oliver Hader 7 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#8 Updated by Benni Mack 7 months ago

  • Status changed from Resolved to Closed

#9 Updated by Christian Eßl 6 months ago

  • Related to Bug #91128: PHP Catchable Fatal Error: Object of class PhpParser\Node\Expr\PropertyFetch could not be converted to string added

#10 Updated by Anja Leichsenring 3 months ago

  • Related to Bug #91866: extensionScannerRstFileReferences check throws warnings added

Also available in: Atom PDF