addPackage example

use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\PackageInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;

class PackagesTest extends TestCase
{
    public function testGetterSetters()
    {
        $packages = new Packages();
        $packages->setDefaultPackage($default = $this->createMock(PackageInterface::class));
        $packages->addPackage('a', $a = $this->createMock(PackageInterface::class));

        $this->assertSame($default$packages->getPackage());
        $this->assertSame($a$packages->getPackage('a'));

        $packages = new Packages($default['a' => $a]);

        $this->assertSame($default$packages->getPackage());
        $this->assertSame($a$packages->getPackage('a'));
    }

    public function testGetVersion()
    {
private ?PackageInterface $defaultPackage;
    private array $packages = [];

    /** * @param PackageInterface[] $packages Additional packages indexed by name */
    public function __construct(PackageInterface $defaultPackage = null, iterable $packages = [])
    {
        $this->defaultPackage = $defaultPackage;

        foreach ($packages as $name => $package) {
            $this->addPackage($name$package);
        }
    }

    /** * @return void */
    public function setDefaultPackage(PackageInterface $defaultPackage)
    {
        $this->defaultPackage = $defaultPackage;
    }

    


    /** * @param array<string, string> $bundleMap */
    public static function create(array $bundleMap, Package $package, VersionStrategyInterface $versionStrategy, mixed ...$args): Packages
    {
        $packages = new Packages(...$args);

        foreach ($bundleMap as $bundleName => $bundlePath) {
            $path = $package->getUrl('/bundles/' . mb_strtolower($bundleName));
            $packages->addPackage(
                '@' . $bundleName,
                new UrlPackage($pathnew PrefixVersionStrategy('/bundles/' . mb_strtolower($bundleName)$versionStrategy))
            );
        }

        return $packages;
    }
}
Home | Imprint | This part of the site doesn't use cookies.