在尝试将服务注入我的侦听器时,我似乎错过了一个我无法识别的步骤。
这是我的 services.xmlL
<services>
<!-- Activity logger -->
<service id="myapp.activity_logger" class="My\AppBundle\Api\ActivityLogger">
</service>
<!-- Activity events -->
<service id="myapp.activity.logged_in" class="My\AppBundle\Listener\ActivityListener">
<argument type="service" id="myapp.activity_logger" />
<tag name="kernel.event_listener" event="security.interactive_login" method="onLoggedIn" priority="254" />
</service>
...
侦听器类本身:
namespace My\AppBundle\Listener;
use My\AppBundle\Api\ActivityLogger;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
class ActivityListener
{
protected $activityLogger;
public function __construct(ActivityLogger $al)
{
$this->activityLogger = $al;
}
public function onLoggedIn(InteractiveLoginEvent $event)
{
// Log activity data
}
触发事件时收到的错误:
ErrorException: Catchable Fatal Error: Argument 1 passed to
My\AppBundle\Listener\ActivityListener::__construct() must be an instance of
My\AppBundle\Api\ActivityLogger, none given, called in
/var/www/app/cache/dev/appDevDebugProjectContainer.php on line 2739 and defined in
/var/www/src/My/AppBundle/Listener/ActivityListener.php line 18
我似乎无法确定我在注入服务时做错了什么,因为我相信我正在遵循手册中的正确步骤。