Skip to content

Commit

Permalink
Simplified public_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 6, 2024
1 parent eb98b01 commit 4d83fa2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
16 changes: 0 additions & 16 deletions src/Resources/config/definition/asset_public_prefix.php

This file was deleted.

7 changes: 5 additions & 2 deletions src/Service/ServiceWorkerCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SpomkyLabs\PwaBundle\Dto\ServiceWorker;
use SpomkyLabs\PwaBundle\Dto\Workbox;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Serializer\Encoder\JsonEncode;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -25,21 +26,23 @@
private array $jsonOptions;

private string $manifestPublicUrl;
private string $assetPublicPrefix;

public function __construct(
private SerializerInterface $serializer,
#[Autowire('%spomky_labs_pwa.manifest.public_url%')]
string $manifestPublicUrl,
#[Autowire('%spomky_labs_pwa.sw.enabled%')]
private bool $serviceWorkerEnabled,
#[Autowire('%spomky_labs_pwa.asset_public_prefix%')]
private string $assetPublicPrefix,
#[Autowire(service: 'asset_mapper.public_assets_path_resolver')]
PublicAssetsPathResolverInterface $publicAssetsPathResolver,
private Manifest $manifest,
private ServiceWorker $serviceWorker,
private AssetMapperInterface $assetMapper,
#[Autowire('%kernel.debug%')]
bool $debug,
) {
$this->assetPublicPrefix = rtrim($publicAssetsPathResolver->resolvePublicPath(''), '/');
$this->manifestPublicUrl = '/' . trim($manifestPublicUrl, '/');
$options = [
JsonEncode::OPTIONS => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR,
Expand Down
26 changes: 0 additions & 26 deletions src/SpomkyLabsPwaBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
if ($serviceWorkerConfig['enabled'] === true && $manifestConfig['enabled'] === true) {
$manifestConfig['serviceworker'] = $serviceWorkerConfig;
}
$builder->setParameter(
'spomky_labs_pwa.asset_public_prefix',
'/' . trim((string) $config['asset_public_prefix'], '/')
);

/*** Manifest ***/
$builder->setParameter('spomky_labs_pwa.manifest.enabled', $config['manifest']['enabled']);
Expand All @@ -58,7 +54,6 @@ public function loadExtension(array $config, ContainerConfigurator $container, C

public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
{
$this->setAssetPublicPrefix($builder);
$this->setAssetMapperPath($builder);
}

Expand All @@ -72,25 +67,4 @@ private function setAssetMapperPath(ContainerBuilder $builder): void
],
]);
}

private function setAssetPublicPrefix(ContainerBuilder $builder): void
{
$bundles = $builder->getParameter('kernel.bundles');
if (isset($bundles['FrameworkBundle'])) {
foreach ($builder->getExtensions() as $name => $extension) {
if ($name !== 'framework') {
continue;
}
$config = $builder->getExtensionConfig($name);
foreach ($config as $c) {
if (! isset($c['asset_mapper']['public_prefix'])) {
continue;
}
$builder->prependExtensionConfig('pwa', [
'asset_public_prefix' => $c['asset_mapper']['public_prefix'],
]);
}
}
}
}
}

0 comments on commit 4d83fa2

Please sign in to comment.