vendor/ezsystems/ezplatform-kernel/eZ/Publish/Core/Event/URLService.php line 19

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\URLService as URLServiceInterface;
  9. use eZ\Publish\API\Repository\Values\URL\URL;
  10. use eZ\Publish\API\Repository\Values\URL\URLUpdateStruct;
  11. use eZ\Publish\API\Repository\Events\URL\BeforeUpdateUrlEvent;
  12. use eZ\Publish\API\Repository\Events\URL\UpdateUrlEvent;
  13. use eZ\Publish\SPI\Repository\Decorator\URLServiceDecorator;
  14. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  15. class URLService extends URLServiceDecorator
  16. {
  17.     /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
  18.     protected $eventDispatcher;
  19.     public function __construct(
  20.         URLServiceInterface $innerService,
  21.         EventDispatcherInterface $eventDispatcher
  22.     ) {
  23.         parent::__construct($innerService);
  24.         $this->eventDispatcher $eventDispatcher;
  25.     }
  26.     public function updateUrl(
  27.         URL $url,
  28.         URLUpdateStruct $struct
  29.     ): URL {
  30.         $eventData = [
  31.             $url,
  32.             $struct,
  33.         ];
  34.         $beforeEvent = new BeforeUpdateUrlEvent(...$eventData);
  35.         $this->eventDispatcher->dispatch($beforeEvent);
  36.         if ($beforeEvent->isPropagationStopped()) {
  37.             return $beforeEvent->getUpdatedUrl();
  38.         }
  39.         $updatedUrl $beforeEvent->hasUpdatedUrl()
  40.             ? $beforeEvent->getUpdatedUrl()
  41.             : $this->innerService->updateUrl($url$struct);
  42.         $this->eventDispatcher->dispatch(
  43.             new UpdateUrlEvent($updatedUrl, ...$eventData)
  44.         );
  45.         return $updatedUrl;
  46.     }
  47. }