在尝试向听众注入服务时,我似乎错过了一个我无法识别的步骤。
这是我的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
我似乎无法隔离我在注入服务方面做错的事情,因为我相信我已按照手册中的正确步骤进行操作。
答案 0 :(得分:0)
看起来你刚刚没有重置缓存。我想流程如下:
ActivityListener
类