Skip to content

Commit

Permalink
修正
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Aug 15, 2016
1 parent a856b7c commit 43d018c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 45 deletions.
33 changes: 9 additions & 24 deletions src/command/migrate/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use think\console\Input;
use think\console\input\Option as InputOption;
use think\console\Output;
use think\console\helper\question\Confirmation as ConfirmationQuestion;
use think\migration\command\AbstractCommand;

class Create extends AbstractCommand
Expand Down Expand Up @@ -49,21 +48,10 @@ protected function configure()
$this->addOption('class', 'l', InputOption::VALUE_REQUIRED, 'Use a class implementing "' . self::CREATION_INTERFACE . '" to generate the template');
}

/**
* Get the confirmation question asking if the user wants to create the
* migrations directory.
*
* @return ConfirmationQuestion
*/
protected function getCreateMigrationDirectoryQuestion()
{
return new ConfirmationQuestion('Create migrations directory? [y]/n ', true);
}

/**
* Create the new migration.
*
* @param Input $input
* @param Input $input
* @param Output $output
* @throws \RuntimeException
* @throws \InvalidArgumentException
Expand All @@ -77,17 +65,14 @@ protected function execute(Input $input, Output $output)
$path = $this->getConfig()->getMigrationPath();

if (!file_exists($path)) {
$helper = $this->getHelper('question');
$question = $this->getCreateMigrationDirectoryQuestion();

if ($helper->ask($input, $output, $question)) {
if ($output->confirm($input, 'Create migrations directory?')) {
mkdir($path, 0755, true);
}
}

$this->verifyMigrationDirectory($path);

$path = realpath($path);
$path = realpath($path);
$className = $input->getArgument('name');

if (!Util::isValidPhinxClassName($className)) {
Expand Down Expand Up @@ -164,19 +149,19 @@ protected function execute(Input $input, Output $output)
// Get the template from the creation class
/** @var CreationInterface $creationClass */
$creationClass = new $creationClassName();
$contents = $creationClass->getMigrationTemplate();
$contents = $creationClass->getMigrationTemplate();
} else {
// Load the alternative template if it is defined.
$contents = file_get_contents($altTemplate ?: $this->getMigrationTemplateFilename());
}

// inject the class names appropriate to this migration
$classes = array(
'$useClassName' => $this->getConfig()->getMigrationBaseClassName(false),
'$className' => $className,
'$version' => Util::getVersionFromFileName($fileName),
$classes = [
'$useClassName' => $this->getConfig()->getMigrationBaseClassName(false),
'$className' => $className,
'$version' => Util::getVersionFromFileName($fileName),
'$baseClassName' => $this->getConfig()->getMigrationBaseClassName(true),
);
];
$contents = strtr($contents, $classes);

if (false === file_put_contents($filePath, $contents)) {
Expand Down
26 changes: 5 additions & 21 deletions src/command/seed/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use think\console\Output;
use think\migration\command\AbstractCommand;
use think\console\input\Argument as InputArgument;
use think\console\helper\question\Confirmation as ConfirmationQuestion;


class Create extends AbstractCommand
{
Expand All @@ -37,21 +35,10 @@ protected function configure()
));
}

/**
* Get the confirmation question asking if the user wants to create the
* seeds directory.
*
* @return ConfirmationQuestion
*/
protected function getCreateSeedDirectoryQuestion()
{
return new ConfirmationQuestion('Create seeds directory? [y]/n ', true);
}

/**
* Create the new seeder.
*
* @param Input $input
* @param Input $input
* @param Output $output
* @throws \RuntimeException
* @throws \InvalidArgumentException
Expand All @@ -65,17 +52,14 @@ protected function execute(Input $input, Output $output)
$path = $this->getConfig()->getSeedPath();

if (!file_exists($path)) {
$helper = $this->getHelper('question');
$question = $this->getCreateSeedDirectoryQuestion();

if ($helper->ask($input, $output, $question)) {
if ($output->confirm($input, 'Create seeds directory?')) {
mkdir($path, 0755, true);
}
}

$this->verifySeedDirectory($path);

$path = realpath($path);
$path = realpath($path);
$className = $input->getArgument('name');

if (!Util::isValidPhinxClassName($className)) {
Expand All @@ -97,11 +81,11 @@ protected function execute(Input $input, Output $output)

// inject the class names appropriate to this seeder
$contents = file_get_contents($this->getSeedTemplateFilename());
$classes = array(
$classes = [
'$useClassName' => 'Phinx\Seed\AbstractSeed',
'$className' => $className,
'$baseClassName' => 'AbstractSeed',
);
];
$contents = strtr($contents, $classes);

if (false === file_put_contents($filePath, $contents)) {
Expand Down

0 comments on commit 43d018c

Please sign in to comment.