PHP code example of wazum / slug-cascade-contracts
1. Go to this page and download the library: Download wazum/slug-cascade-contracts library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wazum / slug-cascade-contracts example snippets
namespace Wazum\SlugCascadeContracts;
use Psr\EventDispatcher\StoppableEventInterface;
interface SlugCascadeEvent extends StoppableEventInterface
{
public function getPageId(): int;
public function getOldParentSlug(): string;
public function getNewParentSlug(): string;
public function getCorrelationId(): string;
public function deferCascade(): void;
}
namespace Acme\Producer\Event;
use Wazum\SlugCascadeContracts\SlugCascadeEvent;
final class SlugChanged implements SlugCascadeEvent
{
private bool $cascadeDeferred = false;
public function __construct(
public readonly int $pageId,
public readonly string $oldParentSlug,
public readonly string $newParentSlug,
public readonly string $correlationId,
) {}
public function getPageId(): int { return $this->pageId; }
public function getOldParentSlug(): string { return $this->oldParentSlug; }
public function getNewParentSlug(): string { return $this->newParentSlug; }
public function getCorrelationId(): string { return $this->correlationId; }
public function deferCascade(): void { $this->cascadeDeferred = true; }
public function isPropagationStopped(): bool { return $this->cascadeDeferred; }
}
$event = new SlugChanged($pageId, $oldSlug, $newSlug, $correlationId);
$this->eventDispatcher->dispatch($event);
if ($event->isPropagationStopped()) {
return;
}
$this->rebuildChildSlugsSynchronously(...);
namespace Acme\Consumer\EventListener;
use Wazum\SlugCascadeContracts\SlugCascadeEvent;
final class HandleCascade
{
public function __invoke(SlugCascadeEvent $event): void
{
// … handle the cascade …
$event->deferCascade();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.