-
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert column property to case insensitive #34
- Loading branch information
Showing
2 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/KitLoong/MigrationsGenerator/Schema/MySQL/ShowColumn.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace KitLoong\MigrationsGenerator\Schema\MySQL; | ||
|
||
use Illuminate\Support\Collection; | ||
use stdClass; | ||
|
||
/** | ||
* Class ShowColumn | ||
* | ||
* Entity from MySQL SHOW COLUMNS statement | ||
* @see https://dev.mysql.com/doc/refman/5.7/en/show-columns.html | ||
* @see https://dev.mysql.com/doc/refman/8.0/en/show-columns.html | ||
* | ||
* @package KitLoong\MigrationsGenerator\Schema\MySQL | ||
*/ | ||
class ShowColumn | ||
{ | ||
/** @var string */ | ||
private $field; | ||
|
||
/** @var string */ | ||
private $type; | ||
|
||
/** @var string */ | ||
private $null; | ||
|
||
/** @var string */ | ||
private $key; | ||
|
||
/** @var string|null */ | ||
private $default; | ||
|
||
/** @var string */ | ||
private $extra; | ||
|
||
public function __construct(stdClass $column) | ||
{ | ||
// Convert column property to case insensitive | ||
// Issue https://github.com/kitloong/laravel-migrations-generator/issues/34 | ||
$lowerKey = (new Collection($column))->mapWithKeys(function ($item, $key) { | ||
return [strtolower($key) => $item]; | ||
}); | ||
|
||
$this->field = $lowerKey['field']; | ||
$this->type = $lowerKey['type']; | ||
$this->null = $lowerKey['null']; | ||
$this->key = $lowerKey['key']; | ||
$this->default = $lowerKey['default']; | ||
$this->extra = $lowerKey['extra']; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getField(): string | ||
{ | ||
return $this->field; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getNull(): string | ||
{ | ||
return $this->null; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKey(): string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getDefault(): ?string | ||
{ | ||
return $this->default; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getExtra(): string | ||
{ | ||
return $this->extra; | ||
} | ||
} |