Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
-3
View File
@@ -1,3 +0,0 @@
vendor/
composer.lock
phpunit.xml
+5
View File
@@ -1,6 +1,11 @@
CHANGELOG
=========
4.2.0
-----
* added different protocols to be allowed as asset base_urls
3.4.0
-----
+1 -5
View File
@@ -24,11 +24,7 @@ class RequestStackContext implements ContextInterface
private $basePath;
private $secure;
/**
* @param string $basePath
* @param bool $secure
*/
public function __construct(RequestStack $requestStack, $basePath = '', $secure = false)
public function __construct(RequestStack $requestStack, string $basePath = '', bool $secure = false)
{
$this->requestStack = $requestStack;
$this->basePath = $basePath;
+1 -1
View File
@@ -16,6 +16,6 @@ namespace Symfony\Component\Asset\Exception;
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface ExceptionInterface
interface ExceptionInterface extends \Throwable
{
}
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2004-2020 Fabien Potencier
Copyright (c) 2004-2022 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+5 -2
View File
@@ -29,7 +29,7 @@ class Package implements PackageInterface
public function __construct(VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
{
$this->versionStrategy = $versionStrategy;
$this->context = $context ?: new NullContext();
$this->context = $context ?? new NullContext();
}
/**
@@ -68,8 +68,11 @@ class Package implements PackageInterface
return $this->versionStrategy;
}
/**
* @return bool
*/
protected function isAbsoluteUrl($url)
{
return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
return str_contains($url, '://') || '//' === substr($url, 0, 2);
}
}
+2 -4
View File
@@ -26,8 +26,7 @@ class Packages
private $packages = [];
/**
* @param PackageInterface $defaultPackage The default package
* @param PackageInterface[] $packages Additional packages indexed by name
* @param PackageInterface[] $packages Additional packages indexed by name
*/
public function __construct(PackageInterface $defaultPackage = null, array $packages = [])
{
@@ -46,8 +45,7 @@ class Packages
/**
* Adds a package.
*
* @param string $name The package name
* @param PackageInterface $package The package
* @param string $name The package name
*/
public function addPackage($name, PackageInterface $package)
{
+3 -9
View File
@@ -29,11 +29,9 @@ class PathPackage extends Package
private $basePath;
/**
* @param string $basePath The base path to be prepended to relative paths
* @param VersionStrategyInterface $versionStrategy The version strategy
* @param ContextInterface|null $context The context
* @param string $basePath The base path to be prepended to relative paths
*/
public function __construct($basePath, VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
public function __construct(string $basePath, VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
{
parent::__construct($versionStrategy, $context);
@@ -53,11 +51,7 @@ class PathPackage extends Package
*/
public function getUrl($path)
{
if ($this->isAbsoluteUrl($path)) {
return $path;
}
$versionedPath = $this->getVersionStrategy()->applyVersion($path);
$versionedPath = parent::getUrl($path);
// if absolute or begins with /, we're done
if ($this->isAbsoluteUrl($versionedPath) || ($versionedPath && '/' === $versionedPath[0])) {
+5 -5
View File
@@ -7,8 +7,8 @@ CSS stylesheets, JavaScript files and image files.
Resources
---------
* [Documentation](https://symfony.com/doc/current/components/asset/introduction.html)
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)
* [Documentation](https://symfony.com/doc/current/components/asset/introduction.html)
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)
-32
View File
@@ -1,32 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests\Context;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\NullContext;
class NullContextTest extends TestCase
{
public function testGetBasePath()
{
$nullContext = new NullContext();
$this->assertEmpty($nullContext->getBasePath());
}
public function testIsSecure()
{
$nullContext = new NullContext();
$this->assertFalse($nullContext->isSecure());
}
}
@@ -1,73 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests\Context;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\RequestStackContext;
class RequestStackContextTest extends TestCase
{
public function testGetBasePathEmpty()
{
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStackContext = new RequestStackContext($requestStack);
$this->assertEmpty($requestStackContext->getBasePath());
}
public function testGetBasePathSet()
{
$testBasePath = 'test-path';
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
$request->method('getBasePath')
->willReturn($testBasePath);
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStack->method('getMasterRequest')
->willReturn($request);
$requestStackContext = new RequestStackContext($requestStack);
$this->assertSame($testBasePath, $requestStackContext->getBasePath());
}
public function testIsSecureFalse()
{
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStackContext = new RequestStackContext($requestStack);
$this->assertFalse($requestStackContext->isSecure());
}
public function testIsSecureTrue()
{
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
$request->method('isSecure')
->willReturn(true);
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStack->method('getMasterRequest')
->willReturn($request);
$requestStackContext = new RequestStackContext($requestStack);
$this->assertTrue($requestStackContext->isSecure());
}
public function testDefaultContext()
{
$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStackContext = new RequestStackContext($requestStack, 'default-path', true);
$this->assertSame('default-path', $requestStackContext->getBasePath());
$this->assertTrue($requestStackContext->isSecure());
}
}
-55
View File
@@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
class PackageTest extends TestCase
{
/**
* @dataProvider getConfigs
*/
public function testGetUrl($version, $format, $path, $expected)
{
$package = new Package($version ? new StaticVersionStrategy($version, $format) : new EmptyVersionStrategy());
$this->assertSame($expected, $package->getUrl($path));
}
public function getConfigs()
{
return [
['v1', '', 'http://example.com/foo', 'http://example.com/foo'],
['v1', '', 'https://example.com/foo', 'https://example.com/foo'],
['v1', '', '//example.com/foo', '//example.com/foo'],
['v1', '', '/foo', '/foo?v1'],
['v1', '', 'foo', 'foo?v1'],
[null, '', '/foo', '/foo'],
[null, '', 'foo', 'foo'],
['v1', 'version-%2$s/%1$s', '/foo', '/version-v1/foo'],
['v1', 'version-%2$s/%1$s', 'foo', 'version-v1/foo'],
['v1', 'version-%2$s/%1$s', 'foo/', 'version-v1/foo/'],
['v1', 'version-%2$s/%1$s', '/foo/', '/version-v1/foo/'],
];
}
public function testGetVersion()
{
$package = new Package(new StaticVersionStrategy('v1'));
$this->assertSame('v1', $package->getVersion('/foo'));
}
}
-71
View File
@@ -1,71 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Package;
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->getMockBuilder('Symfony\Component\Asset\PackageInterface')->getMock());
$packages->addPackage('a', $a = $this->getMockBuilder('Symfony\Component\Asset\PackageInterface')->getMock());
$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()
{
$packages = new Packages(
new Package(new StaticVersionStrategy('default')),
['a' => new Package(new StaticVersionStrategy('a'))]
);
$this->assertSame('default', $packages->getVersion('/foo'));
$this->assertSame('a', $packages->getVersion('/foo', 'a'));
}
public function testGetUrl()
{
$packages = new Packages(
new Package(new StaticVersionStrategy('default')),
['a' => new Package(new StaticVersionStrategy('a'))]
);
$this->assertSame('/foo?default', $packages->getUrl('/foo'));
$this->assertSame('/foo?a', $packages->getUrl('/foo', 'a'));
}
public function testNoDefaultPackage()
{
$this->expectException('Symfony\Component\Asset\Exception\LogicException');
$packages = new Packages();
$packages->getPackage();
}
public function testUndefinedPackage()
{
$this->expectException('Symfony\Component\Asset\Exception\InvalidArgumentException');
$packages = new Packages();
$packages->getPackage('a');
}
}
-96
View File
@@ -1,96 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
class PathPackageTest extends TestCase
{
/**
* @dataProvider getConfigs
*/
public function testGetUrl($basePath, $format, $path, $expected)
{
$package = new PathPackage($basePath, new StaticVersionStrategy('v1', $format));
$this->assertSame($expected, $package->getUrl($path));
}
public function getConfigs()
{
return [
['/foo', '', 'http://example.com/foo', 'http://example.com/foo'],
['/foo', '', 'https://example.com/foo', 'https://example.com/foo'],
['/foo', '', '//example.com/foo', '//example.com/foo'],
['', '', '/foo', '/foo?v1'],
['/foo', '', '/bar', '/bar?v1'],
['/foo', '', 'bar', '/foo/bar?v1'],
['foo', '', 'bar', '/foo/bar?v1'],
['foo/', '', 'bar', '/foo/bar?v1'],
['/foo/', '', 'bar', '/foo/bar?v1'],
['/foo', 'version-%2$s/%1$s', '/bar', '/version-v1/bar'],
['/foo', 'version-%2$s/%1$s', 'bar', '/foo/version-v1/bar'],
['/foo', 'version-%2$s/%1$s', 'bar/', '/foo/version-v1/bar/'],
['/foo', 'version-%2$s/%1$s', '/bar/', '/version-v1/bar/'],
];
}
/**
* @dataProvider getContextConfigs
*/
public function testGetUrlWithContext($basePathRequest, $basePath, $format, $path, $expected)
{
$package = new PathPackage($basePath, new StaticVersionStrategy('v1', $format), $this->getContext($basePathRequest));
$this->assertSame($expected, $package->getUrl($path));
}
public function getContextConfigs()
{
return [
['', '/foo', '', '/baz', '/baz?v1'],
['', '/foo', '', 'baz', '/foo/baz?v1'],
['', 'foo', '', 'baz', '/foo/baz?v1'],
['', 'foo/', '', 'baz', '/foo/baz?v1'],
['', '/foo/', '', 'baz', '/foo/baz?v1'],
['/bar', '/foo', '', '/baz', '/baz?v1'],
['/bar', '/foo', '', 'baz', '/bar/foo/baz?v1'],
['/bar', 'foo', '', 'baz', '/bar/foo/baz?v1'],
['/bar', 'foo/', '', 'baz', '/bar/foo/baz?v1'],
['/bar', '/foo/', '', 'baz', '/bar/foo/baz?v1'],
];
}
public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface')->getMock();
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
$package = new PathPackage('/subdirectory', $versionStrategy, $this->getContext('/bar'));
$this->assertSame('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
}
private function getContext($basePath)
{
$context = $this->getMockBuilder('Symfony\Component\Asset\Context\ContextInterface')->getMock();
$context->expects($this->any())->method('getBasePath')->willReturn($basePath);
return $context;
}
}
-110
View File
@@ -1,110 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\UrlPackage;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
class UrlPackageTest extends TestCase
{
/**
* @dataProvider getConfigs
*/
public function testGetUrl($baseUrls, $format, $path, $expected)
{
$package = new UrlPackage($baseUrls, new StaticVersionStrategy('v1', $format));
$this->assertSame($expected, $package->getUrl($path));
}
public function getConfigs()
{
return [
['http://example.net', '', 'http://example.com/foo', 'http://example.com/foo'],
['http://example.net', '', 'https://example.com/foo', 'https://example.com/foo'],
['http://example.net', '', '//example.com/foo', '//example.com/foo'],
['http://example.com', '', '/foo', 'http://example.com/foo?v1'],
['http://example.com', '', 'foo', 'http://example.com/foo?v1'],
['http://example.com/', '', 'foo', 'http://example.com/foo?v1'],
['http://example.com/foo', '', 'foo', 'http://example.com/foo/foo?v1'],
['http://example.com/foo/', '', 'foo', 'http://example.com/foo/foo?v1'],
[['http://example.com'], '', '/foo', 'http://example.com/foo?v1'],
[['http://example.com', 'http://example.net'], '', '/foo', 'http://example.com/foo?v1'],
[['http://example.com', 'http://example.net'], '', '/fooa', 'http://example.net/fooa?v1'],
['http://example.com', 'version-%2$s/%1$s', '/foo', 'http://example.com/version-v1/foo'],
['http://example.com', 'version-%2$s/%1$s', 'foo', 'http://example.com/version-v1/foo'],
['http://example.com', 'version-%2$s/%1$s', 'foo/', 'http://example.com/version-v1/foo/'],
['http://example.com', 'version-%2$s/%1$s', '/foo/', 'http://example.com/version-v1/foo/'],
];
}
/**
* @dataProvider getContextConfigs
*/
public function testGetUrlWithContext($secure, $baseUrls, $format, $path, $expected)
{
$package = new UrlPackage($baseUrls, new StaticVersionStrategy('v1', $format), $this->getContext($secure));
$this->assertSame($expected, $package->getUrl($path));
}
public function getContextConfigs()
{
return [
[false, 'http://example.com', '', 'foo', 'http://example.com/foo?v1'],
[false, ['http://example.com'], '', 'foo', 'http://example.com/foo?v1'],
[false, ['http://example.com', 'https://example.com'], '', 'foo', 'http://example.com/foo?v1'],
[false, ['http://example.com', 'https://example.com'], '', 'fooa', 'https://example.com/fooa?v1'],
[false, ['http://example.com/bar'], '', 'foo', 'http://example.com/bar/foo?v1'],
[false, ['http://example.com/bar/'], '', 'foo', 'http://example.com/bar/foo?v1'],
[false, ['//example.com/bar/'], '', 'foo', '//example.com/bar/foo?v1'],
[true, ['http://example.com'], '', 'foo', 'http://example.com/foo?v1'],
[true, ['http://example.com', 'https://example.com'], '', 'foo', 'https://example.com/foo?v1'],
];
}
public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface')->getMock();
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
$package = new UrlPackage('https://example.com', $versionStrategy);
$this->assertSame('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
}
public function testNoBaseUrls()
{
$this->expectException('Symfony\Component\Asset\Exception\LogicException');
new UrlPackage([], new EmptyVersionStrategy());
}
public function testWrongBaseUrl()
{
$this->expectException('Symfony\Component\Asset\Exception\InvalidArgumentException');
new UrlPackage(['not-a-url'], new EmptyVersionStrategy());
}
private function getContext($secure)
{
$context = $this->getMockBuilder('Symfony\Component\Asset\Context\ContextInterface')->getMock();
$context->expects($this->any())->method('isSecure')->willReturn($secure);
return $context;
}
}
@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests\VersionStrategy;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
class EmptyVersionStrategyTest extends TestCase
{
public function testGetVersion()
{
$emptyVersionStrategy = new EmptyVersionStrategy();
$path = 'test-path';
$this->assertEmpty($emptyVersionStrategy->getVersion($path));
}
public function testApplyVersion()
{
$emptyVersionStrategy = new EmptyVersionStrategy();
$path = 'test-path';
$this->assertSame($path, $emptyVersionStrategy->applyVersion($path));
}
}
@@ -1,59 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests\VersionStrategy;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy;
class JsonManifestVersionStrategyTest extends TestCase
{
public function testGetVersion()
{
$strategy = $this->createStrategy('manifest-valid.json');
$this->assertSame('main.123abc.js', $strategy->getVersion('main.js'));
}
public function testApplyVersion()
{
$strategy = $this->createStrategy('manifest-valid.json');
$this->assertSame('css/styles.555def.css', $strategy->getVersion('css/styles.css'));
}
public function testApplyVersionWhenKeyDoesNotExistInManifest()
{
$strategy = $this->createStrategy('manifest-valid.json');
$this->assertSame('css/other.css', $strategy->getVersion('css/other.css'));
}
public function testMissingManifestFileThrowsException()
{
$this->expectException('RuntimeException');
$strategy = $this->createStrategy('non-existent-file.json');
$strategy->getVersion('main.js');
}
public function testManifestFileWithBadJSONThrowsException()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('Error parsing JSON');
$strategy = $this->createStrategy('manifest-invalid.json');
$strategy->getVersion('main.js');
}
private function createStrategy($manifestFilename)
{
return new JsonManifestVersionStrategy(__DIR__.'/../fixtures/'.$manifestFilename);
}
}
@@ -1,44 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Asset\Tests\VersionStrategy;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
class StaticVersionStrategyTest extends TestCase
{
public function testGetVersion()
{
$version = 'v1';
$path = 'test-path';
$staticVersionStrategy = new StaticVersionStrategy($version);
$this->assertSame($version, $staticVersionStrategy->getVersion($path));
}
/**
* @dataProvider getConfigs
*/
public function testApplyVersion($path, $version, $format)
{
$staticVersionStrategy = new StaticVersionStrategy($version, $format);
$formatted = sprintf($format ?: '%s?%s', $path, $version);
$this->assertSame($formatted, $staticVersionStrategy->applyVersion($path));
}
public function getConfigs()
{
return [
['test-path', 'v1', null],
['test-path', 'v2', '%s?test%s'],
];
}
}
@@ -1,4 +0,0 @@
{
"main.js": main.123abc.js",
"css/styles.css": "css/styles.555def.css"
}
@@ -1,4 +0,0 @@
{
"main.js": "main.123abc.js",
"css/styles.css": "css/styles.555def.css"
}
+3 -5
View File
@@ -39,9 +39,7 @@ class UrlPackage extends Package
private $sslPackage;
/**
* @param string|string[] $baseUrls Base asset URLs
* @param VersionStrategyInterface $versionStrategy The version strategy
* @param ContextInterface|null $context Context
* @param string|string[] $baseUrls Base asset URLs
*/
public function __construct($baseUrls, VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
{
@@ -123,13 +121,13 @@ class UrlPackage extends Package
return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls));
}
private function getSslUrls($urls)
private function getSslUrls(array $urls)
{
$sslUrls = [];
foreach ($urls as $url) {
if ('https://' === substr($url, 0, 8) || '//' === substr($url, 0, 2)) {
$sslUrls[] = $url;
} elseif ('http://' !== substr($url, 0, 7)) {
} elseif (null === parse_url($url, \PHP_URL_SCHEME)) {
throw new InvalidArgumentException(sprintf('"%s" is not a valid URL.', $url));
}
}
@@ -30,7 +30,7 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
/**
* @param string $manifestPath Absolute path to the manifest file
*/
public function __construct($manifestPath)
public function __construct(string $manifestPath)
{
$this->manifestPath = $manifestPath;
}
@@ -50,11 +50,11 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
return $this->getManifestPath($path) ?: $path;
}
private function getManifestPath($path)
private function getManifestPath(string $path): ?string
{
if (null === $this->manifestData) {
if (!file_exists($this->manifestPath)) {
throw new \RuntimeException(sprintf('Asset manifest file "%s" does not exist.', $this->manifestPath));
throw new \RuntimeException(sprintf('Asset manifest file "%s" does not exist. Did you forget to build the assets with npm or yarn?', $this->manifestPath));
}
$this->manifestData = json_decode(file_get_contents($this->manifestPath), true);
@@ -63,6 +63,6 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
}
}
return isset($this->manifestData[$path]) ? $this->manifestData[$path] : null;
return $this->manifestData[$path] ?? null;
}
}
@@ -25,7 +25,7 @@ class StaticVersionStrategy implements VersionStrategyInterface
* @param string $version Version number
* @param string $format Url format
*/
public function __construct($version, $format = null)
public function __construct(string $version, string $format = null)
{
$this->version = $version;
$this->format = $format ?: '%s?%s';
@@ -46,7 +46,7 @@ class StaticVersionStrategy implements VersionStrategyInterface
{
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));
if ($path && '/' == $path[0]) {
if ($path && '/' === $path[0]) {
return '/'.$versionized;
}
+5 -4
View File
@@ -1,7 +1,7 @@
{
"name": "symfony/asset",
"type": "library",
"description": "Symfony Asset Component",
"description": "Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files",
"keywords": [],
"homepage": "https://symfony.com",
"license": "MIT",
@@ -16,14 +16,15 @@
}
],
"require": {
"php": "^5.5.9|>=7.0.8"
"php": ">=7.1.3",
"symfony/polyfill-php80": "^1.16"
},
"suggest": {
"symfony/http-foundation": ""
},
"require-dev": {
"symfony/http-foundation": "~2.8|~3.0|~4.0",
"symfony/http-kernel": "~2.8|~3.0|~4.0"
"symfony/http-foundation": "^3.4|^4.0|^5.0",
"symfony/http-kernel": "^3.4|^4.0|^5.0"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Asset\\": "" },
-30
View File
@@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Symfony Asset Component Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>