Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Add 13.4: Defining a Complex Lifecycle Callback
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 13, 2022
1 parent 5c5f26c commit 18a9c0f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/EntityListener/ConferenceEntityListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\EntityListener;

use App\Entity\Conference;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Symfony\Component\String\Slugger\SluggerInterface;

class ConferenceEntityListener
{
private $slugger;

public function __construct(SluggerInterface $slugger)
{
$this->slugger = $slugger;
}

public function prePersist(Conference $conference, LifecycleEventArgs $event)
{
$conference->computeSlug($this->slugger);
}

public function preUpdate(Conference $conference, LifecycleEventArgs $event)
{
$conference->computeSlug($this->slugger);
}
}

0 comments on commit 18a9c0f

Please sign in to comment.