Skip to content

Commit

Permalink
Nicer format for the tab-dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Padam87 committed Feb 27, 2017
1 parent 2aef793 commit 4a7c73f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
17 changes: 0 additions & 17 deletions Annotation/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''
);
}
}
23 changes: 22 additions & 1 deletion Util/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4a7c73f

Please sign in to comment.