Skip to content

Instantly share code, notes, and snippets.

@dsuurlant
Created January 1, 2018 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsuurlant/a8af7e6922679f45b818ec4ddad36286 to your computer and use it in GitHub Desktop.
Save dsuurlant/a8af7e6922679f45b818ec4ddad36286 to your computer and use it in GitHub Desktop.
<?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