Установлена Symfony 7, --webapp.
Конверт по умолчанию, настройки.
Воспроизвести
Создать контроллер ping.
Создать еще один каталог «Dto» и пустой класс UserDto.php.
Сделать НЕПРАВИЛЬНОЕ ПРОСТРАНСТВО ИМЕН, т.е.
Код: Выделить всё
namespace App\Dto\SomeWrong;
class UserDto
{
}
Имеет 200 с ответом: версия symfony: 7.1.6
Сделано APP_DEBUG=0 в .env (dev)
Содержит ошибку 500
Код: Выделить всё
Uncaught Exception: Expected to find class "App\Dto\UserDto" in file
"/test_project/src/Dto/UserDto.php" while importing services from resource "../src/",
but it was not found! Check the namespace prefix used with the resource in /test_project/config/services.yaml
(which is being imported from "/test_project/src/Kernel.php").
Например, можно увидеть исключение после запроса, если в index.php создайте DebugClassLoader::disable().
Внутри DebugClassLoader::checkClass() он выдает RuntimeException в неправильном пространстве имен, его можно просмотреть с помощью ./bin/ консольная отладка: контейнер UserDto
Код: Выделить всё
Tags container.error (message: The autoloader expected class "App\Dto\UserDto"
to be defined in file "/test_project/vendor/composer/../../src/Dto/UserDto.php".
The file was found but the class was not in it, the class name or namespace probably has a typo.)
Похоже, что Symfony перехватывает исключения и подавляет их.
Теперь я нашел решение для обнаружения этой ошибки с помощью правил phpcs + slevomat
Код: Выделить всё
SlevomatCodingStandard.Files.TypeNameMatchesFileName
Можно ли это как-то настроить?
Подробнее здесь: https://stackoverflow.com/questions/791 ... ny-7-debug
Мобильная версия