‪TYPO3CMS  ‪main
PropertyMappingConfiguration.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 {
26  public const ‪PROPERTY_PATH_PLACEHOLDER = '*';
27 
36  protected ‪$configuration;
37 
43  protected ‪$subConfigurationForProperty = [];
44 
50  protected ‪$mapping = [];
51 
55  protected ‪$typeConverter;
56 
62  protected ‪$propertiesToBeMapped = [];
63 
69  protected ‪$propertiesToSkip = [];
70 
76  protected ‪$propertiesNotToBeMapped = [];
77 
83  protected ‪$skipUnknownProperties = false;
84 
90  protected ‪$mapUnknownProperties = false;
91 
103  public function ‪shouldMap($propertyName)
104  {
105  if (isset($this->propertiesNotToBeMapped[$propertyName])) {
106  return false;
107  }
108 
109  if (isset($this->propertiesToBeMapped[$propertyName])) {
110  return true;
111  }
112 
113  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
114  return true;
115  }
116 
118  }
119 
126  public function ‪shouldSkip($propertyName)
127  {
128  return isset($this->propertiesToSkip[$propertyName]);
129  }
130 
136  public function ‪allowAllProperties()
137  {
138  $this->mapUnknownProperties = true;
139  return $this;
140  }
141 
150  public function ‪allowProperties()
151  {
152  foreach (func_get_args() as $propertyName) {
153  $this->propertiesToBeMapped[$propertyName] = $propertyName;
154  }
155  return $this;
156  }
157 
166  public function ‪skipProperties()
167  {
168  foreach (func_get_args() as $propertyName) {
169  $this->propertiesToSkip[$propertyName] = $propertyName;
170  }
171  return $this;
172  }
173 
182  public function ‪allowAllPropertiesExcept()
183  {
184  $this->mapUnknownProperties = true;
185 
186  foreach (func_get_args() as $propertyName) {
187  $this->propertiesNotToBeMapped[$propertyName] = $propertyName;
188  }
189  return $this;
190  }
191 
198  public function ‪skipUnknownProperties()
199  {
200  $this->‪skipUnknownProperties = true;
201  return $this;
202  }
203 
210  public function ‪shouldSkipUnknownProperties()
211  {
213  }
214 
221  public function ‪getConfigurationFor($propertyName)
222  {
223  if (isset($this->subConfigurationForProperty[$propertyName])) {
224  return $this->subConfigurationForProperty[$propertyName];
225  }
226  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
227  return $this->subConfigurationForProperty[‪self::PROPERTY_PATH_PLACEHOLDER];
228  }
229 
230  return new self();
231  }
232 
239  public function ‪getTargetPropertyName($sourcePropertyName)
240  {
241  if (isset($this->mapping[$sourcePropertyName])) {
242  return $this->mapping[$sourcePropertyName];
243  }
244  return $sourcePropertyName;
245  }
246 
252  public function ‪getConfigurationValue($typeConverterClassName, $key)
253  {
254  if (!isset($this->configuration[$typeConverterClassName][$key])) {
255  return null;
256  }
257 
258  return $this->configuration[$typeConverterClassName][$key];
259  }
260 
268  public function ‪setMapping($sourcePropertyName, $targetPropertyName)
269  {
270  $this->mapping[$sourcePropertyName] = $targetPropertyName;
271  return $this;
272  }
273 
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 ?: [];
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 
340  public function ‪traverseProperties(array $splittedPropertyPath)
341  {
342  if (empty($splittedPropertyPath)) {
343  return $this;
344  }
345 
346  $currentProperty = array_shift($splittedPropertyPath);
347  if (!isset($this->subConfigurationForProperty[$currentProperty])) {
348  $type = static::class;
349  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
350  $this->subConfigurationForProperty[$currentProperty] = clone $this->subConfigurationForProperty[‪self::PROPERTY_PATH_PLACEHOLDER];
351  } else {
352  $this->subConfigurationForProperty[$currentProperty] = new $type();
353  }
354  }
355  return $this->subConfigurationForProperty[$currentProperty]->traverseProperties($splittedPropertyPath);
356  }
357 
363  public function ‪getTypeConverter()
364  {
366  }
367 
374  {
375  $this->typeConverter = ‪$typeConverter;
376  return $this;
377  }
378 }
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getTypeConvertersWithParentClasses
‪array getTypeConvertersWithParentClasses($typeConverter)
Definition: PropertyMappingConfiguration.php:304
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getTypeConverter
‪TYPO3 CMS Extbase Property TypeConverterInterface null getTypeConverter()
Definition: PropertyMappingConfiguration.php:354
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\skipUnknownProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration skipUnknownProperties()
Definition: PropertyMappingConfiguration.php:189
‪TYPO3\CMS\Extbase\Property\TypeConverterInterface
Definition: TypeConverterInterface.php:26
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$skipUnknownProperties
‪bool $skipUnknownProperties
Definition: PropertyMappingConfiguration.php:75
‪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:157
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\PROPERTY_PATH_PLACEHOLDER
‪const PROPERTY_PATH_PLACEHOLDER
Definition: PropertyMappingConfiguration.php:26
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\shouldSkipUnknownProperties
‪bool shouldSkipUnknownProperties()
Definition: PropertyMappingConfiguration.php:201
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\setTypeConverter
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration setTypeConverter(TypeConverterInterface $typeConverter)
Definition: PropertyMappingConfiguration.php:364
‪TYPO3\CMS\Extbase\Property
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface
Definition: PropertyMappingConfigurationInterface.php:22
‪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:35
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\allowAllPropertiesExcept
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration allowAllPropertiesExcept()
Definition: PropertyMappingConfiguration.php:173
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$propertiesToBeMapped
‪array $propertiesToBeMapped
Definition: PropertyMappingConfiguration.php:57
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
Definition: PropertyMappingConfiguration.php:22
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$mapping
‪array $mapping
Definition: PropertyMappingConfiguration.php:47
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\traverseProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration traverseProperties(array $splittedPropertyPath)
Definition: PropertyMappingConfiguration.php:331
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\setMapping
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration setMapping($sourcePropertyName, $targetPropertyName)
Definition: PropertyMappingConfiguration.php:259
‪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:69
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$typeConverter
‪TYPO3 CMS Extbase Property TypeConverterInterface $typeConverter
Definition: PropertyMappingConfiguration.php:51
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$propertiesToSkip
‪array $propertiesToSkip
Definition: PropertyMappingConfiguration.php:63
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getTargetPropertyName
‪string getTargetPropertyName($sourcePropertyName)
Definition: PropertyMappingConfiguration.php:230
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getConfigurationFor
‪TYPO3 CMS Extbase Property PropertyMappingConfigurationInterface getConfigurationFor($propertyName)
Definition: PropertyMappingConfiguration.php:212
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\allowAllProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration allowAllProperties()
Definition: PropertyMappingConfiguration.php:127
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$mapUnknownProperties
‪bool $mapUnknownProperties
Definition: PropertyMappingConfiguration.php:81
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\allowProperties
‪TYPO3 CMS Extbase Property PropertyMappingConfiguration allowProperties()
Definition: PropertyMappingConfiguration.php:141
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\getConfigurationValue
‪mixed getConfigurationValue($typeConverterClassName, $key)
Definition: PropertyMappingConfiguration.php:243
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\shouldSkip
‪bool shouldSkip($propertyName)
Definition: PropertyMappingConfiguration.php:117
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\shouldMap
‪bool shouldMap($propertyName)
Definition: PropertyMappingConfiguration.php:94
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration\$subConfigurationForProperty
‪TYPO3 CMS Extbase Property PropertyMappingConfigurationInterface[] $subConfigurationForProperty
Definition: PropertyMappingConfiguration.php:41