Skip to content

Commit 857aa4f

Browse files
gsdevmeChrisDBrown
authored andcommitted
refactor: drop symfony 2.x support. (#80)
* refactor: remove symfony <=2.8 logic * refactor: drop symfony v2 * refactor: remove symfony 2 assertion
1 parent 11efeda commit 857aa4f

6 files changed

+23
-71
lines changed

DependencyInjection/MarkupJobQueueExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ private function configureConsoleDirectory(array $config, ContainerBuilder $cont
141141
if ($isUsingSymfony4OrGreater && $config['use_root_dir_for_symfony_console']) {
142142
throw new \Exception('The `use_root_dir_for_symfony_console` option cannot be used with Symfony 4+.');
143143
}
144-
$isUsingSymfony2 = Kernel::MAJOR_VERSION === 2;
145-
if ($isUsingSymfony2 || $config['use_root_dir_for_symfony_console']) {
144+
145+
if ($config['use_root_dir_for_symfony_console']) {
146146
$container->setParameter($parameter, $container->getParameter('kernel.root_dir'));
147147

148148
return;

EventSubscriber/AddUuidOptionConsoleCommandEventSubscriber.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Symfony\Component\Console\Event\ConsoleCommandEvent;
77
use Symfony\Component\Console\Input\InputOption;
88
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9-
use Symfony\Component\HttpKernel\Kernel;
109

1110
/**
1211
* Adds the `uuid` option to all console commands
@@ -15,8 +14,6 @@
1514
*/
1615
class AddUuidOptionConsoleCommandEventSubscriber implements EventSubscriberInterface
1716
{
18-
use CheckUsingSymfony28Trait;
19-
2017
/**
2118
* {@inheritdoc}
2219
*/
@@ -43,23 +40,12 @@ public function onConsoleCommand(ConsoleCommandEvent $event)
4340
null
4441
);
4542

46-
//symfony 2.8+ has different behaviour available for adding options
47-
if ($this->isUsingAtLeastSymfony28()) {
48-
//for symfony 2.8 up
49-
$definition = $event->getCommand()->getDefinition();
50-
$definition->addOption($inputOption);
51-
} else {
52-
$inputDefinition = $event->getCommand()->getApplication()->getDefinition();
53-
$inputDefinition->addOption($inputOption);
54-
}
43+
$definition = $event->getCommand()->getDefinition();
44+
$definition->addOption($inputOption);
5545
}
5646

5747
public function bindInput(ConsoleCommandEvent $event)
5848
{
59-
if (!$this->isUsingAtLeastSymfony28()) {
60-
return;
61-
}
62-
6349
$event->getInput()->bind($event->getCommand()->getDefinition());
6450
}
6551
}

EventSubscriber/CheckUsingSymfony28Trait.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

EventSubscriber/CompleteConsoleCommandEventSubscriber.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
use Markup\JobQueueBundle\Model\JobLog;
88
use Markup\JobQueueBundle\Repository\JobLogRepository;
99
use Symfony\Component\Console\ConsoleEvents;
10-
use Symfony\Component\Console\Event\ConsoleCommandEvent;
1110
use Symfony\Component\Console\Event\ConsoleEvent;
1211
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
1312
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
14-
use Symfony\Component\Console\Input\ArgvInput;
15-
use Symfony\Component\Console\Input\InputOption;
1613
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1714

1815
/**
@@ -27,8 +24,6 @@
2724
*/
2825
class CompleteConsoleCommandEventSubscriber implements EventSubscriberInterface
2926
{
30-
use CheckUsingSymfony28Trait;
31-
3227
/**
3328
* @var JobLogRepository
3429
*/
@@ -47,15 +42,11 @@ public function __construct(JobLogRepository $jobLogRepository)
4742
*/
4843
public static function getSubscribedEvents()
4944
{
50-
$consoleErrorEvent = (class_exists('Symfony\Component\Console\Event\ConsoleErrorEvent'))
51-
? ConsoleEvents::ERROR
52-
: ConsoleEvents::EXCEPTION;
53-
5445
return [
5546
ConsoleEvents::TERMINATE => [
5647
['onConsoleTerminate', 10]
5748
],
58-
$consoleErrorEvent => [
49+
ConsoleEvents::ERROR => [
5950
['onConsoleError', 10]
6051
],
6152
];
@@ -67,15 +58,14 @@ public static function getSubscribedEvents()
6758
*/
6859
public function onConsoleTerminate(ConsoleTerminateEvent $event)
6960
{
70-
if ($this->isUsingAtLeastSymfony28()) {
71-
$input = $event->getInput();
72-
} else {
73-
$event->getCommand()->mergeApplicationDefinition();
74-
$input = new ArgvInput();
75-
$input->bind($event->getCommand()->getDefinition());
61+
$input = $event->getInput();
62+
63+
if (!$input->hasOption('uuid')) {
64+
return;
7665
}
7766

7867
$uuid = $input->getOption('uuid');
68+
7969
if (!$uuid) {
8070
return;
8171
}
@@ -102,12 +92,10 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event)
10292
*/
10393
public function onConsoleError(ConsoleEvent $event)
10494
{
105-
if ($this->isUsingAtLeastSymfony28()) {
106-
$input = $event->getInput();
107-
} else {
108-
$event->getCommand()->mergeApplicationDefinition();
109-
$input = new ArgvInput();
110-
$input->bind($event->getCommand()->getDefinition());
95+
$input = $event->getInput();
96+
97+
if (!$input->hasOption('uuid')) {
98+
return;
11199
}
112100

113101
$uuid = $input->getOption('uuid');

EventSubscriber/LogConsoleCommandEventSubscriber.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
*/
1818
class LogConsoleCommandEventSubscriber implements EventSubscriberInterface
1919
{
20-
use CheckUsingSymfony28Trait;
21-
2220
/**
2321
* @var JobLogRepository
2422
*/
@@ -49,14 +47,10 @@ public static function getSubscribedEvents()
4947
*/
5048
public function onConsoleCommand(ConsoleCommandEvent $event)
5149
{
50+
$input = $event->getInput();
5251

53-
// following jiggerypokery can be removed in symfony 2.8+
54-
if ($this->isUsingAtLeastSymfony28()) {
55-
$input = $event->getInput();
56-
} else {
57-
$event->getCommand()->mergeApplicationDefinition();
58-
$input = new ArgvInput();
59-
$input->bind($event->getCommand()->getDefinition());
52+
if (!$input->hasOption('uuid')) {
53+
return;
6054
}
6155

6256
$uuid = $input->getOption('uuid');

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
}
1616
],
1717
"require": {
18-
"symfony/framework-bundle": "^2.3|^3",
19-
"symfony/finder": "^2.3|^3",
20-
"symfony/yaml": "^2.3|^3",
21-
"symfony/console": "^2.3|^3",
22-
"symfony/process": "^2.3|^3",
18+
"symfony/framework-bundle": "^3",
19+
"symfony/finder": "^3",
20+
"symfony/yaml": "^3",
21+
"symfony/console": "^3",
22+
"symfony/process": "^3",
2323
"twig/twig": "^1.12|^2",
2424
"php": ">=7.1.0",
2525
"mtdowling/cron-expression": "1.0.*",
@@ -32,7 +32,7 @@
3232
"require-dev": {
3333
"phpunit/phpunit": "^7.2",
3434
"mockery/mockery": "^1.2",
35-
"symfony/form": "~2.3|^3",
35+
"symfony/form": "^3",
3636
"predis/predis": "^1.0"
3737
},
3838
"suggest": {

0 commit comments

Comments
 (0)