From 43d018cb0c4e7a11b167a54771baebf2e0d4f9ed Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Mon, 15 Aug 2016 12:09:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/command/migrate/Create.php | 33 +++++++++------------------------ src/command/seed/Create.php | 26 +++++--------------------- 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/src/command/migrate/Create.php b/src/command/migrate/Create.php index eaf0b5e..951fc7f 100644 --- a/src/command/migrate/Create.php +++ b/src/command/migrate/Create.php @@ -15,7 +15,6 @@ use think\console\input\Argument as InputArgument; 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 @@ -49,21 +48,10 @@ class Create extends AbstractCommand $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 @@ -77,17 +65,14 @@ class Create extends AbstractCommand $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)) { @@ -164,19 +149,19 @@ class Create extends AbstractCommand // 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)) { diff --git a/src/command/seed/Create.php b/src/command/seed/Create.php index c05c921..384108c 100644 --- a/src/command/seed/Create.php +++ b/src/command/seed/Create.php @@ -15,8 +15,6 @@ use think\console\Input; 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 { @@ -37,21 +35,10 @@ class Create extends AbstractCommand )); } - /** - * 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 @@ -65,17 +52,14 @@ class Create extends AbstractCommand $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)) { @@ -97,11 +81,11 @@ class Create extends AbstractCommand // 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)) {