Add IDefaultValueDatabaseTableColumn
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 11 Apr 2022 12:11:50 +0000 (14:11 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 11 Apr 2022 12:11:50 +0000 (14:11 +0200)
wcfsetup/install/files/lib/system/database/table/column/IDefaultValueDatabaseTableColumn.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/database/table/column/TDefaultValueDatabaseTableColumn.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/database/table/column/IDefaultValueDatabaseTableColumn.class.php b/wcfsetup/install/files/lib/system/database/table/column/IDefaultValueDatabaseTableColumn.class.php
new file mode 100644 (file)
index 0000000..40620e4
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace wcf\system\database\table\column;
+
+/**
+ * Every database table column that supports specifying a default value must implement this
+ * interface.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2022 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Database\Table\Column
+ * @since   5.5
+ */
+interface IDefaultValueDatabaseTableColumn extends IDatabaseTableColumn
+{
+    /**
+     * Sets the default value of the column and returns the column.
+     *
+     * @param mixed $defaultValue
+     * @return  $this
+     */
+    public function defaultValue($defaultValue);
+
+    /**
+     * Returns the default value of the column.
+     *
+     * @return  mixed
+     */
+    public function getDefaultValue();
+}
diff --git a/wcfsetup/install/files/lib/system/database/table/column/TDefaultValueDatabaseTableColumn.class.php b/wcfsetup/install/files/lib/system/database/table/column/TDefaultValueDatabaseTableColumn.class.php
new file mode 100644 (file)
index 0000000..1c589bc
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+namespace wcf\system\database\table\column;
+
+/**
+ * Provides default implementation of the methods of `IDefaultValueDatabaseTableColumn`.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2022 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Database\Table\Column
+ * @since   5.5
+ */
+trait TDefaultValueDatabaseTableColumn
+{
+    /**
+     * default value of the database table column
+     * @var mixed
+     */
+    protected $defaultValue;
+
+    /**
+     * Checks if the given default value is valid.
+     *
+     * @param mixed $defaultValue validated default value
+     * @throws  \InvalidArgumentException   if given default value is invalid
+     */
+    protected function validateDefaultValue($defaultValue)
+    {
+        // does nothing
+    }
+
+    /**
+     * Sets the default value of the column and returns the column.
+     *
+     * @param mixed $defaultValue
+     * @return  $this
+     */
+    public function defaultValue($defaultValue)
+    {
+        $this->validateDefaultValue($defaultValue);
+
+        $this->defaultValue = $defaultValue;
+
+        return $this;
+    }
+
+    /**
+     * Returns the default value of the column.
+     *
+     * @return  mixed
+     */
+    public function getDefaultValue()
+    {
+        return $this->defaultValue;
+    }
+}