|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPModelGenerator\PropertyProcessor\Property; |
| 4 | + |
| 5 | +use PHPModelGenerator\Exception\InvalidArgumentException; |
| 6 | +use PHPModelGenerator\Model\Property\PropertyInterface; |
| 7 | +use PHPModelGenerator\Model\Validator\PropertyTemplateValidator; |
| 8 | +use PHPModelGenerator\PropertyProcessor\PropertyCollectionProcessor; |
| 9 | +use PHPModelGenerator\PropertyProcessor\PropertyFactory; |
| 10 | +use PHPModelGenerator\Utils\RenderHelper; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class AbstractComposedValueProcessor |
| 14 | + * |
| 15 | + * @package PHPModelGenerator\PropertyProcessor\Property |
| 16 | + */ |
| 17 | +abstract class AbstractComposedValueProcessor extends AbstractNestedValueProcessor |
| 18 | +{ |
| 19 | + protected const COMPOSED_VALUE_VALIDATION = ''; |
| 20 | + |
| 21 | + /** |
| 22 | + * @inheritdoc |
| 23 | + */ |
| 24 | + protected function generateValidators(PropertyInterface $property, array $propertyData): void |
| 25 | + { |
| 26 | + $propertyFactory = new PropertyFactory(); |
| 27 | + |
| 28 | + $properties = []; |
| 29 | + foreach ($propertyData as $compositionElement) { |
| 30 | + $properties[] = $propertyFactory |
| 31 | + ->create( |
| 32 | + new PropertyCollectionProcessor(), |
| 33 | + $this->schemaProcessor, |
| 34 | + $this->schema, |
| 35 | + $property->getName(), |
| 36 | + $compositionElement |
| 37 | + ) |
| 38 | + ->setRequired($property->isRequired()); |
| 39 | + } |
| 40 | + |
| 41 | + $property->addValidator( |
| 42 | + new PropertyTemplateValidator( |
| 43 | + InvalidArgumentException::class, |
| 44 | + 'Invalid composed item', |
| 45 | + DIRECTORY_SEPARATOR . 'Validator' . DIRECTORY_SEPARATOR . 'ComposedItem.phptpl', |
| 46 | + [ |
| 47 | + 'properties' => $properties, |
| 48 | + 'viewHelper' => new RenderHelper(), |
| 49 | + 'availableAmount' => count($properties), |
| 50 | + 'composedValueValidation' => static::COMPOSED_VALUE_VALIDATION, |
| 51 | + ] |
| 52 | + ) |
| 53 | + ); |
| 54 | + } |
| 55 | +} |
0 commit comments