Skip to content

Commit

Permalink
MISC update
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Nov 18, 2018
1 parent 52d5569 commit aa08072
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/Core/Migration/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@
abstract class AbstractMigration
{
use DateFormatTrait;
use CountingOutputTrait;

const UP = 'up';

Expand Down
31 changes: 1 addition & 30 deletions src/Core/Seeder/AbstractSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
abstract class AbstractSeeder
{
use DateFormatTrait;
use CountingOutputTrait;

/**
* Property db.
Expand All @@ -37,13 +38,6 @@ abstract class AbstractSeeder
*/
protected $command;

/**
* Property count.
*
* @var int
*/
protected $count = 0;

/**
* Class init.
*
Expand Down Expand Up @@ -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;
}
}
64 changes: 64 additions & 0 deletions src/Core/Seeder/CountingOutputTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Part of earth project.
*
* @copyright Copyright (C) 2018 ${ORGANIZATION}.
* @license __LICENSE__
*/

namespace Windwalker\Core\Seeder;

use Windwalker\Console\Command\Command;
use Windwalker\Environment\PlatformHelper;

/**
* The CountingOutputTrait class.
*
* @since __DEPLOY_VERSION__
*/
trait CountingOutputTrait
{
/**
* Property count.
*
* @var int
*/
protected $count = 0;

/**
* 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;
}

/**
* resetCount
*
* @return $this
*
* @since __DEPLOY_VERSION__
*/
public function resetCount()
{
$this->count = 0;

return $this;
}
}

0 comments on commit aa08072

Please sign in to comment.