Exemplo n.º 1
0
 /**
  * @test
  */
 public function mapReturnsObjectForOldTxClasses()
 {
     /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
     $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $objectManager->expects($this->at(0))->method('get')->will($this->returnValue($this->getMock('Tx_Extbase_Tests_Fixture_TxClassWithGettersAndSetters')));
     $this->subject->_set('objectManager', $objectManager);
     $source = array('property1' => 'foo', 'property2' => 'bar');
     $expectedObject = $this->getMock('Tx_Extbase_Tests_Fixture_TxClassWithGettersAndSetters');
     $expectedObject->setProperty1($source['property1']);
     $expectedObject->setProperty2($source['property2']);
     $this->assertEquals($expectedObject, $this->subject->map(array('property1', 'property2'), $source, 'Tx_Extbase_Tests_Fixture_TxClassWithGettersAndSetters'));
 }
 /**
  * Checks if the value is a UUID or an array but should be an object, i.e.
  * the argument's data type class schema is set. If that is the case, this
  * method tries to look up the corresponding object instead.
  *
  * Additionally, it maps arrays to objects in case it is a normal object.
  *
  * @param mixed $value The value of an argument
  * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException
  * @return mixed
  * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
  */
 protected function transformValue($value)
 {
     if (!class_exists($this->dataType)) {
         return $value;
     }
     $transformedValue = NULL;
     if ($this->dataTypeClassSchema !== NULL) {
         // The target object is an Entity or ValueObject.
         if (is_numeric($value)) {
             $this->origin = self::ORIGIN_PERSISTENCE;
             $transformedValue = $this->findObjectByUid($value);
         } elseif (is_array($value)) {
             $this->origin = self::ORIGIN_PERSISTENCE_AND_MODIFIED;
             $transformedValue = $this->deprecatedPropertyMapper->map(array_keys($value), $value, $this->dataType);
         }
     } else {
         if (!is_array($value)) {
             throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException('The value was a simple type, so we could not map it to an object. Maybe the @entity or @valueobject annotations are missing?', 1251730701);
         }
         $this->origin = self::ORIGIN_NEWLY_CREATED;
         $transformedValue = $this->deprecatedPropertyMapper->map(array_keys($value), $value, $this->dataType);
     }
     if (!$transformedValue instanceof $this->dataType && ($transformedValue !== NULL || $this->isRequired())) {
         throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException('The value must be of type "' . $this->dataType . '", but was of type "' . (is_object($transformedValue) ? get_class($transformedValue) : gettype($transformedValue)) . '".' . ($this->deprecatedPropertyMapper->getMappingResults()->hasErrors() ? '<p>' . implode('<br />', $this->deprecatedPropertyMapper->getMappingResults()->getErrors()) . '</p>' : ''), 1251730702);
     }
     return $transformedValue;
 }
Exemplo n.º 3
0
 /**
  * Maps arguments delivered by the request object to the local controller arguments.
  *
  * @throws Exception\RequiredArgumentMissingException
  * @return void
  */
 protected function mapRequestArgumentsToControllerArguments()
 {
     if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
         foreach ($this->arguments as $argument) {
             $argumentName = $argument->getName();
             if ($this->request->hasArgument($argumentName)) {
                 $argument->setValue($this->request->getArgument($argumentName));
             } elseif ($argument->isRequired()) {
                 throw new \TYPO3\CMS\Extbase\Mvc\Controller\Exception\RequiredArgumentMissingException('Required argument "' . $argumentName . '" is not set for ' . $this->request->getControllerObjectName() . '->' . $this->request->getControllerActionName() . '.', 1298012500);
             }
         }
     } else {
         // @deprecated since Extbase 1.4, will be removed two versions after Extbase 6.1
         $optionalPropertyNames = array();
         $allPropertyNames = $this->arguments->getArgumentNames();
         foreach ($allPropertyNames as $propertyName) {
             if ($this->arguments[$propertyName]->isRequired() === FALSE) {
                 $optionalPropertyNames[] = $propertyName;
             }
         }
         /** @var $validator ArgumentsValidator */
         $validator = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ArgumentsValidator');
         $this->deprecatedPropertyMapper->mapAndValidate($allPropertyNames, $this->request->getArguments(), $this->arguments, $optionalPropertyNames, $validator);
         $this->argumentsMappingResults = $this->deprecatedPropertyMapper->getMappingResults();
     }
 }