‪TYPO3CMS  9.5
PropertyMappingConfiguration.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
26 
35  protected ‪$configuration;
36 
42  protected ‪$subConfigurationForProperty = [];
43 
49  protected ‪$mapping = [];
50 
54  protected ‪$typeConverter;
55 
61  protected ‪$propertiesToBeMapped = [];
62 
68  protected ‪$propertiesToSkip = [];
69 
75  protected ‪$propertiesNotToBeMapped = [];
76 
82  protected ‪$skipUnknownProperties = false;
83 
89  protected ‪$mapUnknownProperties = false;
90 
102  public function ‪shouldMap($propertyName)
103  {
104  if (isset($this->propertiesNotToBeMapped[$propertyName])) {
105  return false;
106  }
107 
108  if (isset($this->propertiesToBeMapped[$propertyName])) {
109  return true;
110  }
111 
112  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
113  return true;
114  }
115 
117  }
118 
125  public function ‪shouldSkip($propertyName)
126  {
127  return isset($this->propertiesToSkip[$propertyName]);
128  }
129 
135  public function ‪allowAllProperties()
136  {
137  $this->mapUnknownProperties = true;
138  return $this;
139  }
140 
149  public function ‪allowProperties()
150  {
151  foreach (func_get_args() as $propertyName) {
152  $this->propertiesToBeMapped[$propertyName] = $propertyName;
153  }
154  return $this;
155  }
156 
165  public function ‪skipProperties()
166  {
167  foreach (func_get_args() as $propertyName) {
168  $this->propertiesToSkip[$propertyName] = $propertyName;
169  }
170  return $this;
171  }
172 
181  public function ‪allowAllPropertiesExcept()
182  {
183  $this->mapUnknownProperties = true;
184 
185  foreach (func_get_args() as $propertyName) {
186  $this->propertiesNotToBeMapped[$propertyName] = $propertyName;
187  }
188  return $this;
189  }
190 
197  public function ‪skipUnknownProperties()
198  {
199  $this->‪skipUnknownProperties = true;
200  return $this;
201  }
202 
209  public function ‪shouldSkipUnknownProperties()
210  {
212  }
213 
220  public function ‪getConfigurationFor($propertyName)
221  {
222  if (isset($this->subConfigurationForProperty[$propertyName])) {
223  return $this->subConfigurationForProperty[$propertyName];
224  }
225  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
226  return $this->subConfigurationForProperty[‪self::PROPERTY_PATH_PLACEHOLDER];
227  }
228 
229  return new self();
230  }
231 
238  public function ‪getTargetPropertyName($sourcePropertyName)
239  {
240  if (isset($this->mapping[$sourcePropertyName])) {
241  return $this->mapping[$sourcePropertyName];
242  }
243  return $sourcePropertyName;
244  }
245 
251  public function ‪getConfigurationValue($typeConverterClassName, $key)
252  {
253  if (!isset($this->configuration[$typeConverterClassName][$key])) {
254  return null;
255  }
256 
257  return $this->configuration[$typeConverterClassName][$key];
258  }
259 
267  public function ‪setMapping($sourcePropertyName, $targetPropertyName)
268  {
269  $this->mapping[$sourcePropertyName] = $targetPropertyName;
270  return $this;
271  }
272 
280  public function ‪setTypeConverterOptions(‪$typeConverter, array $options)
281  {
283  $this->configuration[‪$typeConverter] = $options;
284  }
285  return $this;
286  }
287 
296  public function ‪setTypeConverterOption(‪$typeConverter, $optionKey, $optionValue)
297  {
299  $this->configuration[‪$typeConverter][$optionKey] = $optionValue;
300  }
301  return $this;
302  }
303 
314  {
315  $typeConverterClasses = class_parents(‪$typeConverter);
316  $typeConverterClasses = $typeConverterClasses === false ? [] : $typeConverterClasses;
317  $typeConverterClasses[] = ‪$typeConverter;
318  return $typeConverterClasses;
319  }
320 
329  public function ‪forProperty($propertyPath)
330  {
331  $splittedPropertyPath = explode('.', $propertyPath);
332  return $this->‪traverseProperties($splittedPropertyPath);
333  }
334 
341  public function ‪traverseProperties(array $splittedPropertyPath)
342  {
343  if (empty($splittedPropertyPath)) {
344  return $this;
345  }
346 
347  $currentProperty = array_shift($splittedPropertyPath);
348  if (!isset($this->subConfigurationForProperty[$currentProperty])) {
349  $type = static::class;
350  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
351  $this->subConfigurationForProperty[$currentProperty] = clone $this->subConfigurationForProperty[‪self::PROPERTY_PATH_PLACEHOLDER];
352  } else {
353  $this->subConfigurationForProperty[$currentProperty] = new $type;
354  }
355  }
356  return $this->subConfigurationForProperty[$currentProperty]->traverseProperties($splittedPropertyPath);
357  }
358 
364  public function ‪getTypeConverter()
365  {
367  }
368 
376  {
377  $this->typeConverter = ‪$typeConverter;
378  return $this;
379  }
380 }
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getTypeConvertersWithParentClasses
‪array getTypeConvertersWithParentClasses($typeConverter)
Definition: PropertyMappingConfiguration.php:304
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\skipUnknownProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration skipUnknownProperties()
Definition: PropertyMappingConfiguration.php:188
‪TYPO3\CMS\Extbase\Property\TypeConverterInterface
Definition: TypeConverterInterface.php:23
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$skipUnknownProperties
‪bool $skipUnknownProperties
Definition: PropertyMappingConfiguration.php:74
‪TYPO3
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\setTypeConverterOption
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration setTypeConverterOption($typeConverter, $optionKey, $optionValue)
Definition: PropertyMappingConfiguration.php:287
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\skipProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration skipProperties()
Definition: PropertyMappingConfiguration.php:156
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\PROPERTY_PATH_PLACEHOLDER
‪const PROPERTY_PATH_PLACEHOLDER
Definition: PropertyMappingConfiguration.php:25
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\shouldSkipUnknownProperties
‪bool shouldSkipUnknownProperties()
Definition: PropertyMappingConfiguration.php:200
‪TYPO3\CMS\Extbase\Property
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getTypeConverter
‪TYPO3 CMS Extbase Property TypeConverterInterface getTypeConverter()
Definition: PropertyMappingConfiguration.php:355
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface
Definition: PropertyMappingConfigurationInterface.php:21
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\forProperty
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration forProperty($propertyPath)
Definition: PropertyMappingConfiguration.php:320
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$configuration
‪array $configuration
Definition: PropertyMappingConfiguration.php:34
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\allowAllPropertiesExcept
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration allowAllPropertiesExcept()
Definition: PropertyMappingConfiguration.php:172
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$propertiesToBeMapped
‪array $propertiesToBeMapped
Definition: PropertyMappingConfiguration.php:56
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
Definition: PropertyMappingConfiguration.php:21
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$mapping
‪array $mapping
Definition: PropertyMappingConfiguration.php:46
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\traverseProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration traverseProperties(array $splittedPropertyPath)
Definition: PropertyMappingConfiguration.php:332
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\setMapping
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration setMapping($sourcePropertyName, $targetPropertyName)
Definition: PropertyMappingConfiguration.php:258
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\setTypeConverterOptions
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration setTypeConverterOptions($typeConverter, array $options)
Definition: PropertyMappingConfiguration.php:271
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$propertiesNotToBeMapped
‪array $propertiesNotToBeMapped
Definition: PropertyMappingConfiguration.php:68
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$typeConverter
‪TYPO3 CMS Extbase Property TypeConverterInterface $typeConverter
Definition: PropertyMappingConfiguration.php:50
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$propertiesToSkip
‪array $propertiesToSkip
Definition: PropertyMappingConfiguration.php:62
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\setTypeConverter
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration setTypeConverter(\TYPO3\CMS\Extbase\Property\TypeConverterInterface $typeConverter)
Definition: PropertyMappingConfiguration.php:366
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getTargetPropertyName
‪string getTargetPropertyName($sourcePropertyName)
Definition: PropertyMappingConfiguration.php:229
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getConfigurationFor
‪TYPO3 CMS Extbase Property PropertyMappingConfigurationInterface getConfigurationFor($propertyName)
Definition: PropertyMappingConfiguration.php:211
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\allowAllProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration allowAllProperties()
Definition: PropertyMappingConfiguration.php:126
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$mapUnknownProperties
‪bool $mapUnknownProperties
Definition: PropertyMappingConfiguration.php:80
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\allowProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration allowProperties()
Definition: PropertyMappingConfiguration.php:140
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getConfigurationValue
‪mixed getConfigurationValue($typeConverterClassName, $key)
Definition: PropertyMappingConfiguration.php:242
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\shouldSkip
‪bool shouldSkip($propertyName)
Definition: PropertyMappingConfiguration.php:116
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\shouldMap
‪bool shouldMap($propertyName)
Definition: PropertyMappingConfiguration.php:93
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$subConfigurationForProperty
‪TYPO3 CMS Extbase Property PropertyMappingConfigurationInterface[] $subConfigurationForProperty
Definition: PropertyMappingConfiguration.php:40