Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] TYPO3 12: AbstractMapping - Determine property type leads to exceptions #31

Open
3l73 opened this issue Sep 3, 2024 · 1 comment

Comments

@3l73
Copy link

3l73 commented Sep 3, 2024

The class AbstractMapping uses the TYPO3 ReflectionService to determine the correct data type.

This leads currently to the following exception:

TypeError: TYPO3\CMS\Extbase\Reflection\ReflectionService::__construct():
Argument #1 ($cache) must be of type TYPO3\CMS\Core\Cache\Frontend\FrontendInterface, Acme\RoadRunner\Domain\Model\Coyote given,
called in vendor/crossmedia/fourallportal/Classes/Mapping/AbstractMapping.php on line 511

Expected behavior

No exception occured.

To Reproduce

  1. Create a functional test for Mappings
  2. Execute the functional test

Used versions:
TYPO3: v12.4.17
Extension version: 3e00a60 (@Dev-Master)

Additional context

This exception occured during a functional test.

The stacktrace is as followed:

vendor/typo3/cms-extbase/Classes/Reflection/ReflectionService.php:53
vendor/crossmedia/fourallportal/Classes/Mapping/AbstractMapping.php:511
vendor/crossmedia/fourallportal/Classes/Mapping/AbstractMapping.php:389
vendor/crossmedia/fourallportal/Classes/Mapping/AbstractMapping.php:327
packages/acme_roadrunner/Classes/Mapping/CoyoteMapping.php:58
vendor/crossmedia/fourallportal/Classes/Mapping/AbstractMapping.php:885
vendor/crossmedia/fourallportal/Classes/Mapping/AbstractMapping.php:133

The reflection service itself uses the frontend cache and an identifier as constructor arguments.
Additionally it should be instantiated via GeneralUtility::makeInstance().

See:

$property = new ReflectionService($object, $propertyName);

The whole method seems to need refactoring, since the methods and there result of the reflection service changed.

Relates change log entries:

@3l73
Copy link
Author

3l73 commented Sep 3, 2024

A possible, not yet fully testet solution could be following code:

    if (property_exists(get_class($object), $propertyName)) {
        $reflectionService = GeneralUtility::makeInstance(ReflectionService::class);
        $classSchema = $reflectionService->getClassSchema($object);
        $property = $classSchema->getProperty($propertyName);
        if ($property->getPrimaryType()->isCollection()) {
            $types = array_map(
                function (Type $type) {
                    return $type->getClassName();
                },
                $property->getPrimaryType()->getCollectionValueTypes()
            );
            return $property->getPrimaryType()->getClassName() . '<' .  implode('|', $types) . '>';
        }
        return $property->getPrimaryType()->getBuiltinType();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant