This repository was archived by the owner on Jun 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 13.4: Defining a Complex Lifecycle Callback
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |