Esempio n. 1
0
 /**
  * Handle the assertation that the given result object has no errors
  *
  * @param \TYPO3\FLOW3\Error\Result $result
  * @param boolean $expectSuccess
  * @return void
  */
 protected function assertSuccess(\TYPO3\FLOW3\Error\Result $result, $expectSuccess = TRUE)
 {
     if ($expectSuccess === TRUE) {
         $this->assertFalse($result->hasErrors());
     } else {
         $this->assertTrue($result->hasErrors());
     }
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function mergeShouldMergeTwoResults()
 {
     $notice1 = $this->getMockMessage('Notice');
     $notice2 = $this->getMockMessage('Notice');
     $notice3 = $this->getMockMessage('Notice');
     $warning1 = $this->getMockMessage('Warning');
     $warning2 = $this->getMockMessage('Warning');
     $warning3 = $this->getMockMessage('Warning');
     $error1 = $this->getMockMessage('Error');
     $error2 = $this->getMockMessage('Error');
     $error3 = $this->getMockMessage('Error');
     $otherResult = new \TYPO3\FLOW3\Error\Result();
     $otherResult->addNotice($notice1);
     $otherResult->forProperty('foo.bar')->addNotice($notice2);
     $this->result->forProperty('foo')->addNotice($notice3);
     $otherResult->addWarning($warning1);
     $this->result->addWarning($warning2);
     $this->result->addWarning($warning3);
     $otherResult->forProperty('foo')->addError($error1);
     $otherResult->forProperty('foo')->addError($error2);
     $otherResult->addError($error3);
     $this->result->merge($otherResult);
     $this->assertSame(array($notice1), $this->result->getNotices(), 'Notices are not merged correctly without recursion');
     $this->assertSame(array($notice3), $this->result->forProperty('foo')->getNotices(), 'Original sub-notices are overridden.');
     $this->assertSame(array($notice2), $this->result->forProperty('foo')->forProperty('bar')->getNotices(), 'Sub-notices are not copied.');
     $this->assertSame(array($warning2, $warning3, $warning1), $this->result->getWarnings());
     $this->assertSame(array($error3), $this->result->getErrors());
     $this->assertSame(array($error1, $error2), $this->result->forProperty('foo')->getErrors());
 }
Esempio n. 3
0
 /**
  * Internal function which actually does the property mapping.
  *
  * @param mixed $source the source data to map. MUST be a simple type, NO object allowed!
  * @param string $targetType The type of the target; can be either a class name or a simple type.
  * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration Configuration for the property mapping.
  * @param array $currentPropertyPath The property path currently being mapped; used for knowing the context in case an exception is thrown.
  * @return mixed an instance of $targetType
  * @throws \TYPO3\FLOW3\Property\Exception\TypeConverterException
  * @throws \TYPO3\FLOW3\Property\Exception\InvalidPropertyMappingConfigurationException
  */
 protected function doMapping($source, $targetType, \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration, &$currentPropertyPath)
 {
     if (is_object($source) && $source instanceof $targetType) {
         return $source;
     }
     if ($source === NULL) {
         $source = '';
     }
     $typeConverter = $this->findTypeConverter($source, $targetType, $configuration);
     if (!is_object($typeConverter) || !$typeConverter instanceof \TYPO3\FLOW3\Property\TypeConverterInterface) {
         throw new Exception\TypeConverterException('Type converter for "' . $source . '" -> "' . $targetType . '" not found.');
     }
     $convertedChildProperties = array();
     foreach ($typeConverter->getSourceChildPropertiesToBeConverted($source) as $sourcePropertyName => $sourcePropertyValue) {
         $targetPropertyName = $configuration->getTargetPropertyName($sourcePropertyName);
         if (!$configuration->shouldMap($targetPropertyName)) {
             throw new Exception\InvalidPropertyMappingConfigurationException('It is not allowed to map property "' . $targetPropertyName . '". You need to use $propertyMappingConfiguration->allowProperties(\'' . $targetPropertyName . '\') to enable mapping of this property.', 1335969887);
         }
         $targetPropertyType = $typeConverter->getTypeOfChildProperty($targetType, $targetPropertyName, $configuration);
         $subConfiguration = $configuration->getConfigurationFor($targetPropertyName);
         $currentPropertyPath[] = $targetPropertyName;
         $targetPropertyValue = $this->doMapping($sourcePropertyValue, $targetPropertyType, $subConfiguration, $currentPropertyPath);
         array_pop($currentPropertyPath);
         if (!$targetPropertyValue instanceof \TYPO3\FLOW3\Error\Error) {
             $convertedChildProperties[$targetPropertyName] = $targetPropertyValue;
         }
     }
     $result = $typeConverter->convertFrom($source, $targetType, $convertedChildProperties, $configuration);
     if ($result instanceof \TYPO3\FLOW3\Error\Error) {
         $this->messages->forProperty(implode('.', $currentPropertyPath))->addError($result);
     }
     return $result;
 }
Esempio n. 4
0
 /**
  * Checks if the specified property of the given object is valid, and adds
  * found errors to the $messages object.
  *
  * @param mixed $value The value to be validated
  * @param array $validators The validators to be called on the value
  * @param \TYPO3\FLOW3\Error\Result $messages the result object to which the validation errors should be added
  * @return void
  */
 protected function checkProperty($value, $validators, \TYPO3\FLOW3\Error\Result $messages)
 {
     foreach ($validators as $validator) {
         if ($validator instanceof ObjectValidatorInterface) {
             $validator->setValidatedInstancesContainer($this->validatedInstancesContainer);
         }
         $result = $validator->validate($value);
         if ($result->hasErrors() || $result->hasNotices() || $result->hasWarnings()) {
             $messages->merge($validator->validate($value));
         }
     }
 }
Esempio n. 5
0
 /**
  * @return boolean TRUE if the argument is valid, FALSE otherwise
  * @api
  */
 public function isValid()
 {
     return !$this->validationResults->hasErrors();
 }
Esempio n. 6
0
 /**
  * Creates a new validation error object and adds it to $this->errors
  *
  * @param string $message The error message
  * @param integer $code The error code (a unix timestamp)
  * @param array $arguments Arguments to be replaced in message
  * @return void
  * @api
  */
 protected function addError($message, $code, array $arguments = array())
 {
     $this->result->addError(new \TYPO3\FLOW3\Validation\Error($message, $code, $arguments));
 }
Esempio n. 7
0
 /**
  * Merge the given Result object into this one.
  *
  * @param \TYPO3\FLOW3\Error\Result $otherResult
  * @return void
  * @api
  */
 public function merge(\TYPO3\FLOW3\Error\Result $otherResult)
 {
     if ($otherResult->hasErrors()) {
         $this->mergeProperty($otherResult, 'getErrors', 'addError');
     }
     if ($otherResult->hasWarnings()) {
         $this->mergeProperty($otherResult, 'getWarnings', 'addWarning');
     }
     if ($otherResult->hasNotices()) {
         $this->mergeProperty($otherResult, 'getNotices', 'addNotice');
     }
     foreach ($otherResult->getSubResults() as $subPropertyName => $subResult) {
         /** @var Result $subResult */
         if ($subResult->hasErrors() || $subResult->hasWarnings() || $subResult->hasNotices()) {
             $this->forProperty($subPropertyName)->merge($subResult);
         }
     }
 }