Skip to content

Commit 896f417

Browse files
committed
minor #252 [Twig][Live] Require Symfony 5.4+ (kbond)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Twig][Live] Require Symfony 5.4+ | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | n/a | License | MIT Both `@weaverryan` and I agree that bumping the min requirement of these library's would be beneficial. The primary reason being, the usability pre-5.3 is sub-par. Component's cannot be autoconfigured with the `AsTwigComponent`/`AsLiveComponent` attributes - they must be tagged manually. Requiring 5.4 makes documentation simpler, cleans up the test suite, and fixes some other compatibility issues. We figured, as we require PHP 8.0 already, requiring Symfony 5.4+ would be palatable. Commits ------- 2a14b8a [Twig][Live] Require Symfony 5.4+
2 parents 112ed03 + 2a14b8a commit 896f417

File tree

14 files changed

+58
-162
lines changed

14 files changed

+58
-162
lines changed

src/LiveComponent/composer.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@
3030
"symfony/ux-twig-component": "^2.0"
3131
},
3232
"require-dev": {
33-
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
34-
"symfony/dependency-injection": "^4.4.2|^5.0|^6.0",
35-
"symfony/twig-bundle": "^4.4|^5.0|^6.0",
36-
"symfony/security-csrf": "^4.4|^5.0|^6.0",
37-
"symfony/serializer": "^4.4|^5.0|^6.0",
38-
"symfony/validator": "^4.4|^5.0|^6.0",
39-
"symfony/phpunit-bridge": "^5.2|^6.0",
4033
"doctrine/annotations": "^1.0",
4134
"doctrine/doctrine-bundle": "^2.0",
4235
"doctrine/orm": "^2.7",
43-
"zenstruck/foundry": "^1.10",
44-
"zenstruck/browser": "^0.9.1"
36+
"symfony/dependency-injection": "^5.4|^6.0",
37+
"symfony/framework-bundle": "^5.4|^6.0",
38+
"symfony/phpunit-bridge": "^6.0",
39+
"symfony/security-csrf": "^5.4|^6.0",
40+
"symfony/serializer": "^5.4|^6.0",
41+
"symfony/twig-bundle": "^5.4|^6.0",
42+
"symfony/validator": "^5.4|^6.0",
43+
"zenstruck/browser": "^0.9.1",
44+
"zenstruck/foundry": "^1.10"
45+
},
46+
"conflict": {
47+
"symfony/config": "<5.4.0"
48+
},
49+
"config": {
50+
"sort-packages": true
4551
},
4652
"extra": {
4753
"thanks": {

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@ final class LiveComponentExtension extends Extension
3838
{
3939
public function load(array $configs, ContainerBuilder $container): void
4040
{
41-
if (method_exists($container, 'registerAttributeForAutoconfiguration')) {
42-
$container->registerAttributeForAutoconfiguration(
43-
AsLiveComponent::class,
44-
function (ChildDefinition $definition, AsLiveComponent $attribute) {
45-
$definition
46-
->addTag('twig.component', array_filter([
47-
'key' => $attribute->name,
48-
'template' => $attribute->template,
49-
'default_action' => $attribute->defaultAction,
50-
]))
51-
->addTag('controller.service_arguments')
52-
;
53-
}
54-
);
55-
}
41+
$container->registerAttributeForAutoconfiguration(
42+
AsLiveComponent::class,
43+
function (ChildDefinition $definition, AsLiveComponent $attribute) {
44+
$definition
45+
->addTag('twig.component', array_filter([
46+
'key' => $attribute->name,
47+
'template' => $attribute->template,
48+
'default_action' => $attribute->defaultAction,
49+
]))
50+
->addTag('controller.service_arguments')
51+
;
52+
}
53+
);
5654

5755
$container->registerForAutoconfiguration(PropertyHydratorInterface::class)
5856
->addTag('twig.component.property_hydrator')

src/LiveComponent/tests/ContainerBC.php

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

src/LiveComponent/tests/Fixture/Kernel.php

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Symfony\Component\HttpFoundation\Response;
2222
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
2323
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
24-
use Symfony\Component\Routing\RouteCollectionBuilder;
2524
use Symfony\UX\LiveComponent\LiveComponentBundle;
2625
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component1;
2726
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component2;
@@ -63,27 +62,17 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
6362
// disable logging errors to the console
6463
$c->register('logger', NullLogger::class);
6564

66-
$componentA = $c->register(Component1::class)->setAutoconfigured(true)->setAutowired(true);
67-
$componentB = $c->register(Component2::class)->setAutoconfigured(true)->setAutowired(true);
68-
$componentC = $c->register(Component3::class)->setAutoconfigured(true)->setAutowired(true);
69-
$componentF = $c->register(Component6::class)->setAutoconfigured(true)->setAutowired(true);
70-
71-
if (self::VERSION_ID < 50300) {
72-
// add tag manually
73-
$componentA->addTag('twig.component', ['key' => 'component1'])->addTag('controller.service_arguments');
74-
$componentB->addTag('twig.component', ['key' => 'component2', 'default_action' => 'defaultAction'])->addTag('controller.service_arguments');
75-
$componentC->addTag('twig.component', ['key' => 'component3'])->addTag('controller.service_arguments');
76-
$componentF->addTag('twig.component', ['key' => 'component6'])->addTag('controller.service_arguments');
77-
}
78-
79-
$sessionConfig = self::VERSION_ID < 50300 ? ['storage_id' => 'session.storage.mock_file'] : ['storage_factory_id' => 'session.storage.factory.mock_file'];
65+
$c->register(Component1::class)->setAutoconfigured(true)->setAutowired(true);
66+
$c->register(Component2::class)->setAutoconfigured(true)->setAutowired(true);
67+
$c->register(Component3::class)->setAutoconfigured(true)->setAutowired(true);
68+
$c->register(Component6::class)->setAutoconfigured(true)->setAutowired(true);
8069

8170
$c->loadFromExtension('framework', [
8271
'secret' => 'S3CRET',
8372
'test' => true,
8473
'router' => ['utf8' => true],
8574
'secrets' => false,
86-
'session' => $sessionConfig,
75+
'session' => ['storage_factory_id' => 'session.storage.factory.mock_file'],
8776
]);
8877

8978
$c->loadFromExtension('twig', [
@@ -108,21 +97,11 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
10897
]);
10998
}
11099

111-
/**
112-
* @param RoutingConfigurator|RouteCollectionBuilder $routes
113-
*/
114-
protected function configureRoutes($routes): void
100+
protected function configureRoutes(RoutingConfigurator $routes): void
115101
{
116102
$routes->import('@LiveComponentBundle/Resources/config/routing/live_component.xml');
117103

118-
if ($routes instanceof RoutingConfigurator) {
119-
$routes->add('template', '/render-template/{template}')->controller('kernel::renderTemplate');
120-
$routes->add('homepage', '/')->controller('kernel::index');
121-
122-
return;
123-
}
124-
125-
$routes->add('/render-template/{template}', 'kernel::renderTemplate', 'template');
126-
$routes->add('/', 'kernel::index', 'homepage');
104+
$routes->add('template', '/render-template/{template}')->controller('kernel::renderTemplate');
105+
$routes->add('homepage', '/')->controller('kernel::index');
127106
}
128107
}

src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1515
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1616
use Symfony\UX\LiveComponent\LiveComponentHydrator;
17-
use Symfony\UX\LiveComponent\Tests\ContainerBC;
1817
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component1;
1918
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component2;
2019
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component6;
@@ -31,7 +30,6 @@
3130
*/
3231
final class LiveComponentSubscriberTest extends KernelTestCase
3332
{
34-
use ContainerBC;
3533
use Factories;
3634
use HasBrowser;
3735
use ResetDatabase;

src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
1515
use Symfony\UX\LiveComponent\Attribute\LiveProp;
1616
use Symfony\UX\LiveComponent\LiveComponentHydrator;
17-
use Symfony\UX\LiveComponent\Tests\ContainerBC;
1817
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component1;
1918
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component2;
2019
use Symfony\UX\LiveComponent\Tests\Fixture\Component\Component3;
@@ -29,7 +28,6 @@
2928
*/
3029
final class LiveComponentHydratorTest extends KernelTestCase
3130
{
32-
use ContainerBC;
3331
use Factories;
3432
use ResetDatabase;
3533

src/LiveComponent/tests/Integration/Twig/LiveComponentExtensionTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
namespace Symfony\UX\LiveComponent\Tests\Integration;
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
15-
use Symfony\UX\LiveComponent\Tests\ContainerBC;
1615

1716
/**
1817
* @author Kevin Bond <[email protected]>
1918
*/
2019
final class LiveComponentExtensionTest extends KernelTestCase
2120
{
22-
use ContainerBC;
23-
2421
public function testGetComponentUrl(): void
2522
{
2623
$rendered = self::getContainer()->get('twig')->render('component_url.html.twig', [

src/TwigComponent/composer.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@
2727
},
2828
"require": {
2929
"php": ">=8.0",
30-
"twig/twig": "^2.0|^3.0",
31-
"symfony/property-access": "^4.4|^5.0|^6.0",
32-
"symfony/dependency-injection": "^4.4|^5.0|^6.0"
30+
"symfony/dependency-injection": "^5.4|^6.0",
31+
"symfony/property-access": "^5.4|^6.0",
32+
"twig/twig": "^2.0|^3.0"
3333
},
3434
"require-dev": {
35-
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
36-
"symfony/twig-bundle": "^4.4|^5.0|^6.0",
37-
"symfony/phpunit-bridge": "^5.2|^6.0"
35+
"symfony/framework-bundle": "^5.4|^6.0",
36+
"symfony/phpunit-bridge": "^6.0",
37+
"symfony/twig-bundle": "^5.4|^6.0"
3838
},
3939
"conflict": {
40-
"symfony/dependency-injection": "<4.4.18,<5.1.10,<5.2.1"
40+
"symfony/config": "<5.4.0"
41+
},
42+
"config": {
43+
"sort-packages": true
4144
},
4245
"extra": {
4346
"thanks": {

src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ final class TwigComponentExtension extends Extension
3434
{
3535
public function load(array $configs, ContainerBuilder $container): void
3636
{
37-
if (method_exists($container, 'registerAttributeForAutoconfiguration')) {
38-
$container->registerAttributeForAutoconfiguration(
39-
AsTwigComponent::class,
40-
static function (ChildDefinition $definition, AsTwigComponent $attribute) {
41-
$definition->addTag('twig.component', array_filter([
42-
'key' => $attribute->name,
43-
'template' => $attribute->template,
44-
]));
45-
}
46-
);
47-
}
37+
$container->registerAttributeForAutoconfiguration(
38+
AsTwigComponent::class,
39+
static function (ChildDefinition $definition, AsTwigComponent $attribute) {
40+
$definition->addTag('twig.component', array_filter([
41+
'key' => $attribute->name,
42+
'template' => $attribute->template,
43+
]));
44+
}
45+
);
4846

4947
$container->register('ux.twig_component.component_factory', ComponentFactory::class)
5048
->setArguments([

src/TwigComponent/src/Resources/doc/index.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ as simple as possible::
7979
{
8080
}
8181

82-
**Note:** If this class is auto-configured, *and* you're using Symfony
83-
5.3+, then you're all set. Otherwise, register the service and tag it
84-
with ``twig.component`` and with a ``key`` tag attribute for the
85-
component's name (``alert``).
86-
8782
Step 2 is to create a template for this component. By default, templates
8883
live in ``templates/components/{Component Name}.html.twig``, where
8984
``{Component Name}`` is whatever you passed as the first argument to the
@@ -184,12 +179,6 @@ as the second argument to the ``AsTwigComponent`` attribute:
184179
// ...
185180
}
186181
187-
**Note:** If this class is auto-configured, *and* you're using Symfony
188-
5.3+, then you're all set. Otherwise, register the service and tag it
189-
with ``twig.component`` and with a ``key`` tag attribute for the
190-
component's name (``alert``) and a ``template`` tag attribute
191-
(``my/custom/template.html.twig``).
192-
193182
The mount() Method
194183
~~~~~~~~~~~~~~~~~~
195184

src/TwigComponent/tests/Fixture/Kernel.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Config\Loader\LoaderInterface;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
20-
use Symfony\Component\Routing\RouteCollectionBuilder;
2120
use Symfony\UX\TwigComponent\Tests\Fixture\Component\ComponentA;
2221
use Symfony\UX\TwigComponent\Tests\Fixture\Component\ComponentB;
2322
use Symfony\UX\TwigComponent\Tests\Fixture\Component\ComponentC;
@@ -51,29 +50,16 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
5150
]);
5251

5352
$c->register(ServiceA::class)->setAutoconfigured(true)->setAutowired(true);
54-
55-
$componentA = $c->register(ComponentA::class)->setAutoconfigured(true)->setAutowired(true);
56-
$componentB = $c->register('component_b', ComponentB::class)->setAutoconfigured(true)->setAutowired(true);
57-
$componentC = $c->register(ComponentC::class)->setAutoconfigured(true)->setAutowired(true);
58-
53+
$c->register(ComponentA::class)->setAutoconfigured(true)->setAutowired(true);
54+
$c->register('component_b', ComponentB::class)->setAutoconfigured(true)->setAutowired(true);
55+
$c->register(ComponentC::class)->setAutoconfigured(true)->setAutowired(true);
5956
$c->register('component_d', ComponentB::class)->addTag('twig.component', [
6057
'key' => 'component_d',
6158
'template' => 'components/custom2.html.twig',
6259
]);
6360

64-
if (self::VERSION_ID < 50300) {
65-
// add tag manually
66-
$componentA->addTag('twig.component', ['key' => 'component_a']);
67-
$componentB->addTag('twig.component', ['key' => 'component_b', 'template' => 'components/custom1.html.twig']);
68-
$componentC->addTag('twig.component', ['key' => 'component_c']);
69-
}
70-
7161
if ('missing_key' === $this->environment) {
7262
$c->register('missing_key', ComponentB::class)->setAutowired(true)->addTag('twig.component');
7363
}
7464
}
75-
76-
protected function configureRoutes(RouteCollectionBuilder $routes): void
77-
{
78-
}
7965
}

src/TwigComponent/tests/Integration/ComponentExtensionTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
*/
2020
final class ComponentExtensionTest extends KernelTestCase
2121
{
22-
use ContainerBC;
23-
2422
public function testCanRenderComponent(): void
2523
{
2624
$output = self::getContainer()->get(Environment::class)->render('template_a.html.twig');

src/TwigComponent/tests/Integration/ComponentFactoryTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
final class ComponentFactoryTest extends KernelTestCase
2525
{
26-
use ContainerBC;
27-
2826
public function testCreatedComponentsAreNotShared(): void
2927
{
3028
/** @var ComponentFactory $factory */

src/TwigComponent/tests/Integration/ContainerBC.php

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

0 commit comments

Comments
 (0)