public function getLanguageItem(): string
{
if ($this->languageItem === null) {
- throw new \BadMethodCallException("Language item has not been set yet.");
+ throw new \BadMethodCallException("Language item has not been set yet for node '{$this->getId()}'.");
}
return $this->languageItem;
if ($languageItem === null) {
if (!empty($variables)) {
throw new \InvalidArgumentException(
- "Cannot use variables when unsetting description of element '{$this->getId()}'"
+ "Cannot use variables when unsetting description of element '{$this->getId()}'."
);
}
} else {
if (!\is_string($languageItem)) {
throw new \InvalidArgumentException(
- "Given description language item is no string, " . \gettype($languageItem) . " given."
+ "Given description language item is no string, " . \gettype($languageItem) . " given for element '{$this->getId()}'."
);
}
if ($languageItem === null) {
if (!empty($variables)) {
throw new \InvalidArgumentException(
- "Cannot use variables when unsetting label of element '{$this->getId()}'"
+ "Cannot use variables when unsetting label of element '{$this->getId()}'."
);
}
} else {
if (!\is_string($languageItem)) {
throw new \InvalidArgumentException(
- "Given label language item is no string, " . \gettype($languageItem) . " given."
+ "Given label language item is no string, " . \gettype($languageItem) . " given for element '{$this->getId()}'."
);
}
static::validateAttribute($name);
if ($value !== null && !\is_bool($value) && !\is_numeric($value) && !\is_string($value)) {
- throw new \InvalidArgumentException("Value argument is of invalid type, " . \gettype($value) . ".");
+ throw new \InvalidArgumentException(
+ "Value argument is of invalid type, " . \gettype($value) . " for node '{$this->getId()}'."
+ );
}
$this->attributes[$name] = $value;
public function getAttribute($name)
{
if (!$this->hasAttribute($name)) {
- throw new \InvalidArgumentException("Unknown attribute '{$name}' requested.");
+ throw new \InvalidArgumentException("Unknown attribute '{$name}' requested for node '{$this->getId()}'.");
}
return $this->attributes[$name];
static::validateId($id);
if ($this->id !== null) {
- throw new \BadMethodCallException("Id has already been set.");
+ throw new \BadMethodCallException("Id has already been set for node '{$this->getId()}'.");
}
$this->id = $id;
public function populate()
{
if ($this->isPopulated) {
- throw new \BadMethodCallException('Node has already been populated');
+ throw new \BadMethodCallException("Node '{$this->getId()}' has already been populated.");
}
$this->isPopulated = true;
/** @var IFormField $field */
$field = $this->getDocument()->getNodeById($dependency->getFieldId());
if ($field === null) {
- throw new \UnexpectedValueException("Unknown field with id '{$dependency->getFieldId()}' for dependency '{$dependency->getId()}'.");
+ throw new \UnexpectedValueException(
+ "Unknown field with id '{$dependency->getFieldId()}' for dependency '{$dependency->getId()}' for node '{$this->getId()}'."
+ );
}
$dependency->field($field);
}
}
- throw new \InvalidArgumentException("Unknown dependency with id '{$dependencyId}'.");
+ throw new \InvalidArgumentException(
+ "Unknown dependency with id '{$dependencyId}' for node '{$this->getId()}'."
+ );
}
/**
}
if (!$didInsertNode) {
- throw new \InvalidArgumentException("Unknown child node with id '{$referenceNodeId}'.");
+ throw new \InvalidArgumentException(
+ "Unknown child node with id '{$referenceNodeId}' for node '{$this->getId()}'."
+ );
}
return $this;
}
if (!$didInsertNode) {
- throw new \InvalidArgumentException("Unknown child node with id '{$referenceNodeId}'.");
+ throw new \InvalidArgumentException(
+ "Unknown child node with id '{$referenceNodeId}' for node '{$this->getId()}'."
+ );
}
return $this;
public function getObjectType()
{
if ($this->objectType === null) {
- throw new \BadMethodCallException("Object type has not been set.");
+ throw new \BadMethodCallException("Object type has not been set for field '{$this->getId()}'.");
}
return $this->objectType;
public function objectType($objectType)
{
if ($this->objectType !== null) {
- throw new \BadMethodCallException("Object type has already been set.");
+ throw new \BadMethodCallException("Object type has already been set for field '{$this->getId()}'.");
}
if (ObjectTypeCache::getInstance()->getDefinitionByName($this->getObjectTypeDefinition()) === null) {
- throw new \UnexpectedValueException("Unknown definition name '{$this->getObjectTypeDefinition()}'.");
+ throw new \UnexpectedValueException(
+ "Unknown definition name '{$this->getObjectTypeDefinition()}' for field '{$this->getId()}'."
+ );
}
$this->objectType = ObjectTypeCache::getInstance()
public function getWysiwygId()
{
if ($this->wysiwygId === null) {
- throw new \BadMethodCallException("The id of the related 'WysiwygFormField' form field is unknown.");
+ throw new \BadMethodCallException("The id of the related 'WysiwygFormField' form field is unknown for node '{$this->getId()}'.");
}
return $this->wysiwygId;
public function application($application)
{
if (ApplicationHandler::getInstance()->getApplication($application) === null) {
- throw new \InvalidArgumentException("Unknown application with abbreviation '{$application}'.");
+ throw new \InvalidArgumentException(
+ "Unknown application with abbreviation '{$application}' for node '{$this->getId()}'."
+ );
}
$this->application = $application;
public function getTemplateName()
{
if ($this->templateName === null) {
- throw new \BadMethodCallException("Template name has not been set yet.");
+ throw new \BadMethodCallException(
+ "Template name has not been set yet for node '{$this->getId()}'."
+ );
}
return $this->templateName;
foreach ($splitAccessKey as $accessKey) {
if (\mb_strlen($accessKey) !== 1) {
throw new \InvalidArgumentException(
- "The given access key contains an access key longer than one character: '{$accessKey}'."
+ "The given access key contains an access key longer than one character: '{$accessKey}' for buttom '{$this->getId()}'."
);
}
}
if ($this instanceof ITabMenuFormContainer) {
if (!($child instanceof ITabFormContainer)) {
- throw new \InvalidArgumentException("Cannot append non-tab container " . \get_class($child) . "('{$child->getId()}') to tab menu container '{$this->getId()}'");
+ throw new \InvalidArgumentException(
+ "Cannot append non-tab container " . \get_class($child)
+ . "('{$child->getId()}') to container '{$this->getId()}'"
+ );
}
if ($child instanceof ITabMenuFormContainer) {
if ($this->getParent() instanceof ITabMenuFormContainer) {
- throw new \InvalidArgumentException("Tab menus can only be nested once.");
+ throw new \InvalidArgumentException(
+ "Tab menus can only be nested once for container '{$this->getId()}'."
+ );
}
}
} elseif ($child instanceof ITabFormContainer) {
}
if ($this instanceof ITabFormContainer && !($child instanceof IFormContainer)) {
- throw new \InvalidArgumentException("Child " . \get_class($child) . "('{$child->getId()}') has to be a form container to be appended to tab container '{$this->getId()}'.");
+ throw new \InvalidArgumentException(
+ "Child " . \get_class($child)
+ . "('{$child->getId()}') has to be a form container to be appended to tab container '{$this->getId()}'."
+ );
}
if ($child instanceof ITabMenuFormContainer) {
&& $parent = $parent->getParent()
) {
if ($parent instanceof ITabMenuFormContainer) {
- throw new \InvalidArgumentException("A tab menu container may only have another tab menu container as a parent, not as an earlier ancestor.");
+ throw new \InvalidArgumentException(
+ "A tab menu container may only have another tab menu container as a parent, not as an earlier ancestor for container '{$this->getId()}'."
+ );
}
}
}
{
if ((!$child instanceof IFormField)) {
throw new \InvalidArgumentException(
- "'" . static::class . "' only supports '" . IFormField::class . "' instances as children."
+ "'" . static::class . "' only supports '" . IFormField::class . "' instances as children for container '{$this->getId()}'."
);
}
public function field(IFormField $formField)
{
if ($this->field !== null) {
- throw new \BadMethodCallException('Field has already been set.');
+ throw new \BadMethodCallException("Field has already been set for container '{$this->getId()}'.");
}
$this->field = $formField;
public function getField()
{
if ($this->field === null) {
- throw new \BadMethodCallException('Field has not been set yet.');
+ throw new \BadMethodCallException("Field has not been set yet for container '{$this->getId()}'.");
}
return $this->field;
public function getSelectedSuffixOption()
{
if ($this->getSuffixField() === null) {
- throw new \BadMethodCallException('There is no suffix field for which a label could be determined.');
+ throw new \BadMethodCallException(
+ "There is no suffix field for which a label could be determined for container '{$this->getId()}'."
+ );
}
if (empty($this->getSuffixField()->getOptions())) {
- throw new \BadMethodCallException('The suffix field has no options.');
+ throw new \BadMethodCallException(
+ "The suffix field has no options for container '{$this->getId()}'."
+ );
}
foreach ($this->getSuffixField()->getNestedOptions() as $option) {
}
}
- throw new \RuntimeException('Cannot determine selected suffix option.');
+ throw new \RuntimeException(
+ "Cannot determine selected suffix option for container '{$this->getId()}'."
+ );
}
/**
public function getSuffixLabel()
{
if ($this->getSuffixField() === null) {
- throw new \BadMethodCallException('There is no suffix field for which a label could be determined.');
+ throw new \BadMethodCallException(
+ "There is no suffix field for which a label could be determined for container '{$this->getId()}'."
+ );
}
if (empty($this->getSuffixField()->getOptions())) {
public function suffixField(ISelectionFormField $formField)
{
if ($this->suffixField !== null) {
- throw new \BadMethodCallException('Suffix field has already been set.');
+ throw new \BadMethodCallException(
+ "Suffix field has already been set for container '{$this->getId()}'."
+ );
}
$this->suffixField = $formField;
public function attachmentData($objectType = null, $parentObjectID = 0)
{
if ($this->attachmentField !== null) {
- throw new \BadMethodCallException("The attachment form field has already been initialized. Use the atatchment form field directly to manipulate attachment data.");
+ throw new \BadMethodCallException("The attachment form field '{$this->getId()}' has already been initialized. Use the atatchment form field directly to manipulate attachment data.");
}
if ($objectType === null) {
$objectType
) === null
) {
- throw new \InvalidArgumentException("Unknown attachment object type '{$objectType}'.");
+ throw new \InvalidArgumentException("Unknown attachment object type '{$objectType}' for container '{$this->getId()}'.");
}
$this->attachmentData = [
{
if ($this->isPopulated) {
throw new \BadMethodCallException(
- 'Enabling and disabling the preview button is only possible before the form has been built.'
+ "Enabling and disabling the preview button is only possible before the form has been built for container '{$this->getId()}'."
);
}
{
if ($this->attachmentField === null) {
throw new \BadMethodCallException(
- "Wysiwyg form field can only be requested after the form has been built."
+ "Wysiwyg form field can only be requested after the form has been built for container '{$this->getId()}'."
);
}
{
if ($this->pollContainer === null) {
throw new \BadMethodCallException(
- "Wysiwyg form field can only be requested after the form has been built."
+ "Wysiwyg form field can only be requested after the form has been built for container '{$this->getId()}'."
);
}
{
if ($this->settingsContainer === null) {
throw new \BadMethodCallException(
- "Wysiwyg form field can only be requested after the form has been built."
+ "Wysiwyg form field can only be requested after the form has been built for container '{$this->getId()}'."
);
}
{
if ($this->smiliesContainer === null) {
throw new \BadMethodCallException(
- "Smilies form field container can only be requested after the form has been built."
+ "Smilies form field container can only be requested after the form has been built for container '{$this->getId()}'."
);
}
{
if ($this->wysiwygField === null) {
throw new \BadMethodCallException(
- "Wysiwyg form field can only be requested after the form has been built."
+ "Wysiwyg form field can only be requested after the form has been built for container '{$this->getId()}'."
);
}
$messageObjectType
) === null
) {
- throw new \InvalidArgumentException("Unknown message object type '{$messageObjectType}'.");
+ throw new \InvalidArgumentException(
+ "Unknown message object type '{$messageObjectType}' for container '{$this->getId()}'."
+ );
}
if ($this->wysiwygField !== null) {
public function pollObjectType($pollObjectType)
{
if (ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.poll', $pollObjectType) === null) {
- throw new \InvalidArgumentException("Unknown poll object type '{$pollObjectType}'.");
+ throw new \InvalidArgumentException(
+ "Unknown poll object type '{$pollObjectType}' for container '{$this->getId()}'."
+ );
}
if ($this->pollContainer !== null) {
public function getEndTimeField()
{
if ($this->endTimeField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->endTimeField;
public function getIsChangeableField()
{
if ($this->isChangeableField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->isChangeableField;
public function getIsPublicField()
{
if ($this->isPublicField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->isPublicField;
public function getMaxVotesField()
{
if ($this->maxVotesField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->maxVotesField;
public function getOptionsField()
{
if ($this->optionsField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->optionsField;
public function getQuestionField()
{
if ($this->questionField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->questionField;
public function getResultsRequireVoteField()
{
if ($this->resultsRequireVoteField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->resultsRequireVoteField;
public function getSortByVotesField()
{
if ($this->sortByVotesField === null) {
- throw new \BadMethodCallException("Poll form field can only be requested after the form has been built.");
+ throw new \BadMethodCallException(
+ "Poll form field can only be requested after the form has been built for container '{$this->getId()}'."
+ );
}
return $this->sortByVotesField;
--- /dev/null
+<?php
+
+namespace wcf\system\form\builder\exception;
+
+use wcf\system\form\builder\field\IFormField;
+
+/**
+ * Exception to throw if an invalid value is given for a form field.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Form\Builder
+ * @since 5.5
+ */
+class InvalidFormFieldValue extends \InvalidArgumentException
+{
+ public function __construct(IFormField $field, string $expectedValue, string $givenValue)
+ {
+ parent::__construct("Given value is no {$expectedValue}, {$givenValue} given for field '{$field->getId()}'.");
+ }
+}
public function addValidator(IFormFieldValidator $validator)
{
if ($this->hasValidator($validator->getId())) {
- throw new \InvalidArgumentException("Validator with id '{$validator->getId()}' already exists.");
+ throw new \InvalidArgumentException("Validator with id '{$validator->getId()}' already exists for field '{$this->getId()}'.");
}
$this->validators[$validator->getId()] = $validator;
public function removeValidator($validatorId)
{
if (!$this->hasValidator($validatorId)) {
- throw new \InvalidArgumentException("Unknown validator with id '{$validatorId}'");
+ throw new \InvalidArgumentException("Unknown validator with id '{$validatorId}' for field '{$this->getId()}'.");
}
unset($this->validators[$validatorId]);
namespace wcf\system\form\builder\field;
+use wcf\system\form\builder\exception\InvalidFormFieldValue;
use wcf\system\form\builder\field\validation\FormFieldValidationError;
/**
if ($step !== null) {
if ($this->integerValues) {
if (!\is_int($step)) {
- throw new \InvalidArgumentException("Given step is no int, '" . \gettype($step) . "' given.");
+ throw new \InvalidArgumentException(
+ "Given step is no int, '" . \gettype($step) . "' given for field '{$this->getId()}'."
+ );
}
} else {
if (\is_string($step) && $step !== 'any') {
- throw new \InvalidArgumentException("The only valid step value is 'any', '" . $step . "' given.");
+ throw new \InvalidArgumentException(
+ "The only valid step value is 'any', '" . $step . "' given for field '{$this->getId()}'."
+ );
} elseif (!\is_numeric($step)) {
- throw new \InvalidArgumentException("Given step is no number, '" . \gettype($step) . "' given.");
+ throw new \InvalidArgumentException(
+ "Given step is no number, '" . \gettype($step) . "' given for field '{$this->getId()}'."
+ );
}
}
}
}
if ($this->integerValues && !\is_int($value)) {
- throw new \InvalidArgumentException(
- "Given value is neither `null` nor an int, " . \gettype($value) . " given."
- );
+ throw new InvalidFormFieldValue($this, 'int or `null`', \gettype($value));
} elseif (!$this->integerValues && !\is_numeric($value)) {
- throw new \InvalidArgumentException(
- "Given value is neither `null` nor a number, " . \gettype($value) . " given."
- );
+ throw new InvalidFormFieldValue($this, 'number or `null`', \gettype($value));
}
}
namespace wcf\system\form\builder\field;
+use wcf\system\form\builder\exception\InvalidFormFieldValue;
use wcf\system\form\builder\field\validation\FormFieldValidationError;
/**
if (\is_int($value) && ($value === 0 || $value === 1)) {
$value = ($value === 1);
} elseif (!\is_bool($value)) {
- throw new \InvalidArgumentException("Given value is no bool, " . \gettype($value) . " given.");
+ throw new InvalidFormFieldValue($this, 'bool', \gettype($value));
}
return parent::value($value);
public function getButtonLabel(): string
{
if ($this->buttonLabel === null) {
- throw new \BadMethodCallException("Button label has not been set.");
+ throw new \BadMethodCallException("Button label has not been set for field '{$this->getId()}'.");
}
return $this->buttonLabel;
public function implementedInterface($interface)
{
if (!\interface_exists($interface)) {
- throw new \InvalidArgumentException("Interface '{$interface}' does not exist.");
+ throw new \InvalidArgumentException("Interface '{$interface}' does not exist for field '{$this->getId()}'.");
}
$this->implementedInterface = $interface;
public function parentClass($parentClass)
{
if (!\class_exists($parentClass)) {
- throw new \InvalidArgumentException("Class '{$parentClass}' does not exist.");
+ throw new \InvalidArgumentException("Class '{$parentClass}' does not exist for field '{$this->getId()}'.");
}
$this->parentClass = $parentClass;
new \DateTimeZone('UTC')
);
if ($earliestDateTime === false) {
- throw new \InvalidArgumentException("Earliest date '{$this->earliestDate}' does not have save value format '{$this->getSaveValueFormat()}'.");
+ throw new \InvalidArgumentException(
+ "Earliest date '{$this->earliestDate}' does not have save value format '{$this->getSaveValueFormat()}' for field '{$this->getId()}'."
+ );
}
if ($this->getLatestDate() !== null) {
);
if ($latestDateTime < $earliestDateTime) {
- throw new \InvalidArgumentException("Earliest date '{$this->earliestDate}' cannot be later than latest date '{$this->getLatestDate()}'.");
+ throw new \InvalidArgumentException(
+ "Earliest date '{$this->earliestDate}' cannot be later than latest date '{$this->getLatestDate()}' for field '{$this->getId()}'."
+ );
}
}
}
);
if ($latestDateTime === false) {
- throw new \InvalidArgumentException("Latest date '{$this->latestDate}' does not have save value format '{$this->getSaveValueFormat()}'.");
+ throw new \InvalidArgumentException(
+ "Latest date '{$this->latestDate}' does not have save value format '{$this->getSaveValueFormat()}' for field '{$this->getId()}'."
+ );
}
if ($this->getEarliestDate() !== null) {
);
if ($latestDateTime < $earliestDateTime) {
- throw new \InvalidArgumentException("Latest date '{$this->latestDate}' cannot be earlier than earliest date '{$this->getEarliestDate()}'.");
+ throw new \InvalidArgumentException(
+ "Latest date '{$this->latestDate}' cannot be earlier than earliest date '{$this->getEarliestDate()}' for field '{$this->getId()}'."
+ );
}
}
}
public function saveValueFormat($saveValueFormat)
{
if ($this->saveValueFormat !== null) {
- throw new \BadMethodCallException("Save value type has already been set.");
+ throw new \BadMethodCallException("Save value type has already been set for field '{$this->getId()}'.");
}
$this->saveValueFormat = $saveValueFormat;
public function supportTime($supportsTime = true)
{
if ($this->value !== null) {
- throw new \BadFunctionCallException("After a value has been set, time support cannot be changed.");
+ throw new \BadFunctionCallException(
+ "After a value has been set, time support cannot be changed for field '{$this->getId()}'."
+ );
}
$this->supportsTime = $supportsTime;
new \DateTimeZone('UTC')
);
if ($dateTime === false) {
- throw new \InvalidArgumentException("Given value does not match format '{$this->getSaveValueFormat()}'.");
+ throw new \InvalidArgumentException(
+ "Given value does not match format '{$this->getSaveValueFormat()}' for field '{$this->getId()}'."
+ );
}
if ($this->supportsTime()) {
namespace wcf\system\form\builder\field;
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
+use wcf\system\form\builder\exception\InvalidFormFieldValue;
use wcf\system\form\builder\field\validation\FormFieldValidationError;
use wcf\system\form\builder\IFormDocument;
use wcf\util\ArrayUtil;
public function saveValueType($saveValueType)
{
if ($this->saveValueType !== null) {
- throw new \BadMethodCallException("Save value type has already been set.");
+ throw new \BadMethodCallException("Save value type has already been set for field '{$this->getId()}'.");
}
if (
self::SAVE_VALUE_TYPE_SSV,
])
) {
- throw new \InvalidArgumentException("Unknown save value type '{$saveValueType}'.");
+ throw new \InvalidArgumentException("Unknown save value type '{$saveValueType}' for field '{$this->getId()}'.");
}
$this->saveValueType = $saveValueType;
if (\is_array($value)) {
$this->value = $value;
} else {
- throw new \InvalidArgumentException("Given value is no array, '" . \gettype($value) . "' given.");
+ throw new InvalidFormFieldValue($this, 'array', \gettype($value));
}
break;
if (\is_string($value)) {
$this->value = \explode(',', $value);
} else {
- throw new \InvalidArgumentException("Given value is no string, '" . \gettype($value) . "' given.");
+ throw new InvalidFormFieldValue($this, 'string', \gettype($value));
}
break;
if (\is_string($value)) {
$this->value = \explode("\n", $value);
} else {
- throw new \InvalidArgumentException("Given value is no string, '" . \gettype($value) . "' given.");
+ throw new InvalidFormFieldValue($this, 'string', \gettype($value));
}
break;
if (\is_string($value)) {
$this->value = \explode(' ', $value);
} else {
- throw new \InvalidArgumentException("Given value is no string, '" . \gettype($value) . "' given.");
+ throw new InvalidFormFieldValue($this, 'string', \gettype($value));
}
break;
public function rows($rows)
{
if ($rows <= 0) {
- throw new \InvalidArgumentException("Given number of rows is not positive.");
+ throw new \InvalidArgumentException("Given number of rows is not positive for field '{$this->getId()}'.");
}
$this->rows = $rows;
namespace wcf\system\form\builder\field;
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
+use wcf\system\form\builder\exception\InvalidFormFieldValue;
use wcf\system\form\builder\field\validation\FormFieldValidationError;
use wcf\system\form\builder\IFormDocument;
}
if (!\is_array($value)) {
- throw new \InvalidArgumentException("Given value is no array, " . \gettype($value) . " given.");
+ throw new InvalidFormFieldValue($this, 'array', \gettype($value));
}
$unknownValues = \array_diff($value, \array_keys($this->getOptions()));
if (!empty($unknownValues)) {
- throw new \InvalidArgumentException("Unknown values '" . \implode("', '", $unknownValues) . "'");
+ throw new \InvalidArgumentException(
+ "Unknown values '" . \implode("', '", $unknownValues) . "' for field '{$this->getId()}'."
+ );
}
return parent::value($value);
public function activeCssClasses(array $cssClasses)
{
if (empty($cssClasses)) {
- throw new \InvalidArgumentException("No css classes for active state given.");
+ throw new \InvalidArgumentException("No css classes for active state given for field '{$this->getId()}'.");
}
foreach ($cssClasses as $cssClass) {
public function defaultCssClasses(array $cssClasses)
{
if (empty($cssClasses)) {
- throw new \InvalidArgumentException("No css classes for default state given.");
+ throw new \InvalidArgumentException("No css classes for default state given for field '{$this->getId()}'.");
}
foreach ($cssClasses as $cssClass) {
public function maximum($maximum = null)
{
if ($maximum === null) {
- throw new \InvalidArgumentException("Cannot unset maximum value.");
+ throw new \InvalidArgumentException("Cannot unset maximum value for field '{$this->getId()}'.");
}
return $this->traitMaximum($maximum);
public function minimum($minimum = null)
{
if ($minimum === null) {
- throw new \InvalidArgumentException("Cannot unset minimum value.");
+ throw new \InvalidArgumentException("Cannot unset minimum value for field '{$this->getId()}'.");
}
return $this->traitMinimum($minimum);
*/
public function getSaveValue(): void
{
- throw new \BadMethodCallException('This form field rejects everything.');
+ throw new \BadMethodCallException("Form field '{$this->getId()}' rejects everything.");
}
/**
}
if (!isset($this->getOptions()[$value])) {
- throw new \InvalidArgumentException("Unknown value '{$value}'");
+ throw new \InvalidArgumentException("Unknown value '{$value}' for field '{$this->getId()}'.");
}
return parent::value($value);
public function language(?string $language): self
{
if (!\in_array($language, self::LANGUAGES)) {
- throw new \InvalidArgumentException("Unsupported language '{$language}' given.");
+ throw new \InvalidArgumentException(
+ "Unsupported language '{$language}' given for field '{$this->getId()}'."
+ );
}
$this->language = $language;
public function getFieldAttribute(string $name)
{
if (!$this->hasFieldAttribute($name)) {
- throw new \InvalidArgumentException("Unknown attribute '{$name}' requested.");
+ throw new \InvalidArgumentException("Unknown attribute '{$name}' requested for field '{$this->getId()}'.");
}
return $this->fieldAttributes[$name];
if ($autoComplete !== null && $autoComplete !== 'on' && $autoComplete !== 'off') {
if (\preg_match('~^(?:section-\w+ )?(?:(shipping|billing) )?(?P<token>.+)$~', $autoComplete, $matches)) {
if (!\in_array($matches['token'], $this->getValidAutoCompleteTokens())) {
- throw new \InvalidArgumentException("Invalid autocomplete attribute '{$autoComplete}'.");
+ throw new \InvalidArgumentException(
+ "Invalid autocomplete attribute '{$autoComplete}' for field '{$this->getId()}'."
+ );
}
} else {
- throw new \InvalidArgumentException("Invalid autocomplete attribute '{$autoComplete}'.");
+ throw new \InvalidArgumentException(
+ "Invalid autocomplete attribute '{$autoComplete}' for field '{$this->getId()}'."
+ );
}
}
use wcf\data\IStorableObject;
use wcf\data\language\item\LanguageItemList;
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
+use wcf\system\form\builder\exception\InvalidFormFieldValue;
use wcf\system\form\builder\field\validation\FormFieldValidationError;
use wcf\system\form\builder\IFormDocument;
use wcf\system\form\builder\IFormNode;
{
if (!$this->isI18n()) {
throw new \BadMethodCallException(
- "You can only get the language item pattern for fields with i18n enabled."
+ "You can only get the language item pattern for fields with i18n enabled for field '{$this->getId()}'."
);
}
if ($this->languageItemPattern === null) {
- throw new \BadMethodCallException("Language item pattern has not been set.");
+ throw new \BadMethodCallException("Language item pattern has not been set for field '{$this->getId()}'.");
}
return $this->languageItemPattern;
{
if (!$this->isI18n()) {
throw new \BadMethodCallException(
- "The language item pattern can only be set for fields with i18n enabled."
+ "The language item pattern can only be set for fields with i18n enabled for field '{$this->getId()}'."
);
}
if (!Regex::compile($pattern)->isValid()) {
- throw new \InvalidArgumentException("Given pattern is invalid.");
+ throw new \InvalidArgumentException("Given pattern is invalid for field '{$this->getId()}'.");
}
$this->languageItemPattern = $pattern;
I18nHandler::getInstance()->setValues($this->getPrefixedId(), $value);
}
} else {
- throw new \InvalidArgumentException(
- "Given value is neither a nor an array, " . \gettype($value) . " given."
- );
+ throw new InvalidFormFieldValue($this, 'string/number/array', \gettype($value));
}
} else {
if (!\is_string($value) && !\is_numeric($value)) {
- throw new \InvalidArgumentException("Given value is no string, " . \gettype($value) . " given.");
+ throw new InvalidFormFieldValue($this, 'string/number', \gettype($value));
}
return parent::value($value);
public function inputMode(?string $inputMode)
{
if ($inputMode !== null && $inputMode !== 'none' && !\in_array($inputMode, $this->getValidInputModes())) {
- throw new \InvalidArgumentException("Invalid inputmode attribute '{$inputMode}'.");
+ throw new \InvalidArgumentException("Invalid inputmode attribute '{$inputMode}' for field '{$this->getId()}'.");
}
$this->inputMode = $inputMode;
{
if ($maximum !== null) {
if (!\is_numeric($maximum)) {
- throw new \InvalidArgumentException("Given maximum is no int, '" . \gettype($maximum) . "' given.");
+ throw new \InvalidArgumentException(
+ "Given maximum is no int, '" . \gettype($maximum) . "' given for field '{$this->getId()}'."
+ );
}
if ($this instanceof IMinimumFormField) {
$minimum = $this->getMinimum();
if ($minimum !== null && $minimum > $maximum) {
throw new \InvalidArgumentException(
- "Minimum ({$minimum}) cannot be greater than maximum ({$maximum})."
+ "Minimum ({$minimum}) cannot be greater than maximum ({$maximum}) for field '{$this->getId()}'."
);
}
}
if ($maximumLength !== null) {
if (!\is_int($maximumLength)) {
throw new \InvalidArgumentException(
- "Given maximum length is no int, '" . \gettype($maximumLength) . "' given."
+ "Given maximum length is no int, '" . \gettype($maximumLength) . "' given for field '{$this->getId()}'."
);
}
if ($maximumLength <= 0) {
- throw new \InvalidArgumentException("Maximum length must be positive, '{$maximumLength}' given.");
+ throw new \InvalidArgumentException(
+ "Maximum length must be positive, '{$maximumLength}' given for field '{$this->getId()}'."
+ );
}
if ($this instanceof IMinimumLengthFormField) {
$minimumLength = $this->getMinimumLength();
if ($minimumLength !== null && $minimumLength > $maximumLength) {
throw new \InvalidArgumentException(
- "Minimum length ({$minimumLength}) cannot be greater than maximum length ({$maximumLength})."
+ "Minimum length ({$minimumLength}) cannot be greater than maximum length ({$maximumLength}) for field '{$this->getId()}'."
);
}
}
{
if ($minimum !== null) {
if (!\is_numeric($minimum)) {
- throw new \InvalidArgumentException("Given minimum is no int, '" . \gettype($minimum) . "' given.");
+ throw new \InvalidArgumentException(
+ "Given minimum is no int, '" . \gettype($minimum) . "' given for field '{$this->getId()}'."
+ );
}
if ($this instanceof IMaximumFormField) {
$maximum = $this->getMaximum();
if ($maximum !== null && $minimum > $maximum) {
throw new \InvalidArgumentException(
- "Minimum ({$minimum}) cannot be greater than maximum ({$maximum})."
+ "Minimum ({$minimum}) cannot be greater than maximum ({$maximum}) for field '{$this->getId()}'."
);
}
}
if ($minimumLength !== null) {
if (!\is_int($minimumLength)) {
throw new \InvalidArgumentException(
- "Given minimum length is no int, '" . \gettype($minimumLength) . "' given."
+ "Given minimum length is no int, '" . \gettype($minimumLength) . "' given for field '{$this->getId()}'."
);
}
if ($minimumLength < 0) {
- throw new \InvalidArgumentException("Minimum length must be non-negative, '{$minimumLength}' given.");
+ throw new \InvalidArgumentException(
+ "Minimum length must be non-negative, '{$minimumLength}' given for field '{$this->getId()}'."
+ );
}
if ($this instanceof IMaximumLengthFormField) {
$maximumLength = $this->getMaximumLength();
if ($maximumLength !== null && $minimumLength > $maximumLength) {
throw new \InvalidArgumentException(
- "Minimum length ({$minimumLength}) cannot be greater than maximum length ({$maximumLength})."
+ "Minimum length ({$minimumLength}) cannot be greater than maximum length ({$maximumLength}) for field '{$this->getId()}'."
);
}
}
if ($maximum !== IMultipleFormField::NO_MAXIMUM_MULTIPLES) {
if ($maximum <= 0) {
throw new \InvalidArgumentException(
- "The maximum number of values has to be positive, '{$maximum}' given."
+ "The maximum number of values has to be positive, '{$maximum}' given for field '{$this->getId()}'."
);
}
if ($this->getMinimumMultiples() !== 0 && $maximum < $this->getMinimumMultiples()) {
- throw new \InvalidArgumentException("The given maximum number of values '{$maximum}' is less than the set minimum number of values '{$this->getMinimumMultiples()}'.");
+ throw new \InvalidArgumentException(
+ "The given maximum number of values '{$maximum}' is less than the set minimum number of values '{$this->getMinimumMultiples()}'. for field '{$this->getId()}'"
+ );
}
}
{
if ($minimum < 0) {
throw new \InvalidArgumentException(
- "The minimum number of values has to be non-negative, '{$minimum}' given."
+ "The minimum number of values has to be non-negative, '{$minimum}' given for field '{$this->getId()}'."
);
}
if ($this->getMaximumMultiples() !== IMultipleFormField::NO_MAXIMUM_MULTIPLES && $minimum > $this->getMaximumMultiples()) {
- throw new \InvalidArgumentException("The given minimum number of values '{$minimum}' is greater than the set maximum number of values '{$this->getMaximumMultiples()}'.");
+ throw new \InvalidArgumentException(
+ "The given minimum number of values '{$minimum}' is greater than the set maximum number of values '{$this->getMaximumMultiples()}' for field '{$this->getId()}'."
+ );
}
$this->minimumMultiples = $minimum;
{
foreach ($packageIDs as $packageID) {
if (PackageCache::getInstance()->getPackage($packageID) === null) {
- throw new \InvalidArgumentException("Unknown package with id '{$packageID}'.");
+ throw new \InvalidArgumentException("Unknown package with id '{$packageID}' for field '{$this->getId()}'.");
}
}
} else {
if (!\is_string($languageItem)) {
throw new \InvalidArgumentException(
- "Given placeholder language item is no string, " . \gettype($languageItem) . " given."
+ "Given placeholder language item is no string, " . \gettype($languageItem) . " given for field '{$this->getId()}'."
);
}
public function getNestedOptions()
{
if (!$this->supportsNestedOptions()) {
- throw new \BadMethodCallException("Nested options are not supported.");
+ throw new \BadMethodCallException("Nested options are not supported for field '{$this->getId()}'.");
}
return $this->nestedOptions;
public function getOptions()
{
if ($this->options === null) {
- throw new \BadMethodCallException("No options have been set.");
+ throw new \BadMethodCallException("No options have been set for field '{$this->getId()}'.");
}
return $this->options;
if ($nestedOptions) {
if (!\is_array($options) && !($options instanceof \Traversable) && !\is_callable($options)) {
throw new \InvalidArgumentException(
- "The given nested options are neither iterable nor a callable, " . \gettype($options) . " given."
+ "The given nested options are neither iterable nor a callable, " . \gettype($options) . " given for field '{$this->getId()}'."
);
}
} elseif (!\is_array($options) && !($options instanceof \Traversable) && !\is_callable($options)) {
throw new \InvalidArgumentException(
- "The given options are neither iterable nor a callable, " . \gettype($options) . " given."
+ "The given options are neither iterable nor a callable, " . \gettype($options) . " given for field '{$this->getId()}'."
);
}
if ($nestedOptions) {
if (!\is_array($options) && !($options instanceof \Traversable)) {
- throw new \UnexpectedValueException("The nested options callable is expected to return an iterable value, " . \gettype($options) . " returned.");
+ throw new \UnexpectedValueException(
+ "The nested options callable is expected to return an iterable value, " . \gettype($options) . " returned for field '{$this->getId()}'."
+ );
}
} elseif (!\is_array($options) && !($options instanceof \Traversable)) {
- throw new \UnexpectedValueException("The options callable is expected to return an iterable value, " . \gettype($options) . " returned.");
+ throw new \UnexpectedValueException(
+ "The options callable is expected to return an iterable value, " . \gettype($options) . " returned for field '{$this->getId()}'."
+ );
}
return $this->options($options, $nestedOptions, $labelLanguageItems);
foreach ($options as $object) {
if (!($object instanceof IObjectTreeNode)) {
throw new \InvalidArgumentException(
- "Nested traversable options must implement '" . IObjectTreeNode::class . "'."
+ "Nested traversable options must implement '" . IObjectTreeNode::class . "' for field '{$this->getId()}'."
);
}
if ($nestedOptions) {
foreach ($options as $key => &$option) {
if (!\is_array($option)) {
- throw new \InvalidArgumentException("Nested option with key '{$key}' has is no array.");
+ throw new \InvalidArgumentException("Nested option with key '{$key}' has is no array for field '{$this->getId()}'.");
}
// check if all required elements exist
foreach (['label', 'value', 'depth'] as $entry) {
if (!isset($option[$entry])) {
- throw new \InvalidArgumentException("Nested option with key '{$key}' has no {$entry} entry.");
+ throw new \InvalidArgumentException("Nested option with key '{$key}' has no {$entry} entry for field '{$this->getId()}'.");
}
}
) {
$option['label'] = $option['label']->getTitle();
} else {
- throw new \InvalidArgumentException("Nested option with key '{$key}' contain invalid label of type " . \gettype($option['label']) . ".");
+ throw new \InvalidArgumentException(
+ "Nested option with key '{$key}' contain invalid label of type " . \gettype($option['label']) . " for field '{$this->getId()}'."
+ );
}
} elseif (!\is_string($option['label']) && !\is_numeric($option['label'])) {
- throw new \InvalidArgumentException("Nested option with key '{$key}' contain invalid label of type " . \gettype($option['label']) . ".");
+ throw new \InvalidArgumentException(
+ "Nested option with key '{$key}' contain invalid label of type " . \gettype($option['label']) . " for field '{$this->getId()}'."
+ );
}
// resolve language item for label
// validate value
if (!\is_string($option['value']) && !\is_numeric($option['value'])) {
- throw new \InvalidArgumentException("Nested option with key '{$key}' contain invalid value of type " . \gettype($option['label']) . ".");
+ throw new \InvalidArgumentException(
+ "Nested option with key '{$key}' contain invalid value of type " . \gettype($option['label']) . " for field '{$this->getId()}'."
+ );
} elseif (isset($this->options[$option['value']])) {
throw new \InvalidArgumentException(
- "Options values must be unique, but '{$option['value']}' appears at least twice as value."
+ "Options values must be unique, but '{$option['value']}' appears at least twice as value for field '{$this->getId()}'."
);
}
// validate depth
if (!\is_int($option['depth'])) {
throw new \InvalidArgumentException(
- "Depth of nested option with key '{$key}' is no integer, " . \gettype($options) . " given."
+ "Depth of nested option with key '{$key}' is no integer, " . \gettype($options) . " given for field '{$this->getId()}'."
);
}
if ($option['depth'] < 0) {
- throw new \InvalidArgumentException("Depth of nested option with key '{$key}' is negative.");
+ throw new \InvalidArgumentException(
+ "Depth of nested option with key '{$key}' is negative for field '{$this->getId()}'."
+ );
}
// set default value of `isSelectable`
foreach ($options as $value => $label) {
if (\is_array($label)) {
throw new \InvalidArgumentException(
- "Non-nested options must not contain any array. Array given for value '{$value}'."
+ "Non-nested options must not contain any array. Array given for value '{$value}' for field '{$this->getId()}'."
);
}
$label = $label->getTitle();
} else {
throw new \InvalidArgumentException(
- "Options contain invalid label of type " . \gettype($label) . "."
+ "Options contain invalid label of type " . \gettype($label) . " for field '{$this->getId()}'."
);
}
} elseif (!\is_string($label) && !\is_numeric($label)) {
throw new \InvalidArgumentException(
- "Options contain invalid label of type " . \gettype($label) . "."
+ "Options contain invalid label of type " . \gettype($label) . " for field '{$this->getId()}'."
);
}
if (isset($this->options[$value])) {
throw new \InvalidArgumentException(
- "Options values must be unique, but '{$value}' appears at least twice as value."
+ "Options values must be unique, but '{$value}' appears at least twice as value for field '{$this->getId()}'."
);
}
} else {
if (!\is_string($languageItem)) {
throw new \InvalidArgumentException(
- "Given suffix language item is no string, " . \gettype($languageItem) . " given."
+ "Given suffix language item is no string, " . \gettype($languageItem) . " given for field '{$this->getId()}'."
);
}
public function getValue()
{
if (!$this->isPopulated) {
- throw new \BadMethodCallException("The field must be populated, before calling this method.");
+ throw new \BadMethodCallException(
+ "The field '{$this->getId()}' must be populated, before calling this method."
+ );
}
if (!$this->isRegistered()) {
public function getRemovedFiles($processFiles = false)
{
if (!$this->isPopulated) {
- throw new \BadMethodCallException("The field must be populated, before calling the method.");
+ throw new \BadMethodCallException(
+ "The field '{$this->getId()}' must be populated, before calling the method."
+ );
}
if (!$this->isRegistered()) {
public function readValue()
{
if (!$this->isPopulated) {
- throw new \BadMethodCallException("The field must be populated, before calling this method.");
+ throw new \BadMethodCallException(
+ "The field '{$this->getId()}' must be populated, before calling the method."
+ );
}
return $this;
public function getHtml()
{
if (!$this->isPopulated) {
- throw new \BadMethodCallException("The field must be populated, before calling this method.");
+ throw new \BadMethodCallException(
+ "The field '{$this->getId()}' must be populated, before calling the method."
+ );
}
if (!$this->isRegistered()) {
public function getFieldHtml()
{
if (!$this->isPopulated) {
- throw new \BadMethodCallException("The field must be populated, before calling this method.");
+ throw new \BadMethodCallException(
+ "The field '{$this->getId()}' must be populated, before calling the method."
+ );
}
if (!$this->isRegistered()) {
$value = \array_map(function ($v) use ($method) {
if (!\is_string($v) || !\file_exists($v)) {
throw new \InvalidArgumentException(
- "The " . $method . " must return an array of strings with the file locations."
+ "The {$method} must return an array of strings with the file locations for field '{$this->getId()}'."
);
}
$this->value($value);
} else {
throw new \InvalidArgumentException(
- "The " . $method . " must return an array of strings with the file locations."
+ "The {$method} must return an array of strings with the file locationsfor field '{$this->getId()}'."
);
}
}
public function value($value)
{
if (!\is_array($value)) {
- throw new \InvalidArgumentException('$value must be an array.');
+ throw new \InvalidArgumentException("Given value must be an array for field '{$this->getId()}'.");
}
foreach ($value as $file) {
if (!($file instanceof UploadFile)) {
throw new \InvalidArgumentException(
- 'All given files must be an instance of ' . UploadFile::class . '.'
+ "All given files must be an instance of " . UploadFile::class . " for field '{$this->getId()}'."
);
}
}
protected function registerField(): void
{
if ($this->isRegistered) {
- throw new \BadMethodCallException("The field is already registered.");
+ throw new \BadMethodCallException("The field '{$this->getId()}' is already registered.");
}
if (!$this->isPopulated) {
- throw new \BadMethodCallException("The field is not populated yet.");
+ throw new \BadMethodCallException("The field '{$this->getId()}' is not populated yet.");
}
UploadHandler::getInstance()->registerUploadField(
{
if ($this->isRegistered()) {
throw new \LogicException(
- 'The upload field has already been registered. Therefore no modifications are allowed.'
+ "The field '{$this->getId()}' has already been registered. Therefore no modifications are allowed."
);
}
if ($maximumFilesize !== null) {
if (!\is_numeric($maximumFilesize)) {
throw new \InvalidArgumentException(
- "Given maximum filesize is no int, '" . \gettype($maximumFilesize) . "' given."
+ "Given maximum filesize is no int, '" . \gettype($maximumFilesize) . "' given for field '{$this->getId()}'."
);
}
}
public function minimumImageWidth($minimumImageWidth = null)
{
if (!$this->isImageOnly()) {
- throw new \LogicException("The form field must be image only, to set a minimum image width.");
+ throw new \LogicException("The field '{$this->getId()}' must be image only to set a minimum image width.");
}
if ($minimumImageWidth !== null) {
if (!\is_numeric($minimumImageWidth)) {
throw new \InvalidArgumentException(
- "Given minimum image width is no int, '" . \gettype($minimumImageWidth) . "' given."
+ "Given minimum image width is no int, '" . \gettype($minimumImageWidth) . "' given for field '{$this->getId()}'."
);
}
$maximumImageWidth = $this->getMaximumImageWidth();
if ($maximumImageWidth !== null && $minimumImageWidth > $maximumImageWidth) {
- throw new \InvalidArgumentException("Minimum image width ({$minimumImageWidth}) cannot be greater than maximum image width ({$maximumImageWidth}).");
+ throw new \InvalidArgumentException(
+ "Minimum image width ({$minimumImageWidth}) cannot be greater than maximum image width ({$maximumImageWidth}) for field '{$this->getId()}'."
+ );
}
}
public function maximumImageWidth($maximumImageWidth = null)
{
if (!$this->isImageOnly()) {
- throw new \LogicException("The form field must be image only, to set a maximum image width.");
+ throw new \LogicException("The field '{$this->getId()}' must be image only to set a maximum image width.");
}
if ($maximumImageWidth !== null) {
if (!\is_numeric($maximumImageWidth)) {
throw new \InvalidArgumentException(
- "Given maximum image width is no int, '" . \gettype($maximumImageWidth) . "' given."
+ "Given maximum image width is no int, '" . \gettype($maximumImageWidth) . "' given for field '{$this->getId()}'."
);
}
$minimumImageWidth = $this->getMinimumImageWidth();
if ($maximumImageWidth !== null && $minimumImageWidth > $maximumImageWidth) {
- throw new \InvalidArgumentException("Maximum image width ({$maximumImageWidth}) cannot be smaller than minimum image width ({$minimumImageWidth}).");
+ throw new \InvalidArgumentException(
+ "Maximum image width ({$maximumImageWidth}) cannot be smaller than minimum image width ({$minimumImageWidth}) for field '{$this->getId()}'."
+ );
}
}
public function minimumImageHeight($minimumImageHeight = null)
{
if (!$this->isImageOnly()) {
- throw new \LogicException("The form field must be image only, to set a minimum image height.");
+ throw new \LogicException(
+ "The field '{$this->getId()}' must be image only to set a minimum image height."
+ );
}
if ($minimumImageHeight !== null) {
if (!\is_numeric($minimumImageHeight)) {
throw new \InvalidArgumentException(
- "Given minimum image height is no int, '" . \gettype($minimumImageHeight) . "' given."
+ "Given minimum image height is no int, '" . \gettype($minimumImageHeight) . "' given for field '{$this->getId()}'."
);
}
$maximumImageHeight = $this->getMaximumImageHeight();
if ($maximumImageHeight !== null && $minimumImageHeight > $maximumImageHeight) {
- throw new \InvalidArgumentException("Minimum image height ({$minimumImageHeight}) cannot be greater than maximum image height ({$maximumImageHeight}).");
+ throw new \InvalidArgumentException(
+ "Minimum image height ({$minimumImageHeight}) cannot be greater than maximum image height ({$maximumImageHeight}) for field '{$this->getId()}'."
+ );
}
}
public function maximumImageHeight($maximumImageHeight = null)
{
if (!$this->isImageOnly()) {
- throw new \LogicException("The form field must be image only, to set a maximum image height.");
+ throw new \LogicException(
+ "The field '{$this->getId()}' must be image only to set a maximum image height."
+ );
}
if ($maximumImageHeight !== null) {
if (!\is_numeric($maximumImageHeight)) {
throw new \InvalidArgumentException(
- "Given maximum image height is no int, '" . \gettype($maximumImageHeight) . "' given."
+ "Given maximum image height is no int, '" . \gettype($maximumImageHeight) . "' given for field '{$this->getId()}'."
);
}
$minimumImageHeight = $this->getMinimumImageHeight();
if ($minimumImageHeight !== null && $maximumImageHeight > $minimumImageHeight) {
- throw new \InvalidArgumentException("Maximum image height ({$maximumImageHeight}) cannot be smaller than minimum image height ({$minimumImageHeight}).");
+ throw new \InvalidArgumentException(
+ "Maximum image height ({$maximumImageHeight}) cannot be smaller than minimum image height ({$minimumImageHeight}) for field '{$this->getId()}'."
+ );
}
}
if (!$imageOnly) {
if ($this->getMinimumImageWidth() !== null) {
throw new \InvalidArgumentException(
- "The form field must be image only, because a minimum image width is set."
+ "The field '{$this->getId()}' must be image only, because a minimum image width is set."
);
}
if ($this->getMaximumImageWidth() !== null) {
throw new \InvalidArgumentException(
- "The form field must be image only, because a maximum image width is set."
+ "The field '{$this->getId()}' must be image only, because a maximum image width is set."
);
}
if ($this->getMinimumImageHeight() !== null) {
throw new \InvalidArgumentException(
- "The form field must be image only, because a minimum image height is set."
+ "The field '{$this->getId()}' must be image only, because a minimum image height is set."
);
}
if ($this->getMaximumImageHeight() !== null) {
throw new \InvalidArgumentException(
- "The form field must be image only, because a maximum image height is set."
+ "The field '{$this->getId()}' must be image only, because a maximum image height is set."
);
}
}
{
if (!$this->isImageOnly()) {
throw new \BadMethodCallException(
- 'Allowing SVG images is only relevant, if the `imageOnly` flag is set to `true`.'
+ "Allowing SVG images is only relevant, if the `imageOnly` flag is set to `true` for field '{$this->getId()}'."
);
}
public function categoryName($categoryName)
{
if (!\is_string($categoryName) || !\preg_match('~^[A-z0-9\-\_]+(\.[A-z0-9\-\_]+)+$~', $categoryName)) {
- throw new \InvalidArgumentException("Invalid category name given.");
+ throw new \InvalidArgumentException("Invalid category name given for field '{$this->getId()}'.");
}
$this->categoryName = $categoryName;
if ($this->objectID === null) {
throw new \UnexpectedValueException(
- "Cannot read object id from object of class '" . \get_class($object) . "'."
+ "Cannot read object id from object of class '" . \get_class($object) . "' for field '{$this->getId()}'."
);
}
public function getLabelGroup()
{
if ($this->labelGroup === null) {
- throw new \BadMethodCallException("No label group has been set.");
+ throw new \BadMethodCallException("No label group has been set for field '{$this->getId()}'.");
}
return $this->labelGroup;
{
if ($this->media === null) {
if (!$this->getValue()) {
- throw new \BadMethodCallException("Cannot be media object if no valid media id is set as value.");
+ throw new \BadMethodCallException(
+ "Cannot be media object if no valid media id is set as value for field '{$this->getId()}'."
+ );
}
$this->media = ViewableMedia::getMedia($this->getValue());
if ($this->media === null) {
- throw new \UnexpectedValueException("Cannot load media with id '{$this->getValue()}'.");
+ throw new \UnexpectedValueException(
+ "Cannot load media with id '{$this->getValue()}' for field '{$this->getId()}'."
+ );
}
}
];
} else {
throw new \InvalidArgumentException(
- "Given value array contains invalid value of type " . \gettype($pollOption) . "."
+ "Given value array contains invalid value of type " . \gettype($pollOption) . " for field '{$this->getId()}'."
);
}
}
use wcf\data\IStorableObject;
use wcf\data\tag\Tag;
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
+use wcf\system\form\builder\exception\InvalidFormFieldValue;
use wcf\system\form\builder\field\AbstractFormField;
use wcf\system\form\builder\field\IAttributeFormField;
use wcf\system\form\builder\field\TDefaultIdFormField;
if ($objectID === null) {
throw new \UnexpectedValueException(
- "Cannot read object id from object of class '" . \get_class($object) . "'."
+ "Cannot read object id from object of class '" . \get_class($object) . "' for field '{$this->getId()}'."
);
}
if ($this->getObjectType() === null) {
- throw new \UnexpectedValueException("Missing taggable object type.");
+ throw new \UnexpectedValueException("Missing taggable object type for field '{$this->getId()}'.");
}
$languageIDs = [];
public function value($value)
{
if (!\is_array($value)) {
- throw new \InvalidArgumentException("Given value is no array, " . \gettype($value) . " given.");
+ throw new InvalidFormFieldValue($this, 'array', \gettype($value));
}
$stringTags = [];
}
if ($stringValues === false) {
- throw new \InvalidArgumentException("Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects.");
+ throw new \InvalidArgumentException(
+ "Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects for field '{$this->getId()}'."
+ );
}
$stringTags[] = $tag;
}
if ($stringValues === true) {
- throw new \InvalidArgumentException("Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects.");
+ throw new \InvalidArgumentException(
+ "Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects for field '{$this->getId()}'."
+ );
}
$stringTags[] = $tag->name;
} else {
throw new \InvalidArgumentException(
- "Given value array contains invalid value of type " . \gettype($tag) . "."
+ "Given value array contains invalid value of type " . \gettype($tag) . " for field '{$this->getId()}'."
);
}
}
// validate validation function
$parameters = (new \ReflectionFunction($validator))->getParameters();
if (\count($parameters) !== 1) {
- throw new \InvalidArgumentException("The validation function must expect one parameter, instead " . \count($parameters) . " parameters are expected.");
+ throw new \InvalidArgumentException(
+ "The validation function must expect one parameter, instead " . \count($parameters)
+ . " parameters are expected for validator '{$id}'."
+ );
}
/** @var \ReflectionType $parameterType */
$parameterType = $parameters[0]->getType();
) {
throw new \InvalidArgumentException(
"The validation function's parameter must be an instance of '" . IFormField::class . "', instead "
- . @($parameterType === null ? 'any' : "'" . $parameterType . "'") . " parameter is expected."
+ . @($parameterType === null ? 'any' : "'" . $parameterType . "'") . " parameter is expected for validator '{$id}'."
);
}
public function getQuoteData($index = null)
{
if (!$this->supportQuotes()) {
- throw new \BadMethodCallException("Quotes are not supported.");
+ throw new \BadMethodCallException("Quotes are not supported for field '{$this->getId()}'.");
}
if ($index === null) {
}
if (!isset($this->quoteData[$index])) {
- throw new \InvalidArgumentException("Unknown quote data '{$index}'.");
+ throw new \InvalidArgumentException("Unknown quote data '{$index}' for field '{$this->getId()}'.");
}
return $this->quoteData[$index];
$objectType
) === null
) {
- throw new \InvalidArgumentException("Unknown message quote object type '{$objectType}'.");
+ throw new \InvalidArgumentException(
+ "Unknown message quote object type '{$objectType}' for field '{$this->getId()}'."
+ );
}
if (!\class_exists($actionClass)) {
- throw new \InvalidArgumentException("Unknown class '{$actionClass}'");
+ throw new \InvalidArgumentException("Unknown class '{$actionClass}' for field '{$this->getId()}'.");
}
if (!\is_subclass_of($actionClass, IMessageQuoteAction::class)) {
throw new \InvalidArgumentException(
- "'{$actionClass}' does not implement '" . IMessageQuoteAction::class . "'."
+ "'{$actionClass}' does not implement '" . IMessageQuoteAction::class . "' for field '{$this->getId()}'."
);
}
if (!empty($selectors)) {
foreach (['container', 'messageBody', 'messageContent'] as $selector) {
if (!isset($selectors[$selector])) {
- throw new \InvalidArgumentException("Missing selector '{$selector}'.");
+ throw new \InvalidArgumentException("Missing selector '{$selector}' for field '{$this->getId()}'.");
}
}
}
foreach ($smilies as $smiley) {
if (!\is_object($smiley)) {
throw new \InvalidArgumentException(
- "Given value array contains invalid value of type " . \gettype($smiley) . "."
+ "Given value array contains invalid value of type " . \gettype($smiley) . " for field '{$this->getId()}'."
);
} elseif (!($smiley instanceof Smiley)) {
throw new \InvalidArgumentException(
- "Given value array contains invalid object of class " . \get_class($smiley) . "."
+ "Given value array contains invalid object of class " . \get_class($smiley) . " for field '{$this->getId()}'."
);
}
}