| Total Complexity | 5 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | abstract class AbstractAppSubscriber |
||
| 10 | { |
||
| 11 | use AddFlashTrait; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var EntityManagerInterface |
||
| 15 | */ |
||
| 16 | protected $em; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @return array The event names to listen to |
||
| 20 | */ |
||
| 21 | abstract public static function getSubscribedEvents(); |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param AbstractAppEvent $event |
||
| 25 | * Registers the trick into the database |
||
| 26 | */ |
||
| 27 | public function sendToDatabase(AbstractAppEvent $event) |
||
| 28 | { |
||
| 29 | $entity = $event->getEntity(); |
||
| 30 | $this->em->persist($entity); |
||
| 31 | $this->em->flush(); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function deleteFromDatabase(AbstractAppEvent $event) |
||
| 35 | { |
||
| 36 | $entity = $event->getEntity(); |
||
| 37 | $this->em->remove($entity); |
||
| 38 | $this->em->flush(); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function persist(AbstractAppEvent $event) |
||
| 42 | { |
||
| 43 | $entity = $event->getEntity(); |
||
| 44 | $this->em->persist($entity); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function flush() |
||
| 48 | { |
||
| 49 | $this->em->flush(); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @required |
||
| 54 | * @param EntityManagerInterface $em |
||
| 55 | */ |
||
| 56 | public function setEm(EntityManagerInterface $em): void |
||
| 59 | } |
||
| 60 | } |