Skip to content

Commit 9e790b7

Browse files
authored
Merge pull request #152 from kitloong/feature/enum
Use `fromValue` for fallback compatible
2 parents ea33a94 + 408fbe5 commit 9e790b7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/DBAL/Models/DBALColumn.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ protected function setTypeToIncrements(bool $supportUnsigned): void
333333
return;
334334
}
335335

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

339339
/**
@@ -357,7 +357,7 @@ protected function setTypeToUnsigned(): void
357357
return;
358358
}
359359

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

363363
/**

src/Enum/Migrations/Method/ColumnType.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ final class ColumnType extends Enum
134134
public static function fromDBALType(Type $dbalType): self
135135
{
136136
$map = Types::BUILTIN_TYPES_MAP + Types::ADDITIONAL_TYPES_MAP;
137-
return self::from($map[get_class($dbalType)]);
137+
return self::fromValue($map[get_class($dbalType)]);
138+
}
139+
140+
/**
141+
* Initiate an instance from value.
142+
*
143+
* @param mixed $value
144+
* @return static
145+
*/
146+
public static function fromValue($value): self
147+
{
148+
if (method_exists(Enum::class, 'from')) {
149+
return parent::from($value);
150+
}
151+
152+
$key = self::search($value);
153+
return self::__callStatic($key, []);
138154
}
139155
}

0 commit comments

Comments
 (0)