Skip to content

Commit

Permalink
Merge pull request #80 from marinalans/master
Browse files Browse the repository at this point in the history
Adding support for Symfonys 3 Table class in Laravel 5.2
  • Loading branch information
liebig authored Jun 15, 2016
2 parents 57ab0e6 + ed2aeae commit b32ad7d
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions src/Liebig/Cron/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,49 @@ public function fire() {
// Get all registered Cron jobs
$jobs = Cron::getCronJobs();

// Create the table helper with headers.
$table = $this->getHelperSet()->get('table');
$table->setHeaders(array('Jobname', 'Expression', 'Activated'));

// Run through all registered jobs
for ($i = 0; $i < count($jobs); $i++) {

// Get current job entry
$job = $jobs[$i];

// If job is enabled or disable use the defined string instead of 1 or 0
$enabled = $job['enabled'] ? 'Enabled' : 'Disabled';

// Add this job to the table.
$table->addRow(array($job['name'], $job['expression']->getExpression(), $enabled));
// Get Laravel version
$laravel = app();
$version = $laravel::VERSION;

if ($version < '5.2') {
// Create the table helper with headers.
$table = $this->getHelperSet()->get('table');
$table->setHeaders(array('Jobname', 'Expression', 'Activated'));

// Run through all registered jobs
for ($i = 0; $i < count($jobs); $i++) {

// Get current job entry
$job = $jobs[$i];

// If job is enabled or disable use the defined string instead of 1 or 0
$enabled = $job['enabled'] ? 'Enabled' : 'Disabled';

// Add this job to the table.
$table->addRow(array($job['name'], $job['expression']->getExpression(), $enabled));
}
} else {
// Create table for new Laravel versions.
$table = new \Symfony\Component\Console\Helper\Table($this->getOutput());
$table->setHeaders(array('Jobname', 'Expression', 'Activated'));

$rows = [];
// Run through all registered jobs
for ($i = 0; $i < count($jobs); $i++) {
// Get current job entry
$job = $jobs[$i];

// If job is enabled or disable use the defined string instead of 1 or 0
$enabled = $job['enabled'] ? 'Enabled' : 'Disabled';

array_push($rows, array($job['name'], $job['expression']->getExpression(), $enabled));

}

$table->setRows($rows);
}


// Render and output the table.
$table->render($this->getOutput());
}
Expand Down

0 comments on commit b32ad7d

Please sign in to comment.