protected $code;
/**
+ * The message arguments. Will be replaced in the message body.
+ * @var array
+ */
+ protected $arguments = array();
+
+ /**
+ * An optional title for the message (used eg. in flashMessages).
+ * @var string
+ */
+ protected $title = '';
+
+ /**
* Constructs this error
*
* @param string $message An english error message which is used if no other error message can be resolved
* @param integer $code A unique error code
- * @author Robert Lemke <robert@typo3.org>
+ * @param array $arguments Array of arguments to be replaced in message
+ * @param string $title optional title for the message
* @api
*/
- public function __construct($message, $code) {
+ public function __construct($message, $code, array $arguments = array(), $title = '') {
$this->message = $message;
$this->code = $code;
+ $this->arguments = $arguments;
+ $this->title = $title;
}
/**
* Returns the error message
* @return string The error message
- * @author Andreas Förthner <andreas.foerthner@netlogix.de>
* @api
*/
public function getMessage() {
/**
* Returns the error code
* @return string The error code
- * @author Andreas Förthner <andreas.foerthner@netlogix.de>
* @api
*/
public function getCode() {
}
/**
+ * Get arguments
+ *
+ * @return array
+ * @api
+ */
+ public function getArguments() {
+ return $this->arguments;
+ }
+
+ /**
+ * Get title
+ *
+ * @return string
+ * @api
+ */
+ public function getTitle() {
+ return $this->title;
+ }
+
+ /**
+ * Return the rendered message
+ *
+ * @return string
+ * @api
+ */
+ public function render() {
+ if (!empty($this->arguments)) {
+ return vsprintf($this->message, $this->arguments);
+ } else {
+ return $this->message;
+ }
+ }
+
+ /**
* Converts this error into a string
*
* @return string
- * @author Robert Lemke <robert@typo3.org>
* @api
*/
public function __toString() {
- return $this->message . ' (#' . $this->code . ')';
+ return $this->render();
}
}
$message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL;
foreach ($this->arguments->getValidationResults()->getFlattenedErrors() as $propertyPath => $errors) {
foreach ($errors as $error) {
- $message .= 'Error for ' . $propertyPath . ': ' . $error->getMessage() . PHP_EOL;
+ $message .= 'Error for ' . $propertyPath . ': ' . $error->render() . PHP_EOL;
}
}
}
}
-?>
\ No newline at end of file
+?>
*
* @param string $message The error message
* @param integer $code The error code (a unix timestamp)
+ * @param array $arguments Arguments to be replaced in message
+ * @param string $title title of the error
* @return void
*/
- protected function addError($message, $code) {
+ protected function addError($message, $code, array $arguments = array(), $title = '') {
if ($this->result !== NULL) {
// backwards compatibility before Extbase 1.4.0: we cannot expect the "result" object to be there.
- $this->result->addError(new Tx_Extbase_Validation_Error($message, $code));
+ $this->result->addError(new Tx_Extbase_Validation_Error($message, $code, $arguments, $title));
}
// the following is @deprecated since Extbase 1.4.0:
- $this->errors[] = new Tx_Extbase_Validation_Error($message, $code);
+ $this->errors[] = new Tx_Extbase_Validation_Error($message, $code, $arguments, $title);
}
}
-?>
\ No newline at end of file
+?>
* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
* All rights reserved
*
-* This class is a backport of the corresponding class of FLOW3.
+* This class is a backport of the corresponding class of FLOW3.
* All credits go to the v5 team.
*
* This script is part of the TYPO3 project. The TYPO3 project is
public function isValid($value) {
$this->errors = array();
if ($value instanceof DateTime) return TRUE;
- $this->addError('The given subject was not a valid DateTime. Got: "' .gettype($value) . '"', 1238087674);
+ $this->addError('The given subject was not a valid DateTime. Got: "%1$d"', 1238087674, array(gettype($value)));
return FALSE;
}
}
}
if (!is_object($object)) {
- $messages->addError(new Tx_Extbase_Validation_Error('Object expected, ' . gettype($object) . ' given.', 1241099149));
+ $messages->addError(new Tx_Extbase_Validation_Error('Object expected, "%1$d" given.', 1241099149, array(gettype($object))));
return $messages;
}
}
}
-?>
\ No newline at end of file
+?>
}
if ($value >= $startRange && $value <= $endRange) return TRUE;
- $this->addError('The given subject was not in the valid range (' . $startRange . ' - ' . $endRange . ').', 1221561046);
+ $this->addError('The given subject was not in the valid range (%1$d - %2$d).', 1221561046, array($startRange, $endRange));
return FALSE;
}
}
* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
* All rights reserved
*
-* This class is a backport of the corresponding class of FLOW3.
+* This class is a backport of the corresponding class of FLOW3.
* All credits go to the v5 team.
*
* This script is part of the TYPO3 project. The TYPO3 project is
return FALSE;
}
if ($result === FALSE) {
- $this->addError('The regular expression "' . $this->options['regularExpression'] . '" contained an error.', 1221565131);
+ $this->addError('The regular expression "%1$d" contained an error.', 1221565131, array($this->options['regularExpression']));
return FALSE;
}
return TRUE;
* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
* All rights reserved
*
-* This class is a backport of the corresponding class of FLOW3.
+* This class is a backport of the corresponding class of FLOW3.
* All credits go to the v5 team.
*
* This script is part of the TYPO3 project. The TYPO3 project is
if ($isValid === FALSE) {
if (isset($this->options['minimum']) && isset($this->options['maximum'])) {
- $this->addError('The length of the given string was not between ' . $this->options['minimum'] . ' and ' . $this->options['maximum'] . ' characters.', 1238108067);
+ $this->addError('The length of the given string was not between %1$d and %2$d characters.', 1238108067, array($this->options['minimum'], $this->options['maximum']));
} elseif (isset($this->options['minimum'])) {
- $this->addError('The length of the given string less than ' . $this->options['minimum'] . ' characters.', 1238108068);
+ $this->addError('The length of the given string less than %1$d characters.', 1238108068, array($this->options['minimum']));
} else {
- $this->addError('The length of the given string exceeded ' . $this->options['maximum'] . ' characters.', 1238108069);
+ $this->addError('The length of the given string exceeded %1$d characters.', 1238108069, array($this->options['maximum']));
}
}