0

認証成功ハンドラーを使用して、ログインが成功するたびにセッションにいくつかの値を入力していました。データベース操作を実行したかったので、構成ファイルから @doctrine.dbal.default_connection を渡しました。これは、success_handler 関数をオーバーライドする構成ファイルです。

services:     
    security.authentication.success_handler:
    class:  XYZ\UserBundle\Handler\AuthenticationSuccessHandler
    arguments:  ["@security.http_utils", {}, @doctrine.dbal.default_connection]
    tags:
        - { name: 'monolog.logger', channel: 'security' }

AuthenticationSuccessHandler.php では、私のコードは次のようになります...

namespace Sourcen\UserBundle\Handler;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Http\HttpUtils;
use Doctrine\DBAL\Connection;


class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler {

private $connection;

public function __construct( HttpUtils $httpUtils, array $options, Connection $dbalConnection ) {
    $this->connection = $dbalConnection;
    parent::__construct( $httpUtils, $options );
}

public function onAuthenticationSuccess( Request $request, TokenInterface $token ) {
    $response = parent::onAuthenticationSuccess( $request, $token );
    // DB CODE GOES  
    return $response;
}
}

これは、コントローラーの URL を直接実行すると機能します。しかし、「www.xyz.com/web」のようなアプリのホームURLを実行すると、次のエラーがスローされます...

 Catchable fatal error: Argument 3 passed to XYZ\UserBundle\Handler\AuthenticationSuccessHandler::__construct() must be an instance of Doctrine\DBAL\Connection, none given, called in /opt/lampp/xyz/app/cache/prod/appProdProjectContainer.php on line 1006 and defined in /opt/lampp/xyz/src/Sourcen/UserBundle/Handler/AuthenticationSuccessHandler.php on line 18

それを解決する方法はありますか?

4

1 に答える 1