Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(live): ensure non-class service id can be used #1052

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ final class ComponentDefaultActionPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
foreach ($container->findTaggedServiceIds('twig.component') as $class => $component) {
foreach ($container->findTaggedServiceIds('twig.component') as $id => $component) {
if (!($component[0]['live'] ?? false)) {
continue;
}

if (!$class = $container->getDefinition($id)->getClass()) {
throw new \LogicException(sprintf('Live component service "%s" must have a class.', $id));
}

$defaultAction = trim($component[0]['default_action'] ?? '__invoke', '()');

if (!method_exists($class, $defaultAction)) {
Expand Down
6 changes: 5 additions & 1 deletion src/LiveComponent/tests/Fixtures/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\UX\LiveComponent\LiveComponentBundle;
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\Component1;
use Symfony\UX\LiveComponent\Tests\Fixtures\Serializer\Entity2Normalizer;
use Symfony\UX\LiveComponent\Tests\Fixtures\Serializer\MoneyNormalizer;
use Symfony\UX\TwigComponent\TwigComponentBundle;
Expand Down Expand Up @@ -129,7 +130,10 @@ protected function configureContainer(ContainerConfigurator $c): void
->set(Entity2Normalizer::class)->autoconfigure()->autowire()
->load(__NAMESPACE__.'\\Component\\', __DIR__.'/Component')
->set(TestingDeterministicIdTwigExtension::class)
->args([service('ux.live_component.deterministic_id_calculator')]);
->args([service('ux.live_component.deterministic_id_calculator')])
->set('some_service_id', Component1::class)
->tag('twig.component', ['live' => true])
;
}

protected function configureRoutes(RoutingConfigurator $routes): void
Expand Down
Loading