Skip to content

Commit 17f73c4

Browse files
committed
ensure only live components can be used as such
1 parent fe4c1a6 commit 17f73c4

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
4747
'key' => $attribute->name,
4848
'template' => $attribute->template,
4949
'default_action' => $attribute->defaultAction,
50+
'live' => true,
5051
]))
5152
->addTag('controller.service_arguments')
5253
;

src/LiveComponent/src/EventListener/LiveComponentSubscriber.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public function onKernelRequest(RequestEvent $event): void
7878
throw new NotFoundHttpException(sprintf('Component "%s" not found.', $componentName), $e);
7979
}
8080

81+
if (!isset($config['live'])) {
82+
throw new NotFoundHttpException(sprintf('"%s" is not a Live Component.', $config['class']));
83+
}
84+
8185
$request->attributes->set('_component_config', $config);
8286

8387
if ('get' === $action) {

src/LiveComponent/src/Twig/LiveComponentRuntime.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function renderLiveAttributes(Environment $env, array $context): string
4343
throw new \LogicException('init_live_component can only be called within a component template.');
4444
}
4545

46+
if (!isset($context['_component_config']['live'])) {
47+
throw new \LogicException(sprintf('"%s" is not a Live Component.', $context['_component_config']['class']));
48+
}
49+
4650
$name = $context['_component_config']['name'];
4751
$url = $this->urlGenerator->generate('live_component', ['component' => $name]);
4852
$data = $this->hydrator->dehydrate($context['this']);

src/LiveComponent/tests/Fixture/Kernel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
7070

7171
if (self::VERSION_ID < 50300) {
7272
// 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');
73+
$componentA->addTag('twig.component', ['key' => 'component1', 'live' => true])->addTag('controller.service_arguments');
74+
$componentB->addTag('twig.component', ['key' => 'component2', 'live' => true, 'default_action' => 'defaultAction'])->addTag('controller.service_arguments');
75+
$componentC->addTag('twig.component', ['key' => 'component3', 'live' => true])->addTag('controller.service_arguments');
76+
$componentF->addTag('twig.component', ['key' => 'component6', 'live' => true])->addTag('controller.service_arguments');
7777
}
7878

7979
$sessionConfig = self::VERSION_ID < 50300 ? ['storage_id' => 'session.storage.mock_file'] : ['storage_factory_id' => 'session.storage.factory.mock_file'];

0 commit comments

Comments
 (0)