среда, 22 января 2014 г.

Вывод 404-й страницы в Symfony2 с учётом авторизации

Появилась задача для 404-й ошибки выводить разные шаблоны в зависимости от того авторизован ли пользователь. Оказалось что стандартными средствами Symfony это сделать не получится, так как с версии 2.1 система рутинга запускается до компонента security:
The Firewall listener is now registered after the Router listener. This means that specific Firewall URLs (like /login_check and /logout) must now have proper routes defined in your routing configuration. Also, if you have a custom 404 error page, make sure that you do not use any security related features such as is_granted on it.
Источник - https://github.com/symfony/symfony/blob/master/UPGRADE-2.1.md#security

Получается, что в шаблоне 404-й страницы или переопределив контроллер для данной страницы не получится определить авторизован пользователь или нет.

Также обнаружился тикет на гитхабе где авторы Symfony разводят руками и говорят, что это меньшее зло из того что может получиться если вернуть данную возможность обратно - https://github.com/symfony/symfony/issues/8414
fabpot commented:
Well, the decision to let Symfony behaves like this has been well thought out at the time we changed the behavior. We faced a challenge: it was either this bug or many other ones that were bigger in my book.
Of course, anyone can prove me wrong by having a look at the code and see if a patch can fix it. But I don't see how we can "fix" this issue and not re-introduce the other ones (everything is covered with tests so if a patch creates a regression here, we will have failing tests).
Примечательно, что это первое ограничение такого плана с которым удалось столкнуться.

Комментариев нет:

Отправить комментарий