TYPO3 CMS  TYPO3_6-2
PropertyMappingConfiguration.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the Extbase framework *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License as published by the *
9  * Free Software Foundation, either version 3 of the License, or (at your *
10  * option) any later version. *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
25 
32 
37 
46  protected $configuration;
47 
53  protected $subConfigurationForProperty = array();
54 
60  protected $mapping = array();
61 
65  protected $typeConverter = NULL;
66 
72  protected $propertiesToBeMapped = array();
73 
79  protected $propertiesToSkip = array();
80 
86  protected $propertiesNotToBeMapped = array();
87 
93  protected $skipUnknownProperties = FALSE;
94 
100  protected $mapUnknownProperties = FALSE;
101 
114  public function shouldMap($propertyName) {
115  if (isset($this->propertiesNotToBeMapped[$propertyName])) {
116  return FALSE;
117  }
118 
119  if (isset($this->propertiesToBeMapped[$propertyName])) {
120  return TRUE;
121  }
122 
123  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
124  return TRUE;
125  }
126 
128  }
129 
137  public function shouldSkip($propertyName) {
138  return isset($this->propertiesToSkip[$propertyName]);
139  }
140 
147  public function allowAllProperties() {
148  $this->mapUnknownProperties = TRUE;
149  return $this;
150  }
151 
161  public function allowProperties() {
162  foreach (func_get_args() as $propertyName) {
163  $this->propertiesToBeMapped[$propertyName] = $propertyName;
164  }
165  return $this;
166  }
167 
177  public function skipProperties() {
178  foreach (func_get_args() as $propertyName) {
179  $this->propertiesToSkip[$propertyName] = $propertyName;
180  }
181  return $this;
182  }
183 
193  public function allowAllPropertiesExcept() {
194  $this->mapUnknownProperties = TRUE;
195 
196  foreach (func_get_args() as $propertyName) {
197  $this->propertiesNotToBeMapped[$propertyName] = $propertyName;
198  }
199  return $this;
200  }
201 
209  public function skipUnknownProperties() {
210  $this->skipUnknownProperties = TRUE;
211  return $this;
212  }
213 
221  public function shouldSkipUnknownProperties() {
223  }
224 
232  public function getConfigurationFor($propertyName) {
233  if (isset($this->subConfigurationForProperty[$propertyName])) {
234  return $this->subConfigurationForProperty[$propertyName];
235  } elseif (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
236  return $this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER];
237  }
238 
239  return new PropertyMappingConfiguration();
240  }
241 
249  public function getTargetPropertyName($sourcePropertyName) {
250  if (isset($this->mapping[$sourcePropertyName])) {
251  return $this->mapping[$sourcePropertyName];
252  }
253  return $sourcePropertyName;
254  }
255 
262  public function getConfigurationValue($typeConverterClassName, $key) {
263  if (!isset($this->configuration[$typeConverterClassName][$key])) {
264  return NULL;
265  }
266 
267  return $this->configuration[$typeConverterClassName][$key];
268  }
269 
278  public function setMapping($sourcePropertyName, $targetPropertyName) {
279  $this->mapping[$sourcePropertyName] = $targetPropertyName;
280  return $this;
281  }
282 
291  public function setTypeConverterOptions($typeConverter, array $options) {
292  if (strpos($typeConverter, '_') !== FALSE) {
294  }
296  $this->configuration[$typeConverter] = $options;
297  }
298  return $this;
299  }
300 
310  public function setTypeConverterOption($typeConverter, $optionKey, $optionValue) {
311  if (strpos($typeConverter, '_') !== FALSE) {
313  }
315  $this->configuration[$typeConverter][$optionKey] = $optionValue;
316  }
317  return $this;
318  }
319 
330  $typeConverterClasses = class_parents($typeConverter);
331  $typeConverterClasses = $typeConverterClasses === FALSE ? array() : $typeConverterClasses;
332  $typeConverterClasses[] = $typeConverter;
333  return $typeConverterClasses;
334  }
335 
345  public function forProperty($propertyPath) {
346  $splittedPropertyPath = explode('.', $propertyPath);
347  return $this->traverseProperties($splittedPropertyPath);
348  }
349 
356  public function traverseProperties(array $splittedPropertyPath) {
357  if (count($splittedPropertyPath) === 0) {
358  return $this;
359  }
360 
361  $currentProperty = array_shift($splittedPropertyPath);
362  if (!isset($this->subConfigurationForProperty[$currentProperty])) {
363  $type = get_class($this);
364  if (isset($this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER])) {
365  $this->subConfigurationForProperty[$currentProperty] = clone $this->subConfigurationForProperty[self::PROPERTY_PATH_PLACEHOLDER];
366  } else {
367  $this->subConfigurationForProperty[$currentProperty] = new $type;
368  }
369  }
370  return $this->subConfigurationForProperty[$currentProperty]->traverseProperties($splittedPropertyPath);
371  }
372 
379  public function getTypeConverter() {
380  return $this->typeConverter;
381  }
382 
390  public function setTypeConverter(\TYPO3\CMS\Extbase\Property\TypeConverterInterface $typeConverter) {
391  $this->typeConverter = $typeConverter;
392  return $this;
393  }
394 }
setTypeConverterOption($typeConverter, $optionKey, $optionValue)
setTypeConverter(\TYPO3\CMS\Extbase\Property\TypeConverterInterface $typeConverter)