Skip to content

[ExpressionLanguage] Add function service #1867

Closed
@seb-jean

Description

@seb-jean

Symfony version(s) affected

7.0.7

Description

I have an error :

The function "service" does not exist around position 1 for expression `service('App\Service\Generator').generate('songs_by_artist_' ~ entity.getId())`.

How to reproduce

I have the following entity:

<?php

namespace App\Entity;

use App\Repository\BookRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\UX\Turbo\Attribute\Broadcast;

#[ORM\Entity(repositoryClass: BookRepository::class)]
#[Broadcast(topics: ["@=service('App\\Service\\Generator').generate('songs_by_artist_' ~ entity.getId())", 'books'], template: 'broadcast/Book.stream.html.twig', private: true)]
class Book
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255)]
    private ?string $title = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(string $title): static
    {
        $this->title = $title;

        return $this;
    }
}

But when I create a Book entity, I get the following error:

The function "service" does not exist around position 1 for expression `service('App\Service\Generator').generate('songs_by_artist_' ~ entity.getId())`.

In my case, $this->functions is enum and constant : https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/ExpressionLanguage/Parser.php#L242

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TurboquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions