‪TYPO3CMS  ‪main
Argument.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
27 {
32 
38  protected ‪$name = '';
39 
45  protected ‪$shortName;
46 
52  protected ‪$dataType;
53 
59  protected ‪$isRequired = false;
60 
66  protected ‪$value;
67 
73  protected ‪$defaultValue;
74 
80  protected ‪$validator;
81 
87  protected ‪$validationResults;
88 
92  private ‪$hasBeenValidated = false;
93 
101  public function ‪__construct(‪$name, ‪$dataType)
102  {
103  if (!is_string(‪$name)) {
104  throw new \InvalidArgumentException('$name must be of type string, ' . gettype(‪$name) . ' given.', 1187951688);
105  }
106  if (‪$name === '') {
107  throw new \InvalidArgumentException('$name must be a non-empty string.', 1232551853);
108  }
109  $this->name = ‪$name;
111 
112  $this->validationResults = new ‪Result();
113  $this->propertyMappingConfiguration = GeneralUtility::makeInstance(MvcPropertyMappingConfiguration::class);
114  }
115 
121  public function ‪getName()
122  {
124  }
125 
133  public function ‪setShortName(‪$shortName)
134  {
135  if (‪$shortName !== null && (!is_string(‪$shortName) || strlen(‪$shortName) !== 1)) {
136  throw new \InvalidArgumentException('$shortName must be a single character or NULL', 1195824959);
137  }
138  $this->shortName = ‪$shortName;
139  return $this;
140  }
141 
147  public function ‪getShortName()
148  {
149  return ‪$this->shortName;
150  }
151 
157  public function ‪getDataType()
158  {
159  return ‪$this->dataType;
160  }
161 
168  public function ‪setRequired($required)
169  {
170  $this->‪isRequired = (bool)$required;
171  return $this;
172  }
173 
179  public function ‪isRequired()
180  {
181  return ‪$this->isRequired;
182  }
183 
190  public function ‪setDefaultValue(‪$defaultValue)
191  {
192  $this->defaultValue = ‪$defaultValue;
193  return $this;
194  }
195 
201  public function ‪getDefaultValue()
202  {
203  return ‪$this->defaultValue;
204  }
205 
213  {
214  $this->validator = ‪$validator;
215  return $this;
216  }
217 
223  public function ‪getValidator()
224  {
226  }
227 
235  public function ‪setValue($rawValue)
236  {
237  $this->value = $rawValue;
238  return $this;
239  }
240 
246  public function ‪getValue()
247  {
248  if ($this->value === null) {
250  }
251  return ‪$this->value;
252  }
253 
259  public function ‪getPropertyMappingConfiguration()
260  {
262  }
263 
267  public function ‪isValid(): bool
268  {
269  return !$this->‪validate()->hasErrors();
270  }
271 
277  public function ‪__toString()
278  {
279  return (string)‪$this->value;
280  }
281 
282  public function ‪validate(): ‪Result
283  {
284  if ($this->hasBeenValidated) {
286  }
287 
288  if ($this->validator !== null) {
289  $validationMessages = $this->validator->validate($this->value);
290  $this->validationResults->‪merge($validationMessages);
291  }
292 
293  $this->hasBeenValidated = true;
295  }
296 
300  public function ‪getValidationResults(): ‪Result
301  {
303  }
304 }
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$dataType
‪string $dataType
Definition: Argument.php:48
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$isRequired
‪bool $isRequired
Definition: Argument.php:54
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\setValidator
‪Argument setValidator(ValidatorInterface $validator)
Definition: Argument.php:202
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$name
‪string $name
Definition: Argument.php:36
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\__construct
‪__construct($name, $dataType)
Definition: Argument.php:91
‪TYPO3\CMS\Extbase\Utility\TypeHandlingUtility\normalizeType
‪static string normalizeType(string $type)
Definition: TypeHandlingUtility.php:80
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getValidator
‪ValidatorInterface getValidator()
Definition: Argument.php:213
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$hasBeenValidated
‪bool $hasBeenValidated
Definition: Argument.php:82
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getPropertyMappingConfiguration
‪MvcPropertyMappingConfiguration getPropertyMappingConfiguration()
Definition: Argument.php:249
‪TYPO3\CMS\Extbase\Mvc\Controller
Definition: ActionController.php:16
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:24
‪TYPO3\CMS\Extbase\Error\Result\merge
‪merge(Result $otherResult)
Definition: Result.php:409
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getValidationResults
‪getValidationResults()
Definition: Argument.php:290
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\isRequired
‪bool isRequired()
Definition: Argument.php:169
‪TYPO3\CMS\Extbase\Utility\TypeHandlingUtility
Definition: TypeHandlingUtility.php:29
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\setDefaultValue
‪Argument setDefaultValue($defaultValue)
Definition: Argument.php:180
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$propertyMappingConfiguration
‪MvcPropertyMappingConfiguration $propertyMappingConfiguration
Definition: Argument.php:30
‪TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfiguration
Definition: MvcPropertyMappingConfiguration.php:26
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getName
‪string getName()
Definition: Argument.php:111
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\setRequired
‪Argument setRequired($required)
Definition: Argument.php:158
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getDefaultValue
‪mixed getDefaultValue()
Definition: Argument.php:191
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$validationResults
‪Result $validationResults
Definition: Argument.php:78
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getShortName
‪string getShortName()
Definition: Argument.php:137
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$validator
‪ValidatorInterface $validator
Definition: Argument.php:72
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$value
‪mixed null $value
Definition: Argument.php:60
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$shortName
‪string $shortName
Definition: Argument.php:42
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getDataType
‪string getDataType()
Definition: Argument.php:147
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\__toString
‪string __toString()
Definition: Argument.php:267
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:26
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument
Definition: Argument.php:27
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\$defaultValue
‪mixed $defaultValue
Definition: Argument.php:66
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\validate
‪validate()
Definition: Argument.php:272
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\setShortName
‪Argument setShortName($shortName)
Definition: Argument.php:123
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\isValid
‪bool isValid()
Definition: Argument.php:257
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\getValue
‪mixed getValue()
Definition: Argument.php:236
‪TYPO3\CMS\Extbase\Mvc\Controller\Argument\setValue
‪Argument setValue($rawValue)
Definition: Argument.php:225