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

Missing require symfony/translation-contracts #5783

Closed
n-valverde opened this issue Aug 29, 2023 · 0 comments
Closed

Missing require symfony/translation-contracts #5783

n-valverde opened this issue Aug 29, 2023 · 0 comments

Comments

@n-valverde
Copy link
Contributor

API Platform version(s) affected: 3.1

Description
Hello,

Creating a fresh Symfony app with require api-platform/core leads to PHP Fatal error: Trait Symfony\Contracts\Translation\TranslatorTrait" not found.

This is caused by the constructor of ApiPlatform\Symfony\EventListener\DeserializeListener, when the translator component is not installed. It is using symfony/translation-contracts as a fallback without actually requiring it or verifying it's installed.

final class DeserializeListener
{
    public function __construct(....., private ?TranslatorInterface $translator = null)
    {
        if (null === $this->translator) {
            $this->translator = new class() implements TranslatorInterface, LocaleAwareInterface {
                use TranslatorTrait; // Offending line
            };
            $this->translator->setLocale('en');
        }
    }

How to reproduce

  • Create a new symfony app
  • composer require api-platform/core
  • Create a resource and try to hit the route

Possible Solution
Add symfony/translation-contracts to composer require or add a pass to ensure there is either the translator component or the contracts available

soyuka added a commit to soyuka/core that referenced this issue Sep 2, 2023
soyuka added a commit to soyuka/core that referenced this issue Sep 8, 2023
@soyuka soyuka closed this as completed in 50999d6 Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant