-
-
Save dsuurlant/a8af7e6922679f45b818ec4ddad36286 to your computer and use it in GitHub Desktop.
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
<?php | |
declare(strict_types=1); | |
namespace App\EventSubscriber; | |
use ApiPlatform\Core\EventListener\EventPriorities; | |
use App\Entity\Article; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | |
use Symfony\Component\HttpKernel\KernelEvents; | |
/** | |
* @author Danielle Suurlant <danielle.suurlant@gmail.com> | |
*/ | |
class ArticleSubscriber extends AuthenticatedSubscriber implements EventSubscriberInterface | |
{ | |
public static function getSubscribedEvents() | |
{ | |
return [ | |
KernelEvents::REQUEST => ['setUserForArticle', EventPriorities::POST_DESERIALIZE], | |
]; | |
} | |
public function setUserForArticle(GetResponseEvent $event) | |
{ | |
$this->setUser($event, Article::class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment