-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Redirections): Added redirection look-up cache and CRUD events
- Loading branch information
1 parent
6da1c69
commit a78b3d3
Showing
11 changed files
with
161 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
lib/RoadizCoreBundle/src/Event/Redirection/PostCreatedRedirectionEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Event\Redirection; | ||
|
||
final class PostCreatedRedirectionEvent extends RedirectionEvent | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
lib/RoadizCoreBundle/src/Event/Redirection/PostDeletedRedirectionEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Event\Redirection; | ||
|
||
final class PostDeletedRedirectionEvent extends RedirectionEvent | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
lib/RoadizCoreBundle/src/Event/Redirection/PostUpdatedRedirectionEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Event\Redirection; | ||
|
||
final class PostUpdatedRedirectionEvent extends RedirectionEvent | ||
{ | ||
} |
39 changes: 39 additions & 0 deletions
39
lib/RoadizCoreBundle/src/Event/Redirection/RedirectionEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Event\Redirection; | ||
|
||
use RZ\Roadiz\CoreBundle\Entity\Redirection; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
abstract class RedirectionEvent extends Event | ||
{ | ||
protected ?Redirection $redirection; | ||
|
||
/** | ||
* @param Redirection|null $redirection | ||
*/ | ||
public function __construct(?Redirection $redirection) | ||
{ | ||
$this->redirection = $redirection; | ||
} | ||
|
||
/** | ||
* @return Redirection|null | ||
*/ | ||
public function getRedirection(): ?Redirection | ||
{ | ||
return $this->redirection; | ||
} | ||
|
||
/** | ||
* @param Redirection|null $redirection | ||
* @return RedirectionEvent | ||
*/ | ||
public function setRedirection(?Redirection $redirection): RedirectionEvent | ||
{ | ||
$this->redirection = $redirection; | ||
return $this; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
lib/RoadizCoreBundle/src/EventSubscriber/RedirectionCacheSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\EventSubscriber; | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
use RZ\Roadiz\CoreBundle\Event\Redirection\PostCreatedRedirectionEvent; | ||
use RZ\Roadiz\CoreBundle\Event\Redirection\PostDeletedRedirectionEvent; | ||
use RZ\Roadiz\CoreBundle\Event\Redirection\PostUpdatedRedirectionEvent; | ||
use RZ\Roadiz\CoreBundle\Event\Redirection\RedirectionEvent; | ||
use RZ\Roadiz\CoreBundle\Routing\RedirectionPathResolver; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class RedirectionCacheSubscriber implements EventSubscriberInterface | ||
{ | ||
private CacheItemPoolInterface $cacheAdapter; | ||
|
||
public function __construct(CacheItemPoolInterface $cacheAdapter) | ||
{ | ||
$this->cacheAdapter = $cacheAdapter; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
PostCreatedRedirectionEvent::class => 'clearCache', | ||
PostDeletedRedirectionEvent::class => 'clearCache', | ||
PostUpdatedRedirectionEvent::class => 'clearCache', | ||
]; | ||
} | ||
|
||
public function clearCache(RedirectionEvent $event): void | ||
{ | ||
$this->cacheAdapter->deleteItem(RedirectionPathResolver::CACHE_KEY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters