This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from drajathasan/development
Improve : Plugin feature
- Loading branch information
Showing
6 changed files
with
218 additions
and
27 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
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,43 @@ | ||
<?php | ||
/** | ||
* @author Drajat Hasan | ||
* @email [[email protected]] | ||
* @create date 2021-03-28 10:34:09 | ||
* @modify date 2021-03-28 10:34:09 | ||
* @desc [description] | ||
*/ | ||
|
||
namespace SLiMSTarsius; | ||
|
||
use SLiMSTarsius\Migrationext\{AddAction}; | ||
|
||
class Migration | ||
{ | ||
private $type; | ||
private $optionsData; | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
|
||
public function run() | ||
{ | ||
$Options = [ | ||
'kolom' => [ | ||
'type' => 'varchar', | ||
'constraint' => 20, | ||
'null' => true, | ||
'default' => 'Pintar' | ||
], | ||
'kolom2' => [ | ||
'type' => 'int', | ||
'constraint' => 20, | ||
'null' => false, | ||
'default' => 10 | ||
] | ||
]; | ||
|
||
echo (AddAction::process('backup_log', AddAction::alter($Options)))."\n"; | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
namespace SLiMSTarsius\Migrationext; | ||
|
||
class AddAction | ||
{ | ||
public static function alter($arrayData) | ||
{ | ||
$rawQuery = []; | ||
foreach ($arrayData as $column => $options) { | ||
$rawQuery[$column] = []; | ||
$rawQuery[$column][0] = 'ADD `' . $column . '` '; | ||
foreach ($options as $option => $value) { | ||
switch ($option) { | ||
case 'type': | ||
$withContraint = ''; | ||
if ((isset($options['constraint']) && !in_array($options['type'], ['datetime','text','longtext','mediumtext','']))) | ||
{ | ||
$withContraint = '(' .(int)$options['constraint']. ')'; | ||
} | ||
$rawQuery[$column][1] = str_replace("'", "\'", $value) . $withContraint.' '; | ||
break; | ||
case 'null': | ||
$rawQuery[$column][2] = 'NOT NULL '; | ||
if ($value) | ||
{ | ||
$rawQuery[$column][2] = 'NULL '; | ||
} | ||
case 'default': | ||
$rawQuery[$column][3] = 'DEFAULT \'' . str_replace("'", "\'", $value) . '\' '; | ||
break; | ||
case 'increment': | ||
$rawQuery[$column][4] = 'AUTO_INCREMENT UNIQUE '; | ||
break; | ||
case 'after': | ||
$rawQuery[$column][5] = 'AFTER `' . str_replace("'", "\'", $value) .'` '; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return ['ALTER TABLE ', $rawQuery]; | ||
} | ||
|
||
public static function process($tableName, $raw) | ||
{ | ||
$rawQuery = $raw[0] . ' `'. $tableName .'` '; | ||
foreach ($raw[1] as $value) { | ||
$rawQuery .= trim(implode('', $value)). ', '; | ||
} | ||
|
||
$rawQuery = substr_replace($rawQuery, ';', -2); | ||
|
||
echo $rawQuery; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -48,7 +48,6 @@ public function compile() | |
} | ||
unset($this->arguments[$id]); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
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
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