Tôi đang mở rộng trình xử lý lỗi xác thực và mọi thứ chủ yếu hoạt động tốt, nhưng đối với một vấn đề nhỏ.Ghi đè trình xử lý sự cố xác thực - Symfony2
Đây là services.yml tôi:
http.utils.class:
class: Symfony\Component\Security\Http\HttpUtils
auth.fail:
class: Acme\MyBundle\AuthenticationFailure
arguments:
- @http_kernel
- @http.utils.class
- []
tôi đã thiết lập này sẽ được sử dụng trong security.yml:
failure_handler: auth.fail
Đây là Acme tôi \ MyBundle \ AuthenticationFailure.php:
namespace Acme\MyBundle;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
use Symfony\Component\HttpFoundation\Response;
class AuthenticationFailure extends DefaultAuthenticationFailureHandler
{
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
//do something
}
}
Vấn đề là các tùy chọn tôi đã đặt trong security.yml bị bỏ qua. Tôi biết tham số thứ ba của phương thức _construct của lớp là mảng $ options, và tôi đã không truyền bất cứ thứ gì vào như tham số thứ ba (trong services.yml), vì vậy tôi đoán đây là vấn đề và một giải pháp có thể Tôi chỉ đoán rằng tôi cũng có thể làm điều gì đó như thế này:
arguments:
- @http_kernel
- @http.utils.class
- %security.firewalls.secure_area.form_login%
.... Tôi chưa thử nghiệm vấn đề này là khó mã hóa trong services.yml và nó không phải là lý tưởng như thể tôi đã thay đổi tên của secure_area nó sẽ phá vỡ. Chắc chắn những giá trị này có sẵn theo cách tốt hơn?