Skip to content

Commit c0d9262

Browse files
authored
Allow Symfony 5.0 (#23)
1 parent dd37aff commit c0d9262

6 files changed

+72
-13
lines changed

.travis.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ cache:
77
- $HOME/.composer/cache/files
88

99
env:
10-
matrix:
11-
- COMPOSER_FLAGS='--no-interaction --no-progress --no-suggest --prefer-dist'
10+
- COMPOSER_FLAGS='--no-interaction --no-progress --no-suggest --prefer-dist'
1211

1312
matrix:
1413
include:
1514
- php: '7.2'
1615
env: PREFER_LOWEST='--prefer-lowest'
1716
- php: '7.3'
17+
- php: '7.4'
18+
env: SYMFONY_VERSION='~4.4.0'
19+
- php: '7.4'
20+
env: SYMFONY_VERSION='~5.0.0'
1821
fast_finish: true
1922

2023
before_install:
2124
- phpenv config-rm xdebug.ini || true
2225
- set -eo pipefail
2326
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
2427
- composer validate --strict
28+
- |
29+
if [ -n "$SYMFONY_VERSION" ]; then
30+
composer require --no-update "symfony/console:${SYMFONY_VERSION}" "symfony/dependency-injection:${SYMFONY_VERSION}" "symfony/process:${SYMFONY_VERSION}" "symfony/framework-bundle:${SYMFONY_VERSION}";
31+
fi
2532
2633
install:
2734
- composer update $COMPOSER_FLAGS $PREFER_LOWEST

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
],
1616

1717
"require": {
18-
"php": "^7.1",
19-
"symfony/console": "^3.0 || ^4.0",
20-
"symfony/dependency-injection": "^3.0 || ^4.1.12",
21-
"symfony/process": "^3.0 || ^4.0",
18+
"php": "^7.2",
19+
"symfony/console": "3.0 || ^4.0 || ^5.0",
20+
"symfony/dependency-injection": "^3.0 || ^4.1.12 || ^5.0",
21+
"symfony/process": "^3.0 || ^4.0 || ^5.0",
2222
"webmozart/assert": "^1.5",
2323
"psr/log": "^1.1"
2424
},
2525
"require-dev": {
2626
"ext-json": "*",
2727
"friendsofphp/php-cs-fixer": "^2.15",
2828
"phpunit/phpunit": "^8.4",
29-
"symfony/framework-bundle": "^4.1"
29+
"symfony/framework-bundle": "^3.0 || ^4.1 || ^5.0"
3030
},
3131

3232
"autoload": {

src/ContainerAwareCommand.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Webmozarts Console Parallelization package.
5+
*
6+
* (c) Webmozarts GmbH <office@webmozarts.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Webmozarts\Console\Parallelization;
15+
16+
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
18+
use Symfony\Component\DependencyInjection\ContainerInterface;
19+
use Webmozart\Assert\Assert;
20+
21+
abstract class ContainerAwareCommand extends Command implements ContainerAwareInterface
22+
{
23+
/**
24+
* @var ContainerInterface|null
25+
*/
26+
private $container;
27+
28+
public function setContainer(ContainerInterface $container = null): void
29+
{
30+
$this->container = $container;
31+
}
32+
33+
protected function getContainer(): ContainerInterface
34+
{
35+
if (null !== $this->container) {
36+
return $this->container;
37+
}
38+
39+
$application = $this->getApplication();
40+
41+
Assert::notNull(
42+
$application,
43+
'The container cannot be retrieved as the application instance is not yet set'
44+
);
45+
46+
return $this->container = $application->getKernel()->getContainer();
47+
}
48+
}

src/Parallelization.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\DependencyInjection\ContainerInterface;
3131
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
3232
use Symfony\Component\Process\PhpExecutableFinder;
33+
use Symfony\Contracts\Service\ResetInterface;
3334
use Throwable;
3435
use function trim;
3536
use Webmozart\Assert\Assert;
@@ -272,15 +273,17 @@ protected function getBatchSize(): int
272273
/**
273274
* Executes the parallelized command.
274275
*/
275-
protected function execute(InputInterface $input, OutputInterface $output): void
276+
protected function execute(InputInterface $input, OutputInterface $output): int
276277
{
277278
if ($input->getOption('child')) {
278279
$this->executeChildProcess($input, $output);
279280

280-
return;
281+
return 0;
281282
}
282283

283284
$this->executeMasterProcess($input, $output);
285+
286+
return 0;
284287
}
285288

286289
/**
@@ -505,7 +508,10 @@ private function runTolerantSingleCommand(
505508

506509
$container = $this->getContainer();
507510

508-
if ($container instanceof ResettableContainerInterface) {
511+
if (
512+
(class_exists(ResetInterface::class) && $container instanceof ResetInterface)
513+
|| (class_exists(ResettableContainerInterface::class) && $container instanceof ResettableContainerInterface)
514+
) {
509515
$container->reset();
510516
}
511517
}

tests/ImportMoviesCommand.php

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Webmozarts\Console\Parallelization;
1515

16-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1716
use Symfony\Component\Console\Input\InputInterface;
1817
use Symfony\Component\Console\Output\OutputInterface;
1918

tests/ParallelizationIntegrationTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Webmozarts\Console\Parallelization;
1515

16-
use function method_exists;
1716
use PHPUnit\Framework\TestCase;
1817
use function preg_replace;
1918
use function str_replace;
@@ -263,6 +262,6 @@ private function getOutput(): string
263262

264263
private function isSymfony3(): bool
265264
{
266-
return method_exists(Application::class, 'getTerminalDimensions');
265+
return Kernel::VERSION_ID < 40000;
267266
}
268267
}

0 commit comments

Comments
 (0)