-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manifest file is now compiled with other assets
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpomkyLabs\PwaBundle\Subscriber; | ||
|
||
use SpomkyLabs\PwaBundle\Dto\Manifest; | ||
use Symfony\Component\AssetMapper\Event\PreAssetsCompileEvent; | ||
use Symfony\Component\AssetMapper\Path\PublicAssetsFilesystemInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
use const JSON_PRETTY_PRINT; | ||
use const JSON_THROW_ON_ERROR; | ||
use const JSON_UNESCAPED_SLASHES; | ||
use const JSON_UNESCAPED_UNICODE; | ||
|
||
#[AsEventListener(PreAssetsCompileEvent::class)] | ||
final readonly class AssetsCompileEventListener | ||
{ | ||
private string $manifestPublicUrl; | ||
|
||
public function __construct( | ||
private SerializerInterface $serializer, | ||
private Manifest $manifest, | ||
#[Autowire('%spomky_labs_pwa.manifest_public_url%')] | ||
string $manifestPublicUrl, | ||
#[Autowire('@asset_mapper.local_public_assets_filesystem')] | ||
private PublicAssetsFilesystemInterface $assetsFilesystem, | ||
) { | ||
$this->manifestPublicUrl = '/' . trim($manifestPublicUrl, '/'); | ||
} | ||
|
||
public function __invoke(PreAssetsCompileEvent $event): void | ||
{ | ||
$data = $this->serializer->serialize($this->manifest, 'json', [ | ||
AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true, | ||
AbstractObjectNormalizer::SKIP_NULL_VALUES => true, | ||
'json_encode_options' => JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, | ||
]); | ||
$this->assetsFilesystem->write($this->manifestPublicUrl, $data); | ||
} | ||
} |