Skip to content

Commit 2364545

Browse files
authored
Relax minimum php version (#5)
1 parent 0612bca commit 2364545

18 files changed

+46
-51
lines changed

.php_cs.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ return PhpCsFixer\Config::create()
2121
->setRules([
2222
'@Symfony' => true,
2323
'@Symfony:risky' => true,
24-
'declare_strict_types' => true,
2524
'header_comment' => [
2625
'header' => $header,
2726
'location' => 'after_open',

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=8.0",
19+
"php": ">=7.2.5",
2020
"symfony/config": "^4.4|^5.2",
2121
"symfony/dependency-injection": "^4.4|^5.2",
2222
"symfony/http-kernel": "^4.4|^5.2"

src/Broadcaster/BroadcasterInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\Broadcaster;
1513

1614
/**

src/Broadcaster/TwigMercureBroadcaster.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\Broadcaster;
1513

1614
use Symfony\Component\Mercure\PublisherInterface;
@@ -40,6 +38,11 @@
4038
*/
4139
final class TwigMercureBroadcaster implements BroadcasterInterface
4240
{
41+
private $twig;
42+
private $messageBus;
43+
private $publisher = null;
44+
private $expressionLanguage = null;
45+
4346
private const OPTIONS = [
4447
// Twig options
4548
'template',
@@ -52,12 +55,16 @@ final class TwigMercureBroadcaster implements BroadcasterInterface
5255
];
5356

5457
public function __construct(
55-
private Environment $twig,
56-
private ?MessageBusInterface $messageBus = null,
57-
private ?PublisherInterface $publisher = null,
58-
private ?ExpressionLanguage $expressionLanguage = null,
59-
private ?string $entityNamespace = null,
58+
Environment $twig,
59+
?MessageBusInterface $messageBus = null,
60+
?PublisherInterface $publisher = null,
61+
?ExpressionLanguage $expressionLanguage = null,
62+
?string $entityNamespace = null
6063
) {
64+
if (80000 > \PHP_VERSION_ID) {
65+
throw new \LogicException('The broadcast feature requires PHP 8.0 or greater, you must either upgrade to PHP 8 or disable it.');
66+
}
67+
6168
if (null === $this->messageBus && null === $this->publisher) {
6269
throw new \InvalidArgumentException('A message bus or a publisher must be provided.');
6370
}
@@ -108,15 +115,17 @@ private function normalizeOptions(object $entity, string $action, array $options
108115
$options = $this->expressionLanguage->evaluate($options[0], ['entity' => $entity, 'action' => $action]);
109116
}
110117

118+
$entityClass = get_class($entity);
119+
111120
if ($extraKeys = array_diff(array_keys($options), self::OPTIONS)) {
112-
throw new \InvalidArgumentException(sprintf('Unknown broadcast options "%s" on class "%s". Valid options are: "%s"', implode('", "', $extraKeys), $entity::class, implode('", "', self::OPTIONS)));
121+
throw new \InvalidArgumentException(sprintf('Unknown broadcast options "%s" on class "%s". Valid options are: "%s"', implode('", "', $extraKeys), $entityClass, implode('", "', self::OPTIONS)));
113122
}
114123

115-
$options['topics'] = (array) ($options['topics'] ?? $entity::class);
124+
$options['topics'] = (array) ($options['topics'] ?? $entityClass);
116125
if (!isset($options['template'])) {
117-
$dir = $entity::class;
118-
if (null !== $this->entityNamespace && str_starts_with($entity::class, $this->entityNamespace)) {
119-
$dir = substr($entity::class, strlen($this->entityNamespace));
126+
$dir = $entityClass;
127+
if (null !== $this->entityNamespace && 0 !== strpos($entityClass, $this->entityNamespace)) {
128+
$dir = substr($entityClass, strlen($this->entityNamespace));
120129
}
121130

122131
$options['template'] = sprintf('broadcast/%s.stream.html.twig', str_replace('\\', '/', $dir));

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\DependencyInjection;
1513

1614
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -35,7 +33,7 @@ public function getConfigTreeBuilder(): TreeBuilder
3533
->end()
3634
->end()
3735
->arrayNode('broadcast')
38-
->addDefaultsIfNotSet()
36+
->{80000 <= \PHP_VERSION_ID ? 'canBeDisabled' : 'canBeEnabled'}()
3937
->children()
4038
->scalarNode('entity_namespace')->info('Prefix to strip when looking for broadcast templates')->defaultValue('App\\Entity\\')->end()
4139
->end()

src/DependencyInjection/TurboExtension.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\DependencyInjection;
1513

1614
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1715
use Doctrine\ORM\EntityManagerInterface;
1816
use Symfony\Bundle\MercureBundle\MercureBundle;
1917
use Symfony\Bundle\TwigBundle\TwigBundle;
18+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
2019
use Symfony\Component\Config\FileLocator;
2120
use Symfony\Component\DependencyInjection\ContainerBuilder;
2221
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
@@ -38,6 +37,10 @@ public function load(array $configs, ContainerBuilder $container): void
3837
$loader = (new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')));
3938
$loader->load('services.php');
4039

40+
if ($config['broadcast']['enabled'] && 80000 > \PHP_VERSION_ID) {
41+
throw new InvalidConfigurationException('Enabling the "broadcast" config option requires PHP 8 or higher.');
42+
}
43+
4144
if (class_exists(TwigBundle::class)) {
4245
$loader->load('twig.php');
4346
if (isset($config['mercure']['subscribe_url'])) {
@@ -54,7 +57,7 @@ public function load(array $configs, ContainerBuilder $container): void
5457
}
5558
}
5659

57-
if (class_exists(DoctrineBundle::class) && interface_exists(EntityManagerInterface::class)) {
60+
if (class_exists(DoctrineBundle::class) && interface_exists(EntityManagerInterface::class) && 80000 <= \PHP_VERSION_ID) {
5861
$loader->load('doctrine.php');
5962
}
6063
}

src/Doctrine/BroadcastListener.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\Doctrine;
1513

1614
use Doctrine\Common\EventArgs;
@@ -30,6 +28,8 @@
3028
*/
3129
final class BroadcastListener implements ResetInterface
3230
{
31+
private $broadcaster;
32+
3333
/**
3434
* @var \SplObjectStorage<object, object>
3535
*/
@@ -43,9 +43,12 @@ final class BroadcastListener implements ResetInterface
4343
*/
4444
private \SplObjectStorage $removedEntities;
4545

46-
public function __construct(
47-
private BroadcasterInterface $broadcaster,
48-
) {
46+
public function __construct(BroadcasterInterface $broadcaster)
47+
{
48+
if (80000 > \PHP_VERSION_ID) {
49+
throw new \LogicException('The broadcast feature requires PHP 8.0 or greater, you must either upgrade to PHP 8 or disable it.');
50+
}
51+
4952
$this->reset();
5053
}
5154

src/Resources/config/broadcaster.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1513

1614
use Symfony\UX\Turbo\Broadcaster\BroadcasterInterface;

src/Resources/config/doctrine.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1513

1614
use Symfony\UX\Turbo\Broadcaster\BroadcasterInterface;

src/Resources/config/services.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1513

1614
use Symfony\UX\Turbo\Stream\AddTurboStreamFormatSubscriber;

src/Resources/config/twig.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1513

1614
use Symfony\UX\Turbo\Twig\FrameExtension;

src/Stream/AddTurboStreamFormatSubscriber.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\Stream;
1513

1614
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -31,7 +29,7 @@ final class AddTurboStreamFormatSubscriber implements EventSubscriberInterface
3129
public function onKernelRequest(RequestEvent $event): void
3230
{
3331
$request = $event->getRequest();
34-
if (!($accept = $request->headers->get('Accept')) || !str_starts_with($accept, TurboStreamResponse::STREAM_MEDIA_TYPE)) {
32+
if (!($accept = $request->headers->get('Accept')) || 0 !== strpos($accept, TurboStreamResponse::STREAM_MEDIA_TYPE)) {
3533
return;
3634
}
3735

src/Stream/TurboStreamResponse.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\Stream;
1513

1614
use Symfony\Component\HttpFoundation\Response;

src/Twig/FrameExtension.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\Twig;
1513

1614
use Twig\Extension\AbstractExtension;

src/Twig/StreamExtension.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace Symfony\UX\Turbo\Twig;
1513

1614
use Twig\Extension\AbstractExtension;
@@ -31,9 +29,12 @@ final class StreamExtension extends AbstractExtension
3129
'remove' => true,
3230
];
3331

34-
public function __construct(
35-
private ?string $mercureHub = null,
36-
) {}
32+
private $mercureHub;
33+
34+
public function __construct(?string $mercureHub = null)
35+
{
36+
$this->mercureHub = $mercureHub;
37+
}
3738

3839
public function getFunctions(): iterable
3940
{

tests/BroadcastTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* BroadcastTest.
2020
*
2121
* @author Kévin Dunglas <[email protected]>
22+
*
23+
* @requires PHP >= 8.0
2224
*/
2325
class BroadcastTest extends PantherTestCase
2426
{

tests/app/Entity/Book.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
namespace App\Entity;
1513

1614
use Doctrine\ORM\Mapping as ORM;

tests/app/public/index.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
declare(strict_types=1);
13-
1412
use App\Kernel;
1513
use Symfony\Bundle\FrameworkBundle\Console\Application;
1614
use Symfony\Component\HttpFoundation\Request;

0 commit comments

Comments
 (0)