vendor/easycorp/easyadmin-bundle/src/Asset/AssetPackage.php line 30

  1. <?php
  2. namespace EasyCorp\Bundle\EasyAdminBundle\Asset;
  3. use Symfony\Component\Asset\Context\RequestStackContext;
  4. use Symfony\Component\Asset\PackageInterface;
  5. use Symfony\Component\Asset\PathPackage;
  6. use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. /**
  9.  * This defines a Symfony Asset named package that groups all the assets provided
  10.  * by EasyAdmin. This is needed because EasyAdmin uses asset versioning, so the
  11.  * full absolute URLs of assets isn't known (the URL contain changing hashes).
  12.  *
  13.  * In practice this uses the same strategy (and even the same "manifest.json" file)
  14.  * used by Webpack Encore. We do this because we want to keep EasyAdmin dependencies as
  15.  * lean as possible, so we don't want to require Webpack Encore to use EasyAdmin.
  16.  */
  17. final class AssetPackage implements PackageInterface
  18. {
  19.     public const PACKAGE_NAME 'easyadmin.assets.package';
  20.     private PackageInterface $package;
  21.     public function __construct(RequestStack $requestStack)
  22.     {
  23.         $this->package = new PathPackage(
  24.             '/bundles/easyadmin',
  25.             new JsonManifestVersionStrategy(__DIR__.'/../Resources/public/manifest.json'),
  26.             new RequestStackContext($requestStack)
  27.         );
  28.     }
  29.     public function getUrl(string $assetPath): string
  30.     {
  31.         return $this->package->getUrl($assetPath);
  32.     }
  33.     public function getVersion(string $assetPath): string
  34.     {
  35.         return $this->package->getVersion($assetPath);
  36.     }
  37. }