Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ManifestBuilder events, #173 #183

Open
wants to merge 1 commit into
base: 1.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Event/PostManifestBuildEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php


namespace SpomkyLabs\PwaBundle\Event;

use SpomkyLabs\PwaBundle\Dto\Manifest;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Dispatched during the ManifestBuilder::create method, after the configuration is denormalized
*/
class PostManifestBuildEvent extends Event
{
public function __construct(private Manifest $manifest)
{
}

public function setManifest(Manifest $manifest): void
{
$this->manifest = $manifest;
}

public function getManifest(): Manifest
{
return $this->manifest;
}
}

26 changes: 26 additions & 0 deletions src/Event/PreManifestBuildEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


namespace SpomkyLabs\PwaBundle\Event;

use Symfony\Contracts\EventDispatcher\Event;

/**
* Dispatched during the ManifestBuilder::create method, before the configuration is denormalized
*/
class PreManifestBuildEvent extends Event
{
public function __construct(private array $config)
{
}

public function setConfig(array $config): void
{
$this->config = $config;
}

public function getConfig(): array
{
return $this->config;
}
}
6 changes: 6 additions & 0 deletions src/Service/ManifestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace SpomkyLabs\PwaBundle\Service;

use SpomkyLabs\PwaBundle\Dto\Manifest;
use SpomkyLabs\PwaBundle\Event\PostManifestBuildEvent;
use SpomkyLabs\PwaBundle\Event\PreManifestBuildEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use function assert;

Expand All @@ -17,15 +20,18 @@ final class ManifestBuilder
*/
public function __construct(
private readonly DenormalizerInterface $denormalizer,
private readonly null|EventDispatcherInterface $dispatcher,
private readonly array $config,
) {
}

public function create(): Manifest
{
if ($this->manifest === null) {
$this->dispatcher->dispatch(new PreManifestBuildEvent($this->config));
$result = $this->denormalizer->denormalize($this->config, Manifest::class);
assert($result instanceof Manifest);
$this->dispatcher->dispatch(new PostManifestBuildEvent($this->manifest));
$this->manifest = $result;
}

Expand Down