- Field mapper is now removed from Adapters and set into it's own object
- Added a PK to Column (IS)
This commit is contained in:
1 parent
9977a25cf5
commit
3c2ae86653
7 files changed
+168
-57
No files matched your search
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Adapter;
|
||||
|
||||
use Ulmus\Migration\FieldDefinition;
|
||||
|
||||
class MySQLFieldMapper extends SqlFieldMapper
|
||||
{
|
||||
public readonly string $type;
|
||||
|
||||
public readonly string $length;
|
||||
|
||||
public function map() : void
|
||||
{
|
||||
$type = $this->field->type;
|
||||
$length = $this->field->length;
|
||||
|
||||
if ( enum_exists($type) ) {
|
||||
# Haven't found a better way yet to check for BackendEnum without an instance of the object
|
||||
if ( ! method_exists($type, 'tryFrom') ) {
|
||||
throw new \Ulmus\Exception\BackedEnumRequired(sprintf("You must define your enum as a BackedEnum instead of an UnitEnum for field '%s'.", $this->field->getColumnName()));
|
||||
}
|
||||
|
||||
$this->length = implode(',', array_map(fn($e) => MySQL::escapeIdentifier($e->value, MySQL::IDENTIFIER_VALUE) , $type::cases()));
|
||||
$this->type = "ENUM";
|
||||
}
|
||||
else {
|
||||
parent::map();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user