vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/EventListener/ReviewCreateListener.php line 34

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\CoreBundle\EventListener;
  12. use Sylius\Component\Core\Model\CustomerInterface;
  13. use Sylius\Component\Customer\Context\CustomerContextInterface;
  14. use Sylius\Component\Review\Model\ReviewInterface;
  15. use Symfony\Component\EventDispatcher\GenericEvent;
  16. use Webmozart\Assert\Assert;
  17. final class ReviewCreateListener
  18. {
  19.     private CustomerContextInterface $customerContext;
  20.     public function __construct(CustomerContextInterface $customerContext)
  21.     {
  22.         $this->customerContext $customerContext;
  23.     }
  24.     /**
  25.      * @throws \InvalidArgumentException
  26.      */
  27.     public function ensureReviewHasAuthor(GenericEvent $event): void
  28.     {
  29.         $subject $event->getSubject();
  30.         Assert::isInstanceOf($subjectReviewInterface::class);
  31.         if (null !== $subject->getAuthor()) {
  32.             return;
  33.         }
  34.         $customer $this->customerContext->getCustomer();
  35.         Assert::isInstanceOf($customerCustomerInterface::class);
  36.         $subject->setAuthor($customer);
  37.     }
  38. }