-
-
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.
Better Service Worker
- Loading branch information
Showing
18 changed files
with
257 additions
and
162 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpomkyLabs\PwaBundle\Dto; | ||
|
||
final class Asset | ||
{ | ||
public function __construct( | ||
public string $src | ||
) { | ||
} | ||
|
||
public static function create(string $data): self | ||
{ | ||
return new self($data); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
final class Icon | ||
{ | ||
public string $src; | ||
public Asset $src; | ||
|
||
/** | ||
* @var array<int> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SpomkyLabs\PwaBundle\Normalizer; | ||
|
||
use SpomkyLabs\PwaBundle\Dto\Asset; | ||
use Symfony\Component\AssetMapper\AssetMapperInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
use function assert; | ||
use function is_string; | ||
|
||
final readonly class AssetNormalizer implements NormalizerInterface, DenormalizerInterface | ||
{ | ||
public function __construct( | ||
private AssetMapperInterface $assetMapper, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array{src: string, sizes?: string, form_factor?: string, label?: string, platform?: string, format?: string} | ||
*/ | ||
public function normalize(mixed $object, string $format = null, array $context = []): string | ||
{ | ||
assert($object instanceof Asset); | ||
$url = null; | ||
dump($object); | ||
if (! str_starts_with($object->src, '/')) { | ||
$asset = $this->assetMapper->getAsset($object->src); | ||
$url = $asset?->publicPath; | ||
} | ||
if ($url === null) { | ||
$url = $object->src; | ||
} | ||
|
||
return $url; | ||
} | ||
|
||
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed | ||
{ | ||
assert(is_string($data)); | ||
|
||
return Asset::create($data); | ||
} | ||
|
||
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool | ||
{ | ||
return $data instanceof Asset; | ||
} | ||
|
||
public function supportsDenormalization( | ||
mixed $data, | ||
string $type, | ||
string $format = null, | ||
array $context = [] | ||
): bool { | ||
return $type === Asset::class; | ||
} | ||
|
||
/** | ||
* @return array<class-string, bool> | ||
*/ | ||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [ | ||
Asset::class => true, | ||
]; | ||
} | ||
} |
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
Oops, something went wrong.