* @subpackage MVC\Controller
* @version $ID:$
* @scope prototype
+ * @api
*/
class Tx_Extbase_MVC_Controller_Argument {
* Data type of this argument's value
* @var string
*/
- protected $dataType = 'Text';
+ protected $dataType = NULL;
/**
* If the data type is an object, the class schema of the data type class is resolved
*/
protected $validator = NULL;
- /**
- * If validation for this argument is temporarily disabled
- * @var boolean
- */
- protected $validationDisabled = FALSE;
-
/**
* Uid for the argument, if it has one
* @var string
*/
protected $uid = NULL;
+ const ORIGIN_CLIENT = 0;
+ const ORIGIN_PERSISTENCE = 1;
+ const ORIGIN_PERSISTENCE_AND_MODIFIED = 2;
+ const ORIGIN_NEWLY_CREATED = 3;
+
+ /**
+ * The origin of the argument value. This is only meaningful after argument mapping.
+ *
+ * One of the ORIGIN_* constants above
+ * @var integer
+ */
+ protected $origin = 0;
+
/**
* Constructs this controller argument
*
* @throws InvalidArgumentException if $name is not a string or empty
* @api
*/
- public function __construct($name, $dataType = 'Text') {
+ public function __construct($name, $dataType) {
+ if (!is_string($name)) throw new InvalidArgumentException('$name must be of type string, ' . gettype($name) . ' given.', 1187951688);
+ if (strlen($name) === 0) throw new InvalidArgumentException('$name must be a non-empty string, ' . strlen($name) . ' characters given.', 1232551853);
+ $this->name = $name;
+ $this->dataType = $dataType;
+ }
+
+ /**
+ * Initializes this object
+ *
+ * @return void
+ */
+ public function initializeObject() {
$this->reflectionService = t3lib_div::makeInstance('Tx_Extbase_Reflection_Service');
$this->propertyMapper = t3lib_div::makeInstance('Tx_Extbase_Property_Mapper');
$this->propertyMapper->injectReflectionService($this->reflectionService);
- if (!is_string($name) || strlen($name) < 1) throw new InvalidArgumentException('$name must be of type string, ' . gettype($name) . ' given.', 1187951688);
- $this->name = $name;
- $this->setDataType($dataType);
+ $this->dataTypeClassSchema = (strstr($this->dataType, '_') !== FALSE) ? $this->reflectionService->getClassSchema($this->dataType) : NULL;
}
/**
*/
public function setDataType($dataType) {
$this->dataType = $dataType;
- $this->dataTypeClassSchema = $this->reflectionService->getClassSchema($this->dataType);
+ $this->dataTypeClassSchema = $this->reflectionService->getClassSchema($dataType);
return $this;
}
}
/**
- * Returns TRUE if validation is temporarily disabled for this argument and
- * FALSE if it's enabled.
+ * Get the origin of the argument value. This is only meaningful after argument mapping.
*
- * Note that this is flag is only informational and does not have any real impact
- * on other validation methods of this argument.
- *
- * @return boolean If validation is disabled
- * @api
- */
- public function isValidationDisabled() {
- return $this->validationDisabled;
- }
-
- /**
- * Enables validation for this argument.
- *
- * @return void
- * @api
+ * @return integer one of the ORIGIN_* constants
+ * @author Sebastian Kurfürst <sebastian@typo3.org>
*/
- public function enableValidation() {
- $this->validationDisabled = FALSE;
- }
-
- /**
- * Disables validation for this argument.
- *
- * @return void
- * @api
- */
- public function disableValidation() {
- $this->validationDisabled = TRUE;
+ public function getOrigin() {
+ return $this->origin;
}
/**
}
$transformedValue = NULL;
if ($this->dataTypeClassSchema !== NULL) {
- // It is an Entity or ValueObject.
+ // 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->propertyMapper->map(array_keys($value), $value, $this->dataType);
}
} else {
if (!is_array($value)) {
throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('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->propertyMapper->map(array_keys($value), $value, $this->dataType);
}
if (!($transformedValue instanceof $this->dataType)) {
- throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('The value must be of type "' . $this->dataType . '", but was of type "' . get_class($transformedValue) . '".', 1251730701);
+ if (is_object($transformedValue)) {
+ throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('The value must be of type "' . $this->dataType . '", but was of type "' . get_class($transformedValue) . '".', 1251730701);
+ } else {
+ throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('The value must be of type "' . $this->dataType . '", but was of type "' . gettype($transformedValue) . '".', 1251730702);
+ }
}
return $transformedValue;
}
*/
protected function findObjectByUid($uid) {
$query = $this->queryFactory->create($this->dataType);
+ $query->getQuerySettings()->setRespectSysLanguage(FALSE);
$result = $query->matching($query->withUid($uid))->execute();
$object = NULL;
if (count($result) > 0) {