Project

General

Profile

Actions

Bug #92357

closed

Extbase / Symfony: Domain Object Validation with Lazy Loading ignores Getters

Added by Till Wimmer about 4 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2020-09-21
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.4
Tags:
extbase symfony validation lazyloading
Complexity:
Is Regression:
Sprint Focus:

Description

There is an issue with model validation in V10 when lazy loading is involved.

In such a case we get the PHP error:

Cannot access protected property Myvend\Myext\Domain\Model\Myclass::$property

I.e. it tries to access the (protected) property instead of using the getter.

The reason is that Symfony analyzes the LazyLoadingProxy object instead of the real class and then gets the ACCESS_TYPE_PROPERTY (/var/www/typo3_src-10.4.8/vendor/symfony/property-access/PropertyAccessor.php line 398):

                    throw $e;
                }
            } elseif (self::ACCESS_TYPE_PROPERTY === $access[self::ACCESS_TYPE]) {
                $result[self::VALUE] = $object->{$access[self::ACCESS_NAME]};

                if ($access[self::ACCESS_REF] && isset($zval[self::REF])) {
                    $result[self::REF] = &$object->{$access[self::ACCESS_NAME]};
                }

This happens in Symfony\Component\PropertyAccess::readProperty() by calling getReadAccessInfo().

My workaround is adding those lines starting at 377, readProperty():

    private function readProperty(array $zval, string $property, bool $ignoreInvalidProperty = false): array
    {
        if (!\is_object($zval[self::VALUE])) {
            throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%1$s]" instead.', $property));
        }

377:    if ($zval[self::VALUE] instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
378:        $zval[self::VALUE] = $zval[self::VALUE]->_loadRealInstance();
379:    }
Actions

Also available in: Atom PDF