public function getData()
{
$data = [
- 'default' => $this->getDefaultValue() !== null ? "'" . \str_replace(
- ["'", '\\'],
- ["''", '\\\\'],
- $this->getDefaultValue()
- ) . "'" : null,
'notNull' => $this->isNotNull() ? 1 : 0,
'type' => $this->getType(),
];
+ if ($this instanceof IDefaultValueDatabaseTableColumn) {
+ if ($this->getDefaultValue() !== null) {
+ $data['default'] = "'" . \str_replace(
+ ["'", '\\'],
+ ["''", '\\\\'],
+ $this->getDefaultValue()
+ ) . "'";
+ } else {
+ $data['default'] = null;
+ }
+ }
+
if ($this instanceof IAutoIncrementDatabaseTableColumn) {
$data['autoIncrement'] = $this->isAutoIncremented() ? 1 : 0;
public static function createFromData($name, array $data)
{
$column = static::create($name)
- ->defaultValue($data['default'])
->notNull($data['notNull']);
+ if ($column instanceof IDefaultValueDatabaseTableColumn) {
+ $column->defaultValue($data['default']);
+ }
+
if ($column instanceof IAutoIncrementDatabaseTableColumn) {
$column->autoIncrement($data['autoIncrement'] ?: null);
}
*/
interface IDatabaseTableColumn
{
- /**
- * Sets the default value of the column and returns the column.
- *
- * @param mixed $defaultValue
- * @return $this
- */
- public function defaultValue($defaultValue);
-
/**
* Marks the column to be dropped and returns the column.
*
*/
public function getData();
- /**
- * Returns the default value of the column.
- *
- * @return mixed
- */
- public function getDefaultValue();
-
/**
* Returns the name of the column.
*