From aa08072cdcc786a26d1562a11bcd6eb281ba7aa1 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 18 Nov 2018 16:35:05 +0800 Subject: [PATCH] MISC update --- src/Core/Migration/AbstractMigration.php | 2 + src/Core/Seeder/AbstractSeeder.php | 31 +----------- src/Core/Seeder/CountingOutputTrait.php | 64 ++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 src/Core/Seeder/CountingOutputTrait.php diff --git a/src/Core/Migration/AbstractMigration.php b/src/Core/Migration/AbstractMigration.php index b79adad2..b9b5d3aa 100644 --- a/src/Core/Migration/AbstractMigration.php +++ b/src/Core/Migration/AbstractMigration.php @@ -10,6 +10,7 @@ use Windwalker\Console\Command\AbstractCommand; use Windwalker\Core\Database\Traits\DateFormatTrait; +use Windwalker\Core\Seeder\CountingOutputTrait; use Windwalker\Database\Command\AbstractTable; use Windwalker\Database\Driver\AbstractDatabaseDriver; use Windwalker\Utilities\Arr; @@ -22,6 +23,7 @@ abstract class AbstractMigration { use DateFormatTrait; + use CountingOutputTrait; const UP = 'up'; diff --git a/src/Core/Seeder/AbstractSeeder.php b/src/Core/Seeder/AbstractSeeder.php index 81b2cea6..e86f8942 100644 --- a/src/Core/Seeder/AbstractSeeder.php +++ b/src/Core/Seeder/AbstractSeeder.php @@ -22,6 +22,7 @@ abstract class AbstractSeeder { use DateFormatTrait; + use CountingOutputTrait; /** * Property db. @@ -37,13 +38,6 @@ abstract class AbstractSeeder */ protected $command; - /** - * Property count. - * - * @var int - */ - protected $count = 0; - /** * Class init. * @@ -201,27 +195,4 @@ public function setCommand(Command $command) return $this; } - - /** - * outCounting - * - * @return Command - */ - public function outCounting() - { - // @see https://gist.github.com/asika32764/19956edcc5e893b2cbe3768e91590cf1 - if (PlatformHelper::isWindows()) { - $loading = ['|', '/', '-', '\\']; - } else { - $loading = ['◐', '◓', '◑', '◒']; - } - - $this->count++; - - $icon = $loading[$this->count % count($loading)]; - - $this->command->out("\r ({$this->count}) $icon ", false); - - return $this->command; - } } diff --git a/src/Core/Seeder/CountingOutputTrait.php b/src/Core/Seeder/CountingOutputTrait.php new file mode 100644 index 00000000..8910b184 --- /dev/null +++ b/src/Core/Seeder/CountingOutputTrait.php @@ -0,0 +1,64 @@ +count++; + + $icon = $loading[$this->count % count($loading)]; + + $this->command->out("\r ({$this->count}) $icon ", false); + + return $this->command; + } + + /** + * resetCount + * + * @return $this + * + * @since __DEPLOY_VERSION__ + */ + public function resetCount() + { + $this->count = 0; + + return $this; + } +}