vendor/ibexa/http-cache/src/lib/EventSubscriber/CachePurge/SectionEventsSubscriber.php line 42

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 Ibexa\HttpCache\EventSubscriber\CachePurge;
  8. use Ibexa\Contracts\Core\Repository\Events\Section\AssignSectionEvent;
  9. use Ibexa\Contracts\Core\Repository\Events\Section\AssignSectionToSubtreeEvent;
  10. use Ibexa\Contracts\Core\Repository\Events\Section\DeleteSectionEvent;
  11. use Ibexa\Contracts\Core\Repository\Events\Section\UpdateSectionEvent;
  12. final class SectionEventsSubscriber extends AbstractSubscriber
  13. {
  14.     private const SECTION_TAG_PREFIX 's';
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             AssignSectionEvent::class => 'onAssignSection',
  19.             DeleteSectionEvent::class => 'onDeleteSection',
  20.             UpdateSectionEvent::class => 'onUpdateSection',
  21.             AssignSectionToSubtreeEvent::class => 'onAssignSectionToSubtree',
  22.         ];
  23.     }
  24.     public function onAssignSection(AssignSectionEvent $event): void
  25.     {
  26.         $contentId $event->getContentInfo()->id;
  27.         $tags array_merge(
  28.             $this->getContentTags($contentId),
  29.             $this->getContentLocationsTags($contentId)
  30.         );
  31.         $this->purgeClient->purge($tags);
  32.     }
  33.     public function onDeleteSection(DeleteSectionEvent $event): void
  34.     {
  35.         $sectionId $event->getSection()->id;
  36.         $this->purgeClient->purge([
  37.            self::SECTION_TAG_PREFIX $sectionId,
  38.         ]);
  39.     }
  40.     public function onUpdateSection(UpdateSectionEvent $event): void
  41.     {
  42.         $sectionId $event->getSection()->id;
  43.         $this->purgeClient->purge([
  44.             self::SECTION_TAG_PREFIX $sectionId,
  45.         ]);
  46.     }
  47.     public function onAssignSectionToSubtree(AssignSectionToSubtreeEvent $event): void
  48.     {
  49.         $location $event->getLocation();
  50.         $tags array_merge(
  51.             $this->getContentTags($location->contentId),
  52.             $this->getLocationTags($location->id),
  53.             $this->getParentLocationTags($location->parentLocationId),
  54.             [
  55.                 'path-' $location->id,
  56.             ]
  57.         );
  58.         $this->purgeClient->purge($tags);
  59.     }
  60. }
  61. class_alias(SectionEventsSubscriber::class, 'EzSystems\PlatformHttpCacheBundle\EventSubscriber\CachePurge\SectionEventsSubscriber');