vendor/ezsystems/ezplatform-kernel/eZ/Publish/Core/Event/BookmarkService.php line 20

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace eZ\Publish\Core\Event;
  8. use eZ\Publish\API\Repository\BookmarkService as BookmarkServiceInterface;
  9. use eZ\Publish\API\Repository\Values\Content\Location;
  10. use eZ\Publish\API\Repository\Events\Bookmark\BeforeCreateBookmarkEvent;
  11. use eZ\Publish\API\Repository\Events\Bookmark\BeforeDeleteBookmarkEvent;
  12. use eZ\Publish\API\Repository\Events\Bookmark\CreateBookmarkEvent;
  13. use eZ\Publish\API\Repository\Events\Bookmark\DeleteBookmarkEvent;
  14. use eZ\Publish\SPI\Repository\Decorator\BookmarkServiceDecorator;
  15. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  16. class BookmarkService extends BookmarkServiceDecorator
  17. {
  18.     /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
  19.     protected $eventDispatcher;
  20.     public function __construct(
  21.         BookmarkServiceInterface $innerService,
  22.         EventDispatcherInterface $eventDispatcher
  23.     ) {
  24.         parent::__construct($innerService);
  25.         $this->eventDispatcher $eventDispatcher;
  26.     }
  27.     public function createBookmark(Location $location): void
  28.     {
  29.         $eventData = [$location];
  30.         $beforeEvent = new BeforeCreateBookmarkEvent(...$eventData);
  31.         $this->eventDispatcher->dispatch($beforeEvent);
  32.         if ($beforeEvent->isPropagationStopped()) {
  33.             return;
  34.         }
  35.         $this->innerService->createBookmark($location);
  36.         $this->eventDispatcher->dispatch(new CreateBookmarkEvent(...$eventData));
  37.     }
  38.     public function deleteBookmark(Location $location): void
  39.     {
  40.         $eventData = [$location];
  41.         $beforeEvent = new BeforeDeleteBookmarkEvent(...$eventData);
  42.         $this->eventDispatcher->dispatch($beforeEvent);
  43.         if ($beforeEvent->isPropagationStopped()) {
  44.             return;
  45.         }
  46.         $this->innerService->deleteBookmark($location);
  47.         $this->eventDispatcher->dispatch(new DeleteBookmarkEvent(...$eventData));
  48.     }
  49. }