-
-
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.
- Loading branch information
Showing
13 changed files
with
225 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?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,66 @@ | ||
<?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 | ||
Check failure on line 24 in src/Normalizer/AssetNormalizer.php GitHub Actions / PHP 8.2 Test on ubuntu-latest
Check failure on line 24 in src/Normalizer/AssetNormalizer.php GitHub Actions / PHP 8.2 Test on ubuntu-latest
|
||
{ | ||
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 | ||
Check failure on line 47 in src/Normalizer/AssetNormalizer.php GitHub Actions / PHP 8.2 Test on ubuntu-latest
|
||
{ | ||
return $data instanceof Asset; | ||
} | ||
|
||
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool | ||
Check failure on line 52 in src/Normalizer/AssetNormalizer.php GitHub Actions / PHP 8.2 Test on ubuntu-latest
|
||
{ | ||
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
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
// *** Workbox Bundle rules *** | ||
//WORKBOX_IMPORT_PLACEHOLDER | ||
//STANDARD_RULES_PLACEHOLDER | ||
//PRECACHING_PLACEHOLDER | ||
//WARM_CACHE_URLS_PLACEHOLDER | ||
//OFFLINE_FALLBACK_PLACEHOLDER | ||
//WIDGETS_PLACEHOLDER |
Oops, something went wrong.