| Total Complexity | 7 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | abstract class AppSubscriber |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var EntityManagerInterface |
||
| 13 | */ |
||
| 14 | protected $em; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var FlashBagInterface |
||
| 18 | */ |
||
| 19 | protected $flashBag; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return array The event names to listen to |
||
| 23 | */ |
||
| 24 | abstract public static function getSubscribedEvents(); |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param AppEvent $event |
||
| 28 | * Registers the trick into the database |
||
| 29 | */ |
||
| 30 | public function sendToDatabase(AppEvent $event) |
||
| 31 | { |
||
| 32 | $entity = $event->getEntity(); |
||
| 33 | $this->em->persist($entity); |
||
| 34 | $this->em->flush(); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function deleteFromDatabase(AppEvent $event) |
||
| 38 | { |
||
| 39 | $entity = $event->getEntity(); |
||
| 40 | $this->em->remove($entity); |
||
| 41 | $this->em->flush(); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function persist(AppEvent $event) |
||
| 45 | { |
||
| 46 | $entity = $event->getEntity(); |
||
| 47 | $this->em->persist($entity); |
||
| 48 | } |
||
| 49 | |||
| 50 | public function flush() |
||
| 51 | { |
||
| 52 | $this->em->flush(); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Adding te flash message to the session. This enables to have the same syntax as in the controllers |
||
| 57 | * @param string $type |
||
| 58 | * @param string $message |
||
| 59 | */ |
||
| 60 | public function addFlash(string $type, string $message) |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @required |
||
| 67 | * @param EntityManagerInterface $em |
||
| 68 | */ |
||
| 69 | public function setEm(EntityManagerInterface $em): void |
||
| 70 | { |
||
| 71 | $this->em = $em; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @required |
||
| 76 | * @param FlashBagInterface $flashBag |
||
| 77 | */ |
||
| 78 | public function setFlashBag(FlashBagInterface $flashBag): void |
||
| 81 | } |
||
| 82 | } |