Skip to content

Commit

Permalink
Merge pull request #152 from kitloong/feature/enum
Browse files Browse the repository at this point in the history
Use `fromValue` for fallback compatible
  • Loading branch information
kitloong authored Dec 30, 2022
2 parents ea33a94 + 408fbe5 commit 9e790b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/DBAL/Models/DBALColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected function setTypeToIncrements(bool $supportUnsigned): void
return;
}

$this->type = ColumnType::from(str_replace('Integer', 'Increments', $this->type));
$this->type = ColumnType::fromValue(str_replace('Integer', 'Increments', $this->type));
}

/**
Expand All @@ -357,7 +357,7 @@ protected function setTypeToUnsigned(): void
return;
}

$this->type = ColumnType::from('unsigned' . ucfirst($this->type));
$this->type = ColumnType::fromValue('unsigned' . ucfirst($this->type));
}

/**
Expand Down
18 changes: 17 additions & 1 deletion src/Enum/Migrations/Method/ColumnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ final class ColumnType extends Enum
public static function fromDBALType(Type $dbalType): self
{
$map = Types::BUILTIN_TYPES_MAP + Types::ADDITIONAL_TYPES_MAP;
return self::from($map[get_class($dbalType)]);
return self::fromValue($map[get_class($dbalType)]);
}

/**
* Initiate an instance from value.
*
* @param mixed $value
* @return static
*/
public static function fromValue($value): self
{
if (method_exists(Enum::class, 'from')) {
return parent::from($value);
}

$key = self::search($value);
return self::__callStatic($key, []);
}
}

0 comments on commit 9e790b7

Please sign in to comment.