TYPO3 CMS  TYPO3_6-2
MvcPropertyMappingConfigurationService.php
Go to the documentation of this file.
1 <?php
3 
34 
41  protected $hashService;
42 
52  public function generateTrustedPropertiesToken($formFieldNames, $fieldNamePrefix = '') {
53  $formFieldArray = array();
54  foreach ($formFieldNames as $formField) {
55  $formFieldParts = explode('[', $formField);
56  $currentPosition = &$formFieldArray;
57  for ($i = 0; $i < count($formFieldParts); $i++) {
58  $formFieldPart = $formFieldParts[$i];
59  $formFieldPart = rtrim($formFieldPart, ']');
60  if (!is_array($currentPosition)) {
61  throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException('The form field "' . $formField . '" is declared as array, but it collides with a previous form field of the same name which declared the field as string. This is an inconsistency you need to fix inside your Fluid form. (String overridden by Array)', 1255072196);
62  }
63  if ($i === count($formFieldParts) - 1) {
64  if (isset($currentPosition[$formFieldPart]) && is_array($currentPosition[$formFieldPart])) {
65  throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException('The form field "' . $formField . '" is declared as string, but it collides with a previous form field of the same name which declared the field as array. This is an inconsistency you need to fix inside your Fluid form. (Array overridden by String)', 1255072587);
66  }
67  // Last iteration - add a string
68  if ($formFieldPart === '') {
69  $currentPosition[] = 1;
70  } else {
71  $currentPosition[$formFieldPart] = 1;
72  }
73  } else {
74  if ($formFieldPart === '') {
75  throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException('The form field "' . $formField . '" is invalid. Reason: "[]" used not as last argument, but somewhere in the middle (like foo[][bar]).', 1255072832);
76  }
77  if (!isset($currentPosition[$formFieldPart])) {
78  $currentPosition[$formFieldPart] = array();
79  }
80  $currentPosition = &$currentPosition[$formFieldPart];
81  }
82  }
83  }
84  if ($fieldNamePrefix !== '') {
85  $formFieldArray = (isset($formFieldArray[$fieldNamePrefix]) ? $formFieldArray[$fieldNamePrefix] : array());
86  }
87  return $this->serializeAndHashFormFieldArray($formFieldArray);
88  }
89 
97  protected function serializeAndHashFormFieldArray(array $formFieldArray) {
98  $serializedFormFieldArray = serialize($formFieldArray);
99  return $this->hashService->appendHmac($serializedFormFieldArray);
100  }
101 
111  public function initializePropertyMappingConfigurationFromRequest(\TYPO3\CMS\Extbase\Mvc\Request $request, \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $controllerArguments) {
112  $trustedPropertiesToken = $request->getInternalArgument('__trustedProperties');
113  if (!is_string($trustedPropertiesToken)) {
114  return;
115  }
116 
117  $serializedTrustedProperties = $this->hashService->validateAndStripHmac($trustedPropertiesToken);
118  $trustedProperties = unserialize($serializedTrustedProperties);
119  foreach ($trustedProperties as $propertyName => $propertyConfiguration) {
120  if (!$controllerArguments->hasArgument($propertyName)) {
121  continue;
122  }
123  $propertyMappingConfiguration = $controllerArguments->getArgument($propertyName)->getPropertyMappingConfiguration();
124  $this->modifyPropertyMappingConfiguration($propertyConfiguration, $propertyMappingConfiguration);
125  }
126  }
127 
140  protected function modifyPropertyMappingConfiguration($propertyConfiguration, \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration) {
141  if (!is_array($propertyConfiguration)) {
142  return;
143  }
144 
145  if (isset($propertyConfiguration['__identity'])) {
146  $propertyMappingConfiguration->setTypeConverterOption('TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter', \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, TRUE);
147  unset($propertyConfiguration['__identity']);
148  } else {
149  $propertyMappingConfiguration->setTypeConverterOption('TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter', \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, TRUE);
150  }
151 
152  foreach ($propertyConfiguration as $innerKey => $innerValue) {
153  if (is_array($innerValue)) {
154  $this->modifyPropertyMappingConfiguration($innerValue, $propertyMappingConfiguration->forProperty($innerKey));
155  }
156  $propertyMappingConfiguration->allowProperties($innerKey);
157  }
158  }
159 }
modifyPropertyMappingConfiguration($propertyConfiguration, \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration $propertyMappingConfiguration)
initializePropertyMappingConfigurationFromRequest(\TYPO3\CMS\Extbase\Mvc\Request $request, \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $controllerArguments)