use wcf\data\condition\Condition;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
/**
* Abstract condition implementation for check a text-typed property of a database
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
$className = $this->getListClassName();
if (!($objectList instanceof $className)) {
- throw new \InvalidArgumentException("Object list is no instance of '{$className}', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, $className, 'Object list');
}
if ($this->supportsMultipleValues) {
public function checkObject(DatabaseObject $object, array $conditionData) {
$className = $this->getClassName();
if (!($object instanceof $className)) {
- throw new \InvalidArgumentException("Object is no instance of '{$className}', instance of '".get_class($object)."' given.");
+ throw new InvalidObjectArgument($object, $className);
}
return in_array($object->{$this->getPropertyName()}, $conditionData[$this->fieldName]);
use wcf\data\condition\Condition;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
$className = $this->getListClassName();
if (!($objectList instanceof $className)) {
- throw new \InvalidArgumentException("Object list is no instance of '{$className}', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, $className, 'Object list');
}
/** @noinspection PhpUndefinedFieldInspection */
public function checkObject(DatabaseObject $object, array $conditionData) {
$className = $this->getClassName();
if (!($object instanceof $className)) {
- throw new \InvalidArgumentException("Object is no instance of '{$className}', instance of '".get_class($object)."' given.");
+ throw new InvalidObjectArgument($object, $className);
}
if (isset($conditionData['startTime']) && $object->{$this->getPropertyName()} < strtotime($conditionData['startTime'])) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
switch ($conditionData['userAvatar']) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
switch ($conditionData['userCoverPhoto']) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('user_table.email LIKE ?', ['%'.addcslashes($conditionData['email'], '_%').'%']);
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
if (isset($conditionData['greaterThan'])) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\exception\UserInputException;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('user_table.languageID IN (?)', [$conditionData['languageIDs']]);
use wcf\data\user\UserList;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\option\user\UserOptionHandler;
use wcf\system\WCF;
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
$optionValues = $conditionData['optionValues'];
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
if (isset($conditionData['registrationDateEnd'])) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
if (isset($conditionData['greaterThan'])) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
switch ($conditionData['userSignature']) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
if (isset($conditionData['userIsBanned'])) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
if (isset($conditionData['userTrophyIDs'])) {
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is not an instance of '".UserList::class."', an instance of '".get_class($objectList)."' was given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('user_table.userID = ?', [$conditionData['userID']]);
use wcf\data\user\User;
use wcf\data\user\UserList;
use wcf\data\DatabaseObjectList;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('user_table.username LIKE ?', ['%'.addcslashes($conditionData['username'], '_%').'%']);
use wcf\data\DatabaseObjectList;
use wcf\system\condition\AbstractMultiCategoryCondition;
use wcf\system\condition\IObjectListCondition;
+use wcf\system\exception\InvalidObjectArgument;
/**
* Condition implementation for the category an article belongs to.
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof ArticleList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".ArticleList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, ArticleList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('article.categoryID IN (?)', [$conditionData[$this->fieldName]]);
use wcf\system\condition\AbstractSingleFieldCondition;
use wcf\system\condition\IObjectCondition;
use wcf\system\condition\IObjectListCondition;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
use wcf\util\ClassUtil;
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserList)) {
- throw new \InvalidArgumentException("Object list is no instance of '" . UserList::class . "', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserList::class, 'Object list');
}
/** @noinspection PhpUndefinedFieldInspection */
*/
public function checkObject(DatabaseObject $object, array $conditionData) {
if (!($object instanceof User) && !ClassUtil::isDecoratedInstanceOf($object, User::class)) {
- throw new \InvalidArgumentException("Object is no instance of '" . User::class . "', instance of '".get_class($object)."' given.");
+ throw new InvalidObjectArgument($objectList, User::class);
}
if (isset($conditionData['startDays'])) {
use wcf\data\DatabaseObjectList;
use wcf\system\condition\AbstractMultiSelectCondition;
use wcf\system\condition\IObjectListCondition;
+use wcf\system\exception\InvalidObjectArgument;
use wcf\system\WCF;
/**
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserActivityEventList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserActivityEventList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserActivityEventList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('user_activity_event.objectTypeID NOT IN (?)', [$conditionData[$this->fieldName]]);
use wcf\data\DatabaseObjectList;
use wcf\system\condition\AbstractMultiSelectCondition;
use wcf\system\condition\IObjectListCondition;
+use wcf\system\exception\InvalidObjectArgument;
/**
* Condition implementation for the excluded trophies.
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserTrophyList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserTrophyList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserTrophyList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('user_trophy.trophyID NOT IN (?)', [$conditionData[$this->fieldName]]);
use wcf\data\DatabaseObjectList;
use wcf\system\condition\AbstractMultiSelectCondition;
use wcf\system\condition\IObjectListCondition;
+use wcf\system\exception\InvalidObjectArgument;
/**
* Condition implementation for the excluded trophies.
*/
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) {
if (!($objectList instanceof UserTrophyList)) {
- throw new \InvalidArgumentException("Object list is no instance of '".UserTrophyList::class."', instance of '".get_class($objectList)."' given.");
+ throw new InvalidObjectArgument($objectList, UserTrophyList::class, 'Object list');
}
$objectList->getConditionBuilder()->add('trophy.categoryID NOT IN (?)', [$conditionData[$this->fieldName]]);
--- /dev/null
+<?php
+namespace wcf\system\exception;
+
+/**
+ * Exception implementation instances where an API allows passing generic objects but a concrete
+ * implementation requires the objects to be instances of a specific (sub)class.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Exception
+ * @since 5.4
+ */
+class InvalidObjectArgument extends \InvalidArgumentException {
+ /**
+ * InvalidObjectArgument constructor.
+ */
+ public function __construct(object $object, string $expectedClass, string $objectName = 'Object') {
+ parent::__construct("{$objectName} is no instance of '{$expectedClass}', instance of '" . get_class($object) . "' given.");
+ }
+}