Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Symfony 8.2: object mapper probe is a fatal error when symfony/translation is not installed

Đang mở
#8,725 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php, symfony
Lĩnh vực
api, backend

Hướng nghiên cứu

Read src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php around line 217 and review the condition introduced for #8627. Reproduce the reported failure with Symfony FrameworkBundle 8.2 and no symfony/translation. Change the version gate so it avoids autoloading the FrameworkBundle command with its optional parent; done when the container build succeeds in that setup.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

API Platform version(s) affected: 5.0.2, and main at 23c4876d1726b17826fbc8901791f8f843eadf42

Description

With symfony/framework-bundle 8.2 and without symfony/translation, the container build stops with a fatal error:

PHP Fatal error:  Uncaught Error: Class "Symfony\Component\Translation\Command\TranslationExtractCommand" not found in vendor/symfony/framework-bundle/Command/TranslationExtractCommand.php:26
#3 vendor/api-platform/core/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php(217): class_exists('Symfony\\Bundle\\...')

In FrameworkBundle 8.2, Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand extends Symfony\Component\Translation\Command\TranslationExtractCommand. FrameworkBundle 8.2 lists symfony/translation only in require-dev, so the parent class can be absent. class_exists() with autoload then includes the file, and PHP throws an Error instead of returning false.

#8627 (for #8626) checks the Translation class first, but it keeps the FrameworkBundle class as a fallback. When symfony/translation is not installed, the first check returns false, the fallback runs, and the same error occurs.

How to reproduce

composer init -n --name=x/repro --stability=dev
composer config prefer-stable true
composer require symfony/framework-bundle:8.2.x-dev
cat > probe.php <<'PHP'
<?php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Translation\Command\TranslationExtractCommand;
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand;
var_dump(class_exists(TranslationExtractCommand::class) || class_exists(FrameworkTranslationExtractCommand::class));
PHP
php probe.php

The condition is the one from ApiPlatformExtension on main. The script stops with the fatal error above.

Possible Solution

Do not autoload a FrameworkBundle class whose parent comes from an optional package. The gate needs to know only that FrameworkBundle is 7.3 or later. For example, check the version with Composer\InstalledVersions, or check a class from 7.3 that has no optional parent.

Additional Context

A production install of Maho got 8.2.x-dev and hit this error on every REST request. composer require symfony/translation is a workaround. When Symfony releases 8.2.0, every application without symfony/translation gets this error.

Ngôn ngữ chính
PHP
Star
2.6k
Fork
989
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
102

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của api-platform/core

Tất cả issue của api-platform/core

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.