-
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.
- Loading branch information
1 parent
e4f116f
commit 7648350
Showing
20 changed files
with
287 additions
and
68 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,52 @@ | ||
<?php | ||
|
||
namespace Alirezasalehizadeh\QuickMigration\Command; | ||
|
||
use Alirezasalehizadeh\QuickMigration\Enums\Command as EnumsCommand; | ||
|
||
class Command | ||
{ | ||
|
||
private EnumsCommand $name; | ||
|
||
private string $pattern = ''; | ||
|
||
private array $includes = []; | ||
|
||
|
||
public function getName() | ||
{ | ||
return $this->name->value; | ||
} | ||
|
||
public function setName(EnumsCommand $name) | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPattern() | ||
{ | ||
return $this->pattern; | ||
} | ||
|
||
public function setPattern(string $pattern) | ||
{ | ||
$this->pattern = $pattern; | ||
|
||
return $this; | ||
} | ||
|
||
public function getIncludes() | ||
{ | ||
return $this->includes; | ||
} | ||
|
||
public function setIncludes(array $includes) | ||
{ | ||
$this->includes = $includes; | ||
|
||
return $this; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?php | ||
|
||
namespace Alirezasalehizadeh\QuickMigration\Command; | ||
|
||
use Alirezasalehizadeh\QuickMigration\Command\Command; | ||
|
||
interface CommandInterface | ||
{ | ||
public function generate() : string; | ||
public function getCommand(): Command; | ||
} |
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 |
---|---|---|
@@ -1,23 +1,31 @@ | ||
<?php | ||
namespace Alirezasalehizadeh\QuickMigration\Command\Commands; | ||
|
||
use Alirezasalehizadeh\QuickMigration\Command\CommandGenerator; | ||
use Alirezasalehizadeh\QuickMigration\Command\Command; | ||
use Alirezasalehizadeh\QuickMigration\Command\CommandInterface; | ||
use Alirezasalehizadeh\QuickMigration\Enums\Command as EnumsCommand; | ||
|
||
class DropIfExistsTableCommand extends CommandGenerator | ||
class DropIfExistsTableCommand extends Command implements CommandInterface | ||
{ | ||
|
||
private $database, $table; | ||
|
||
protected $pattern = "DROP TABLE IF EXISTS `%s`.`%s`"; | ||
protected $pattern = "%s `%s`.`%s`"; | ||
|
||
public function __construct(string $database, string $table) | ||
{ | ||
$this->database = $database; | ||
$this->table = $table; | ||
} | ||
|
||
public function generate(): string | ||
public function getCommand() : self | ||
{ | ||
return sprintf($this->pattern, $this->database, $this->table); | ||
return $this | ||
->setName(EnumsCommand::DropTableIfExists) | ||
->setPattern($this->pattern) | ||
->setIncludes([ | ||
'database' => $this->database, | ||
'table' => $this->table, | ||
]); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,31 @@ | ||
<?php | ||
namespace Alirezasalehizadeh\QuickMigration\Command\Commands; | ||
|
||
use Alirezasalehizadeh\QuickMigration\Command\CommandGenerator; | ||
use Alirezasalehizadeh\QuickMigration\Command\Command; | ||
use Alirezasalehizadeh\QuickMigration\Command\CommandInterface; | ||
use Alirezasalehizadeh\QuickMigration\Enums\Command as EnumsCommand; | ||
|
||
class DropTableCommand extends CommandGenerator | ||
class DropTableCommand extends Command implements CommandInterface | ||
{ | ||
|
||
private $database, $table; | ||
|
||
protected $pattern = "DROP TABLE `%s`.`%s`"; | ||
protected $pattern = "%s `%s`.`%s`"; | ||
|
||
public function __construct(string $database, string $table) | ||
{ | ||
$this->database = $database; | ||
$this->table = $table; | ||
} | ||
|
||
public function generate(): string | ||
public function getCommand() :self | ||
{ | ||
return sprintf($this->pattern, $this->database, $this->table); | ||
return $this | ||
->setName(EnumsCommand::Drop) | ||
->setPattern($this->pattern) | ||
->setIncludes([ | ||
'database' => $this->database, | ||
'table' => $this->table, | ||
]); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Alirezasalehizadeh\QuickMigration\Enums; | ||
|
||
enum Command: string | ||
{ | ||
case Create = "CREATE TABLE"; | ||
case Drop = "DROP TABLE"; | ||
case DropTableIfExists = "DROP TABLE IF EXISTS"; | ||
} |
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
8 changes: 4 additions & 4 deletions
8
src/Translation/Translator.php → ...ion/ColumnTranslator/ColumnTranslator.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
4 changes: 2 additions & 2 deletions
4
src/Translation/TranslatorInterface.php → ...nTranslator/ColumnTranslatorInterface.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
6 changes: 3 additions & 3 deletions
6
...anslation/Translators/MySqlTranslator.php → ...ranslator/Translators/MySqlTranslator.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
6 changes: 3 additions & 3 deletions
6
...tion/Translators/PostgreSqlTranslator.php → ...ator/Translators/PostgreSqlTranslator.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
9 changes: 9 additions & 0 deletions
9
src/Translation/CommandTranslator/CommandTranslatorInterface.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,9 @@ | ||
<?php | ||
|
||
namespace Alirezasalehizadeh\QuickMigration\Translation\CommandTranslator; | ||
|
||
|
||
interface CommandTranslatorInterface | ||
{ | ||
public function make(): string; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Translation/CommandTranslator/Translators/CreateTableCommandTranslator.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,27 @@ | ||
<?php | ||
namespace Alirezasalehizadeh\QuickMigration\Translation\CommandTranslator\Translators; | ||
|
||
use Alirezasalehizadeh\QuickMigration\Command\Command; | ||
use Alirezasalehizadeh\QuickMigration\Translation\CommandTranslator\CommandTranslatorInterface; | ||
|
||
class CreateTableCommandTranslator implements CommandTranslatorInterface | ||
{ | ||
|
||
public function __construct( | ||
private Command $command | ||
){ | ||
$this->command = $command; | ||
} | ||
|
||
public function make():string | ||
{ | ||
return sprintf( | ||
$this->command->getPattern(), | ||
$this->command->getName(), | ||
$this->command->getIncludes()['database'], | ||
$this->command->getIncludes()['table'], | ||
implode(',', $this->command->getIncludes()['sqlCommands']), | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.