From 4a7c73fe01c75b029828f85cd05a19c116e60fc1 Mon Sep 17 00:00:00 2001 From: Adam Prager Date: Mon, 27 Feb 2017 14:03:55 +0100 Subject: [PATCH] Nicer format for the tab-dump --- Annotation/Job.php | 17 ----------------- Util/Tab.php | 23 ++++++++++++++++++++++- composer.json | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Annotation/Job.php b/Annotation/Job.php index 047d6dd..3485bf1 100644 --- a/Annotation/Job.php +++ b/Annotation/Job.php @@ -47,21 +47,4 @@ class Job * @var string */ public $logFile; - - /** - * @return string - */ - public function __toString() - { - return sprintf( - "%10s %10s %10s %10s %10s %s%s", - str_replace('\/', '/', $this->minute), - $this->hour, - $this->day, - $this->month, - $this->dayOfWeek, - $this->commandLine, - $this->logFile ? ' >> ' . $this->logFile : '' - ); - } } diff --git a/Util/Tab.php b/Util/Tab.php index ca0b0c9..d00f8c5 100644 --- a/Util/Tab.php +++ b/Util/Tab.php @@ -3,6 +3,8 @@ namespace Padam87\CronBundle\Util; use Padam87\CronBundle\Annotation\Job; +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Output\BufferedOutput; class Tab implements \ArrayAccess { @@ -74,7 +76,26 @@ public function offsetUnset($offset) */ public function __toString() { - return (string) $this->vars . PHP_EOL . implode(PHP_EOL, $this->jobs) . PHP_EOL; + $output = new BufferedOutput(); + $table = new Table($output); + $table->setStyle('compact'); + + foreach ($this->jobs as $job) { + $table->addRow( + [ + str_replace('\/', '/', $job->minute), + $job->hour, + $job->day, + $job->month, + $job->dayOfWeek, + $job->commandLine . ($job->logFile ? ' >> ' . $job->logFile : ''), + ] + ); + } + + $table->render(); + + return (string) $this->vars . PHP_EOL . $output->fetch(); } /** diff --git a/composer.json b/composer.json index 9de2d7a..3cb80dd 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "php": ">=5.4.0", "doctrine/annotations": "~1.0", - "symfony/console": "~2.3 || ~3.0", + "symfony/console": "~2.7 || ~3.0", "symfony/process": "~2.3 || ~3.0", "symfony/config": "~2.3 || ~3.0", "symfony/dependency-injection": "~2.3 || ~3.0"