LazyProperty example

// Validate all properties against their constraints         foreach ($metadata->getConstrainedProperties() as $propertyName) {
            // If constraints are defined both on the getter of a property as             // well as on the property itself, then getPropertyMetadata()             // returns two metadata objects, not just one             foreach ($metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
                if (!$propertyMetadata instanceof PropertyMetadataInterface) {
                    throw new UnsupportedMetadataException(sprintf('The property metadata instances should implement "Symfony\Component\Validator\Mapping\PropertyMetadataInterface", got: "%s".', get_debug_type($propertyMetadata)));
                }

                if ($propertyMetadata instanceof GetterMetadata) {
                    $propertyValue = new LazyProperty(static fn () => $propertyMetadata->getPropertyValue($object));
                } else {
                    $propertyValue = $propertyMetadata->getPropertyValue($object);
                }

                $this->validateGenericNode(
                    $propertyValue,
                    $object,
                    $cacheKey.':'.$object::class.':'.$propertyName,
                    $propertyMetadata,
                    PropertyPath::append($propertyPath$propertyName),
                    $groups,
                    
// Validate all properties against their constraints         foreach ($metadata->getConstrainedProperties() as $propertyName) {
            // If constraints are defined both on the getter of a property as             // well as on the property itself, then getPropertyMetadata()             // returns two metadata objects, not just one             foreach ($metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
                if (!$propertyMetadata instanceof PropertyMetadataInterface) {
                    throw new UnsupportedMetadataException(sprintf('The property metadata instances should implement "Symfony\Component\Validator\Mapping\PropertyMetadataInterface", got: "%s".', get_debug_type($propertyMetadata)));
                }

                if ($propertyMetadata instanceof GetterMetadata) {
                    $propertyValue = new LazyProperty(static fn () => $propertyMetadata->getPropertyValue($object));
                } else {
                    $propertyValue = $propertyMetadata->getPropertyValue($object);
                }

                $this->validateGenericNode(
                    $propertyValue,
                    $object,
                    $cacheKey.':'.$object::class.':'.$propertyName,
                    $propertyMetadata,
                    PropertyPath::append($propertyPath$propertyName),
                    $groups,
                    
Home | Imprint | This part of the site doesn't use cookies.