Skip to content

Commit

Permalink
Alguos ajustes y nuevos metodos
Browse files Browse the repository at this point in the history
  • Loading branch information
elmijo committed Sep 26, 2016
1 parent a3cf8a6 commit 3123fa5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 13 deletions.
72 changes: 59 additions & 13 deletions Console/Command/BuilderBoxAwareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ abstract class BuilderBoxAwareCommand extends ContainerAwareCommand
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface|null
*/
private $container;
protected $container;

/**
* @var \Symfony\Component\Console\Style\SymfonyStyle|null
*/
protected $style;

/**
* @var \Symfony\Component\Console\Input\InputInterface
*/
protected $input;

/**
* @var Symfony\Component\Console\Output\OutputInterface
*/
Expand All @@ -52,12 +52,12 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->style = new SymfonyStyle($input, $output);

try {
$container = $this->getContainer();
$this->container = $this->getContainer();
foreach($this->getRequiredServices() as $key => $value) {
$this->{$key} = $container->get($value);
$this->{$key} = $this->container->get($value);
}
} catch (\Exception $e) {}

return $this;
}

Expand Down Expand Up @@ -91,13 +91,37 @@ final protected function listing(array $elements)
return $this;
}

final protected function textInfo($message)
{
$this->multilineText($message, CommandStyle::COLOR_BLUE);
return $this;
}

final protected function textWarning($message)
{
$this->multilineText($message, CommandStyle::COLOR_YELLOW);
return $this;
}

final protected function textSuccess($message)
{
$this->multilineText($message, CommandStyle::COLOR_GREEN);
return $this;
}

final protected function textError($message)
{
$this->multilineText($message, CommandStyle::COLOR_RED);
return $this;
}

/**
* @see \Symfony\Component\Console\Style\StyleInterface::text()
* @return self
*/
final protected function text($message)
{
$this->multiline($message, 'text');
$this->multilineBlock($message, 'text');
return $this;
}

Expand All @@ -107,7 +131,7 @@ final protected function text($message)
*/
final protected function comment($message)
{
$this->multiline($message, 'comment');
$this->multilineBlock($message, 'comment');
return $this;
}

Expand All @@ -117,7 +141,7 @@ final protected function comment($message)
*/
final protected function success($message)
{
$this->multiline($message, 'success');
$this->multilineBlock($message, 'success');
return $this;
}

Expand All @@ -127,7 +151,7 @@ final protected function success($message)
*/
final protected function error($message)
{
$this->multiline($message, 'error');
$this->multilineBlock($message, 'error');
return $this;
}

Expand Down Expand Up @@ -177,7 +201,7 @@ final protected function info($message)
*/
final protected function note($message)
{
$this->multiline($message, 'note');
$this->multilineBlock($message, 'note');
return $this;
}

Expand All @@ -187,7 +211,7 @@ final protected function note($message)
*/
final protected function caution($message)
{
$this->multiline($message, 'caution');
$this->multilineBlock($message, 'caution');
return $this;
}

Expand Down Expand Up @@ -296,10 +320,32 @@ final protected function confirm($question, $default = true)
* @param string|array $message
* @param string $method
*/
private function multiline($message, $method)
private function multilineBlock($message, $method)
{
if (in_array(gettype($message), ['string', 'array'])) {
$this->style->{$method}($message);
}
}

private function multilineText($message, $fontColor = "default", $backgroundColor = "default")
{
if (is_array($message)) {
foreach ($message as $key => $value) {
$message[$key] = CommandStyle::styleText(
$message,
$fontColor,
$backgroundColor
);
}
} elseif(is_string($message)) {
$message = CommandStyle::styleText(
$message,
$fontColor,
$backgroundColor
);
}
if (in_array(gettype($message), ['string', 'array'])) {
$this->output->writeln($message);
}
}
}
13 changes: 13 additions & 0 deletions Console/Command/CommandStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ public static function styleBlock($fontColor, $backgroundColor)
return sprintf("fg=%s;bg=%s", $fontColor, $backgroundColor);
}

public static function styleText($text, $fontColor = "default", $backgroundColor = "default")
{

return sprintf(
"<%s>%s</>",
static::styleBlock(
$fontColor,
$backgroundColor
),
$text
);
}

private static function validateColor($color)
{
return in_array(
Expand Down

0 comments on commit 3123fa5

Please sign in to comment.