我有事件POST_WRITE的订阅者。通常,在这种方法中,我可以获得保存的对象。我该怎么办?
final class ProductCreateSubscriber implements EventSubscriberInterface
{
private $entityManager;
private $hostRepository;
private $jwtEncoder;
private $tokenExtractor;
public function __construct(EntityManagerInterface $entityManager, HostRepository $hostRepository, JWTEncoderInterface $jwtEncoder, TokenExtractorInterface $tokenExtractor)
{
$this->jwtEncoder = $jwtEncoder;
$this->entityManager = $entityManager;
$this->hostRepository = $hostRepository;
$this->tokenExtractor = $tokenExtractor;
}
public static function getSubscribedEvents()
{
return [
KernelEvents::VIEW => ['createProductWatcher', EventPriorities::POST_WRITE],
];
}
public function createProductWatcher(GetResponseForControllerResultEvent $event)
{
---------- HERE I NEED SAVED OBJECT -----------
$token = $this->tokenExtractor->extract($event->getRequest());
if ($token) {
$payload = $this->jwtEncoder->decode($token);
$productWatcher = new ProductWatcher();
}
}
}
我可以通过这种方法获取对象吗?还是需要使用EventListeners?