Skip to content

Commit

Permalink
Fixed composer.json and added translated messages on console command …
Browse files Browse the repository at this point in the history
…line
  • Loading branch information
vluzrmos committed Jun 24, 2015
1 parent 22ce17f commit 6ddf107
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 337 deletions.
76 changes: 76 additions & 0 deletions app/Console/Commands/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command as IlluminateCommand;

abstract class Command extends IlluminateCommand
{


/**
* Prints an horizontal table
* @param array $rows
*/
protected function horizontalTable(array $rows)
{
$rows = array_dot($rows);

$lines = [];

foreach($rows as $key => $value) {
$lines[] = $this->getTableLine($key, $value);
}

$linesMaxLength = $this->getStringsMaxLength($lines);

$this->writeTableLine($linesMaxLength);

foreach($lines as $line) {
$this->output->writeln($line);
}

$this->writeTableLine($linesMaxLength);
}

/**
*
* Get a string for a given row (header, content)
*
* @param string $header Title of the header
* @param string $content content of the header
*
* @return string
*/
private function getTableLine($header, $content)
{
return sprintf("<info>%s:</info> %s", $header, $content);
}

/**
* Get max length of strings on a given array of headers
*
* @param array $strings
*
* @return int
*/
private function getStringsMaxLength(array $strings)
{
$size = 0;

foreach($strings as $string) {
$size = max($size, strlen($string));
}

return $size;
}

/**
* Writes a line with a given separator
* @param int $length Length of the line
* @param string $separator Chacactere used for the line
*/
private function writeTableLine($length, $separator = '-') {
$this->output->writeln(substr(str_repeat($separator, $length), 0, $length));
}
}
21 changes: 17 additions & 4 deletions app/Console/Commands/SlackStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Console\Commands;

use App\Services\SlackStatusService;
use Illuminate\Console\Command;

class SlackStatusCommand extends Command
{
Expand Down Expand Up @@ -39,10 +38,24 @@ public function __construct(SlackStatusService $slack)
*/
public function fire()
{
$this->info('Checking for new status...');
$this->info(trans('slackin.updating_status'));

$this->slack->refreshUsersStatus();
$status = $this->slack->refreshUsersStatus();

$this->info('Done!');
$this->infoStatusUser($status);

$this->info(trans('slackin.command_done'));
}

/**
* Show info message about status of users
*
* @param array $status
*/
public function infoStatusUser(array $status)
{
$message = strip_tags(trans_choice('slackin.users_online', $status['active'], $status));

$this->info($message);
}
}
9 changes: 5 additions & 4 deletions app/Console/Commands/SlackTeamInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Console\Commands;

use App\Services\SlackStatusService;
use Illuminate\Console\Command;

class SlackTeamInfoCommand extends Command
{
Expand Down Expand Up @@ -39,10 +38,12 @@ public function __construct(SlackStatusService $slack)
*/
public function fire()
{
$this->info('Checking slack team info...');
$this->info(trans('slackin.updating_team_info'));

$this->slack->refreshTeamInfo();
$info = $this->slack->refreshTeamInfo();

$this->info('Done!');
$this->horizontalTable($info);

$this->info(trans('slackin.command_done'));
}
}
4 changes: 4 additions & 0 deletions artisan
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ use Symfony\Component\Console\Output\ConsoleOutput;

$app = require __DIR__.'/bootstrap/app.php';

if(class_exists('Vluzrmos\Tinker\TinkerServiceProvider')) {
$app->register('Vluzrmos\Tinker\TinkerServiceProvider');
}

/*
|--------------------------------------------------------------------------
| Run The Artisan Application
Expand Down
4 changes: 1 addition & 3 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,12 @@

$app->register('App\Providers\ValidationServiceProvider');

$app->register('\App\Providers\TranslatorServiceProvider');
$app->register('App\Providers\TranslatorServiceProvider');

$app->register('Vluzrmos\SlackApi\SlackApiServiceProvider');

$app->register('Vluzrmos\BadgePoser\BadgePoserServiceProvider');

$app->register('Vluzrmos\Tinker\TinkerServiceProvider');

/*
|--------------------------------------------------------------------------
| Load The Application Routes
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
"vluzrmos/badge-poser": "1.0.*",
"predis/predis": "1.0.*",
"illuminate/redis": "5.0.*",
"badges/poser": "1.1.*",
"vluzrmos/slack-api": "0.4.*",
"vluzrmos/tinker":"1.0.*"
"vluzrmos/slack-api": "0.4.*"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "~4.0",
"vluzrmos/tinker":"1.0.*"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 6ddf107

Please sign in to comment.