src/Subscriber/ArticleSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber;
  3. use App\Entity\Article;
  4. use App\Service\ArticleService;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityDeletedEvent;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  7. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ArticleSubscriber implements EventSubscriberInterface
  10. {
  11. private $articleService;
  12. public function __construct(ArticleService $articlesService)
  13. {
  14. $this->articleService = $articlesService;
  15. }
  16. public static function getSubscribedEvents()
  17. {
  18. return array(
  19. AfterEntityPersistedEvent::class => array('updateSitemap'),
  20. AfterEntityUpdatedEvent::class => array('updateSitemap'),
  21. AfterEntityDeletedEvent::class => array('updateSitemap'),
  22. );
  23. }
  24. function updateSitemap($event) {
  25. $result = $event->getEntityInstance();
  26. if (!($result instanceof Article)) {
  27. return;
  28. }
  29. $this->articleService->generateSitemap();
  30. }
  31. }