> */ protected array $uploadedFiles = []; /** * Default value. Used if argument is optional. */ protected mixed $defaultValue = null; /** * A custom validator, used supplementary to the base validation */ protected ?ValidatorInterface $validator = null; /** * The validation results. This can be asked if the argument has errors. */ protected Result $validationResults; /** * Constructs this controller argument * * @throws \InvalidArgumentException if $name is empty string */ public function __construct(string $name, string $dataType) { if ($name === '') { throw new \InvalidArgumentException('$name must be a non-empty string.', 1232551853); } $this->name = $name; $this->dataType = TypeHandlingUtility::normalizeType($dataType); $this->validationResults = new Result(); $this->propertyMappingConfiguration = GeneralUtility::makeInstance(MvcPropertyMappingConfiguration::class); $this->fileHandlingServiceConfiguration = GeneralUtility::makeInstance(FileHandlingServiceConfiguration::class); } public function getName(): string { return $this->name; } /** * @throws \InvalidArgumentException if $shortName is not a character */ public function setShortName(string $shortName): Argument { if (strlen($shortName) !== 1) { throw new \InvalidArgumentException('$shortName must be a single character or NULL', 1195824959); } $this->shortName = $shortName; return $this; } public function getShortName(): string { return $this->shortName; } public function getDataType(): string { return $this->dataType; } public function setRequired(bool $required): Argument { $this->isRequired = $required; return $this; } public function isRequired(): bool { return $this->isRequired; } public function setDefaultValue(mixed $defaultValue): Argument { $this->defaultValue = $defaultValue; return $this; } public function getDefaultValue(): mixed { return $this->defaultValue; } /** * Sets a custom validator which is used supplementary to the base validation */ public function setValidator(ValidatorInterface $validator): Argument { $this->validator = $validator; return $this; } public function getValidator(): ?ValidatorInterface { return $this->validator; } public function setValue(mixed $rawValue): Argument { $this->value = $rawValue; return $this; } public function getValue(): mixed { if ($this->value === null) { return $this->defaultValue; } return $this->value; } /** * Return the Property Mapping Configuration used for this argument; can be used by the initialize*action to modify the Property Mapping. */ public function getPropertyMappingConfiguration(): MvcPropertyMappingConfiguration { return $this->propertyMappingConfiguration; } /** * Return the FileHandlingServiceConfiguration used for this argument; can be used by the * initialize*action to modify the file upload configuration for properties. */ public function getFileHandlingServiceConfiguration(): FileHandlingServiceConfiguration { return $this->fileHandlingServiceConfiguration; } public function getUploadedFiles(): array { return $this->uploadedFiles; } public function setUploadedFiles(array $uploadedFiles): void { $this->uploadedFiles = $uploadedFiles; } /** * @return bool TRUE if the argument is valid, FALSE otherwise */ public function isValid(): bool { return !$this->validate()->hasErrors(); } /** * Returns a string representation of this argument's value */ public function __toString(): string { return (string)$this->value; } public function validate(): Result { if ($this->hasBeenValidated) { return $this->validationResults; } if ($this->validator !== null) { $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } if ($this->fileHandlingServiceConfiguration->hasfileUploadConfigurations()) { $fileOperationValidationResults = $this->fileHandlingServiceConfiguration->validateFileOperations($this); $this->validationResults->merge($fileOperationValidationResults); } $this->hasBeenValidated = true; return $this->validationResults; } /** * Returns an array of possible UploadedFile objects for the given property * @return list */ public function getUploadedFilesForProperty(string $propertyName): array { $result = []; try { $uploadedFiles = ArrayUtility::getValueByPath($this->uploadedFiles, $propertyName, '.'); if ($uploadedFiles instanceof UploadedFile) { $result = [$uploadedFiles]; } elseif (is_iterable($uploadedFiles)) { foreach ($uploadedFiles as $uploadedFile) { $result[] = $uploadedFile; } } } catch (MissingArrayPathException) { // Do nothing, empty array will be returned } return $result; } /** * @internal only to be used within Extbase, not part of TYPO3 Core API. */ public function getValidationResults(): Result { return $this->validationResults; } }