This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
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 #10 from baselbj/develop
Add namespace support and add generate skeleton migration file
- Loading branch information
Showing
9 changed files
with
2,813 additions
and
313 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
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,96 @@ | ||
<?php | ||
namespace Vulcan\Commands; | ||
|
||
use CodeIgniter\CLI\BaseCommand; | ||
use CodeIgniter\CLI\CLI; | ||
use Vulcan\Libraries\GeneratorTrait; | ||
|
||
/** | ||
* Creates a skeleton Migration | ||
* | ||
* @package Vulcan\Commands | ||
*/ | ||
class MakeMigration extends BaseCommand | ||
{ | ||
use GeneratorTrait; | ||
|
||
protected $group = 'Vulcan'; | ||
|
||
/** | ||
* The Migration's name | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:migration'; | ||
|
||
/** | ||
* the Migration's short description | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Creates a skeleton migration file.'; | ||
|
||
/** | ||
* the Command's usage | ||
* | ||
* @var string | ||
*/ | ||
protected $usage = 'make:migration [migration_name] [Options]'; | ||
|
||
/** | ||
* the Command's Arguments | ||
* | ||
* @var array | ||
*/ | ||
protected $arguments = [ | ||
'migration_name' => 'The migration file name' | ||
]; | ||
|
||
/** | ||
* the Command's Options | ||
* | ||
* @var array | ||
*/ | ||
protected $options = [ | ||
'-n' => 'Set migration namespace', | ||
'-f' => 'overwrite files' | ||
]; | ||
|
||
/** | ||
* Creates a skeleton Migration file. | ||
*/ | ||
public function run(array $params=[]) | ||
{ | ||
/* | ||
* Name | ||
*/ | ||
$name = array_shift($params); | ||
|
||
if (empty($name)) | ||
{ | ||
$name = CLI::prompt('Migration name'); | ||
} | ||
|
||
// Format to CI standards | ||
$name = ucfirst($name); | ||
$view = 'Migration/Migration'; | ||
|
||
$data = [ | ||
'namespace' => 'namespace' => CLI::getOption('n') ?? 'App', | ||
'name' => $name, | ||
'today' => date('Y-m-d H:i:a') | ||
]; | ||
|
||
$destination = $this->determineOutputPath('Database\Migrations',$data['namespace']).$name.'.php'; | ||
|
||
$overwrite = (bool)CLI::getOption('f'); | ||
|
||
try { | ||
$this->copyTemplate($view, $destination, $data, $overwrite); | ||
} | ||
catch (\Exception $e) | ||
{ | ||
$this->showError($e); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.