Skip to content

Commit c7474a5

Browse files
author
Ian Jenkins
committed
Use new table helper if available, else fallback to the old one.
Particularly important for Symfony 3 support as `TableHelper` was removed in Symfony 3. The new Table helper was added in Symfony 2.5 and the old one deprecated, but as we support 2.3 and upwards we cannot guarantee the new one being available and thus the fallback is required.
1 parent b4c3acd commit c7474a5

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

Command/DebugCommand.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Bernard\BernardBundle\Command;
44

55
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6+
use Symfony\Component\Console\Helper\Table;
67
use Symfony\Component\Console\Input\InputInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
89

@@ -28,12 +29,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
2829
$rows[] = [$key, $val];
2930
}
3031

31-
/** @var \Symfony\Component\Console\Helper\TableHelper $helper */
32-
$helper = $this->getHelper('table');
33-
$helper
34-
->setHeaders(['Message', 'Service'])
35-
->addRows($rows)
36-
->render($output)
37-
;
32+
$headers = ['Message', 'Service'];
33+
34+
if (class_exists('Symfony\Component\Console\Helper\Table')) {
35+
$table = new Table($output);
36+
$table
37+
->setHeaders($headers)
38+
->addRows($rows)
39+
->render()
40+
;
41+
} else {
42+
/** @var \Symfony\Component\Console\Helper\TableHelper $helper */
43+
$helper = $this->getHelper('table');
44+
$helper
45+
->setHeaders($headers)
46+
->addRows($rows)
47+
->render($output)
48+
;
49+
}
3850
}
3951
}

0 commit comments

Comments
 (0)