A good way to persist and flush with callback func in symfony? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, March 22, 2022

A good way to persist and flush with callback func in symfony?

I'm looking how I can do to automically persist and flush to bdd without having to repeat the same things. Here is my example (i'm novice just like pseudo code)

`    private function updateAddress(User $user, string $address) : void {
        $user->setAddress($address);
    }

    private function deleteTicket(int $idTicket) : void {
        // example
    }

    private function persistAndFlush($entity, $parameter, $funcTo) : void {
        $entity = array_map($funcTo, $parameter);
        $this->em->persist($entity);
        $this->em->flush();
    }

    private function updateAddress(User $user, string $address) : void {
        $user->setAddress($address);
    }

    $this->persistAndFlush($currentUser, 'test', 'updateAddress');
    $this->persistAndFlush($currentUser, 1, 'deleteTicket');
    $this->persistAndFlush($currentUser, ['test', 'test2'], 'foo_bar');`


source https://stackoverflow.com/questions/71562325/a-good-way-to-persist-and-flush-with-callback-func-in-symfony

No comments:

Post a Comment