Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

3
vendor/symfony/asset/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
vendor/
composer.lock
phpunit.xml

18
vendor/symfony/asset/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,18 @@
CHANGELOG
=========
3.4.0
-----
* added optional arguments `$basePath` and `$secure` in `RequestStackContext::__construct()`
to provide a default request context in case the stack is empty
3.3.0
-----
* Added `JsonManifestVersionStrategy` as a way to read final,
versioned paths from a JSON manifest file.
2.7.0
-----
* added the component

View File

@@ -0,0 +1,34 @@
<?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\Context;
/**
* Holds information about the current request.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface ContextInterface
{
/**
* Gets the base path.
*
* @return string The base path
*/
public function getBasePath();
/**
* Checks whether the request is secure or not.
*
* @return bool true if the request is secure, false otherwise
*/
public function isSecure();
}

View File

@@ -0,0 +1,36 @@
<?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\Context;
/**
* A context that does nothing.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class NullContext implements ContextInterface
{
/**
* {@inheritdoc}
*/
public function getBasePath()
{
return '';
}
/**
* {@inheritdoc}
*/
public function isSecure()
{
return false;
}
}

View File

@@ -0,0 +1,61 @@
<?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\Context;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Uses a RequestStack to populate the context.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RequestStackContext implements ContextInterface
{
private $requestStack;
private $basePath;
private $secure;
/**
* @param string $basePath
* @param bool $secure
*/
public function __construct(RequestStack $requestStack, $basePath = '', $secure = false)
{
$this->requestStack = $requestStack;
$this->basePath = $basePath;
$this->secure = $secure;
}
/**
* {@inheritdoc}
*/
public function getBasePath()
{
if (!$request = $this->requestStack->getMasterRequest()) {
return $this->basePath;
}
return $request->getBasePath();
}
/**
* {@inheritdoc}
*/
public function isSecure()
{
if (!$request = $this->requestStack->getMasterRequest()) {
return $this->secure;
}
return $request->isSecure();
}
}

View File

@@ -0,0 +1,21 @@
<?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\Exception;
/**
* Base ExceptionInterface for the Asset component.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface ExceptionInterface
{
}

View File

@@ -0,0 +1,21 @@
<?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\Exception;
/**
* Base InvalidArgumentException for the Asset component.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}

View File

@@ -0,0 +1,21 @@
<?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\Exception;
/**
* Base LogicException for the Asset component.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class LogicException extends \LogicException implements ExceptionInterface
{
}

19
vendor/symfony/asset/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2004-2020 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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

75
vendor/symfony/asset/Package.php vendored Normal file
View File

@@ -0,0 +1,75 @@
<?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;
use Symfony\Component\Asset\Context\ContextInterface;
use Symfony\Component\Asset\Context\NullContext;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
/**
* Basic package that adds a version to asset URLs.
*
* @author Kris Wallsmith <kris@symfony.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
class Package implements PackageInterface
{
private $versionStrategy;
private $context;
public function __construct(VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
{
$this->versionStrategy = $versionStrategy;
$this->context = $context ?: new NullContext();
}
/**
* {@inheritdoc}
*/
public function getVersion($path)
{
return $this->versionStrategy->getVersion($path);
}
/**
* {@inheritdoc}
*/
public function getUrl($path)
{
if ($this->isAbsoluteUrl($path)) {
return $path;
}
return $this->versionStrategy->applyVersion($path);
}
/**
* @return ContextInterface
*/
protected function getContext()
{
return $this->context;
}
/**
* @return VersionStrategyInterface
*/
protected function getVersionStrategy()
{
return $this->versionStrategy;
}
protected function isAbsoluteUrl($url)
{
return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
}
}

View File

@@ -0,0 +1,38 @@
<?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;
/**
* Asset package interface.
*
* @author Kris Wallsmith <kris@symfony.com>
*/
interface PackageInterface
{
/**
* Returns the asset version for an asset.
*
* @param string $path A path
*
* @return string The version string
*/
public function getVersion($path);
/**
* Returns an absolute or root-relative public path.
*
* @param string $path A path
*
* @return string The public path
*/
public function getUrl($path);
}

111
vendor/symfony/asset/Packages.php vendored Normal file
View File

@@ -0,0 +1,111 @@
<?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;
use Symfony\Component\Asset\Exception\InvalidArgumentException;
use Symfony\Component\Asset\Exception\LogicException;
/**
* Helps manage asset URLs.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Kris Wallsmith <kris@symfony.com>
*/
class Packages
{
private $defaultPackage;
private $packages = [];
/**
* @param PackageInterface $defaultPackage The default package
* @param PackageInterface[] $packages Additional packages indexed by name
*/
public function __construct(PackageInterface $defaultPackage = null, array $packages = [])
{
$this->defaultPackage = $defaultPackage;
foreach ($packages as $name => $package) {
$this->addPackage($name, $package);
}
}
public function setDefaultPackage(PackageInterface $defaultPackage)
{
$this->defaultPackage = $defaultPackage;
}
/**
* Adds a package.
*
* @param string $name The package name
* @param PackageInterface $package The package
*/
public function addPackage($name, PackageInterface $package)
{
$this->packages[$name] = $package;
}
/**
* Returns an asset package.
*
* @param string $name The name of the package or null for the default package
*
* @return PackageInterface An asset package
*
* @throws InvalidArgumentException If there is no package by that name
* @throws LogicException If no default package is defined
*/
public function getPackage($name = null)
{
if (null === $name) {
if (null === $this->defaultPackage) {
throw new LogicException('There is no default asset package, configure one first.');
}
return $this->defaultPackage;
}
if (!isset($this->packages[$name])) {
throw new InvalidArgumentException(sprintf('There is no "%s" asset package.', $name));
}
return $this->packages[$name];
}
/**
* Gets the version to add to public URL.
*
* @param string $path A public path
* @param string $packageName A package name
*
* @return string The current version
*/
public function getVersion($path, $packageName = null)
{
return $this->getPackage($packageName)->getVersion($path);
}
/**
* Returns the public path.
*
* Absolute paths (i.e. http://...) are returned unmodified.
*
* @param string $path A public path
* @param string $packageName The name of the asset package to use
*
* @return string A public path which takes into account the base path and URL path
*/
public function getUrl($path, $packageName = null)
{
return $this->getPackage($packageName)->getUrl($path);
}
}

79
vendor/symfony/asset/PathPackage.php vendored Normal file
View File

@@ -0,0 +1,79 @@
<?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;
use Symfony\Component\Asset\Context\ContextInterface;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
/**
* Package that adds a base path to asset URLs in addition to a version.
*
* In addition to the provided base path, this package also automatically
* prepends the current request base path if a Context is available to
* allow a website to be hosted easily under any given path under the Web
* Server root directory.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
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
*/
public function __construct($basePath, VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
{
parent::__construct($versionStrategy, $context);
if (!$basePath) {
$this->basePath = '/';
} else {
if ('/' != $basePath[0]) {
$basePath = '/'.$basePath;
}
$this->basePath = rtrim($basePath, '/').'/';
}
}
/**
* {@inheritdoc}
*/
public function getUrl($path)
{
if ($this->isAbsoluteUrl($path)) {
return $path;
}
$versionedPath = $this->getVersionStrategy()->applyVersion($path);
// if absolute or begins with /, we're done
if ($this->isAbsoluteUrl($versionedPath) || ($versionedPath && '/' === $versionedPath[0])) {
return $versionedPath;
}
return $this->getBasePath().ltrim($versionedPath, '/');
}
/**
* Returns the base path.
*
* @return string The base path
*/
public function getBasePath()
{
return $this->getContext()->getBasePath().$this->basePath;
}
}

14
vendor/symfony/asset/README.md vendored Normal file
View File

@@ -0,0 +1,14 @@
Asset Component
===============
The Asset component manages URL generation and versioning of web assets such as
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)

View File

@@ -0,0 +1,32 @@
<?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());
}
}

View File

@@ -0,0 +1,73 @@
<?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());
}
}

View File

@@ -0,0 +1,55 @@
<?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'));
}
}

View File

@@ -0,0 +1,71 @@
<?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');
}
}

View File

@@ -0,0 +1,96 @@
<?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;
}
}

View File

@@ -0,0 +1,110 @@
<?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;
}
}

View File

@@ -0,0 +1,34 @@
<?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));
}
}

View File

@@ -0,0 +1,59 @@
<?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);
}
}

View File

@@ -0,0 +1,44 @@
<?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'],
];
}
}

View File

@@ -0,0 +1,4 @@
{
"main.js": main.123abc.js",
"css/styles.css": "css/styles.555def.css"
}

View File

@@ -0,0 +1,4 @@
{
"main.js": "main.123abc.js",
"css/styles.css": "css/styles.555def.css"
}

139
vendor/symfony/asset/UrlPackage.php vendored Normal file
View File

@@ -0,0 +1,139 @@
<?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;
use Symfony\Component\Asset\Context\ContextInterface;
use Symfony\Component\Asset\Exception\InvalidArgumentException;
use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
/**
* Package that adds a base URL to asset URLs in addition to a version.
*
* The package allows to use more than one base URLs in which case
* it randomly chooses one for each asset; it also guarantees that
* any given path will always use the same base URL to be nice with
* HTTP caching mechanisms.
*
* When the request context is available, this package can choose the
* best base URL to use based on the current request scheme:
*
* * For HTTP request, it chooses between all base URLs;
* * For HTTPs requests, it chooses between HTTPs base URLs and relative protocol URLs
* or falls back to any base URL if no secure ones are available.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class UrlPackage extends Package
{
private $baseUrls = [];
private $sslPackage;
/**
* @param string|string[] $baseUrls Base asset URLs
* @param VersionStrategyInterface $versionStrategy The version strategy
* @param ContextInterface|null $context Context
*/
public function __construct($baseUrls, VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
{
parent::__construct($versionStrategy, $context);
if (!\is_array($baseUrls)) {
$baseUrls = (array) $baseUrls;
}
if (!$baseUrls) {
throw new LogicException('You must provide at least one base URL.');
}
foreach ($baseUrls as $baseUrl) {
$this->baseUrls[] = rtrim($baseUrl, '/');
}
$sslUrls = $this->getSslUrls($baseUrls);
if ($sslUrls && $baseUrls !== $sslUrls) {
$this->sslPackage = new self($sslUrls, $versionStrategy);
}
}
/**
* {@inheritdoc}
*/
public function getUrl($path)
{
if ($this->isAbsoluteUrl($path)) {
return $path;
}
if (null !== $this->sslPackage && $this->getContext()->isSecure()) {
return $this->sslPackage->getUrl($path);
}
$url = $this->getVersionStrategy()->applyVersion($path);
if ($this->isAbsoluteUrl($url)) {
return $url;
}
if ($url && '/' != $url[0]) {
$url = '/'.$url;
}
return $this->getBaseUrl($path).$url;
}
/**
* Returns the base URL for a path.
*
* @param string $path
*
* @return string The base URL
*/
public function getBaseUrl($path)
{
if (1 === \count($this->baseUrls)) {
return $this->baseUrls[0];
}
return $this->baseUrls[$this->chooseBaseUrl($path)];
}
/**
* Determines which base URL to use for the given path.
*
* Override this method to change the default distribution strategy.
* This method should always return the same base URL index for a given path.
*
* @param string $path
*
* @return int The base URL index for the given path
*/
protected function chooseBaseUrl($path)
{
return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls));
}
private function getSslUrls($urls)
{
$sslUrls = [];
foreach ($urls as $url) {
if ('https://' === substr($url, 0, 8) || '//' === substr($url, 0, 2)) {
$sslUrls[] = $url;
} elseif ('http://' !== substr($url, 0, 7)) {
throw new InvalidArgumentException(sprintf('"%s" is not a valid URL.', $url));
}
}
return $sslUrls;
}
}

View File

@@ -0,0 +1,36 @@
<?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\VersionStrategy;
/**
* Disable version for all assets.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class EmptyVersionStrategy implements VersionStrategyInterface
{
/**
* {@inheritdoc}
*/
public function getVersion($path)
{
return '';
}
/**
* {@inheritdoc}
*/
public function applyVersion($path)
{
return $path;
}
}

View File

@@ -0,0 +1,68 @@
<?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\VersionStrategy;
/**
* Reads the versioned path of an asset from a JSON manifest file.
*
* For example, the manifest file might look like this:
* {
* "main.js": "main.abc123.js",
* "css/styles.css": "css/styles.555abc.css"
* }
*
* You could then ask for the version of "main.js" or "css/styles.css".
*/
class JsonManifestVersionStrategy implements VersionStrategyInterface
{
private $manifestPath;
private $manifestData;
/**
* @param string $manifestPath Absolute path to the manifest file
*/
public function __construct($manifestPath)
{
$this->manifestPath = $manifestPath;
}
/**
* With a manifest, we don't really know or care about what
* the version is. Instead, this returns the path to the
* versioned file.
*/
public function getVersion($path)
{
return $this->applyVersion($path);
}
public function applyVersion($path)
{
return $this->getManifestPath($path) ?: $path;
}
private function getManifestPath($path)
{
if (null === $this->manifestData) {
if (!file_exists($this->manifestPath)) {
throw new \RuntimeException(sprintf('Asset manifest file "%s" does not exist.', $this->manifestPath));
}
$this->manifestData = json_decode(file_get_contents($this->manifestPath), true);
if (0 < json_last_error()) {
throw new \RuntimeException(sprintf('Error parsing JSON from asset manifest file "%s": ', $this->manifestPath).json_last_error_msg());
}
}
return isset($this->manifestData[$path]) ? $this->manifestData[$path] : null;
}
}

View File

@@ -0,0 +1,55 @@
<?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\VersionStrategy;
/**
* Returns the same version for all assets.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class StaticVersionStrategy implements VersionStrategyInterface
{
private $version;
private $format;
/**
* @param string $version Version number
* @param string $format Url format
*/
public function __construct($version, $format = null)
{
$this->version = $version;
$this->format = $format ?: '%s?%s';
}
/**
* {@inheritdoc}
*/
public function getVersion($path)
{
return $this->version;
}
/**
* {@inheritdoc}
*/
public function applyVersion($path)
{
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));
if ($path && '/' == $path[0]) {
return '/'.$versionized;
}
return $versionized;
}
}

View File

@@ -0,0 +1,38 @@
<?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\VersionStrategy;
/**
* Asset version strategy interface.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface VersionStrategyInterface
{
/**
* Returns the asset version for an asset.
*
* @param string $path A path
*
* @return string The version string
*/
public function getVersion($path);
/**
* Applies version to the supplied path.
*
* @param string $path A path
*
* @return string The versionized path
*/
public function applyVersion($path);
}

35
vendor/symfony/asset/composer.json vendored Normal file
View File

@@ -0,0 +1,35 @@
{
"name": "symfony/asset",
"type": "library",
"description": "Symfony Asset Component",
"keywords": [],
"homepage": "https://symfony.com",
"license": "MIT",
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"require": {
"php": "^5.5.9|>=7.0.8"
},
"suggest": {
"symfony/http-foundation": ""
},
"require-dev": {
"symfony/http-foundation": "~2.8|~3.0|~4.0",
"symfony/http-kernel": "~2.8|~3.0|~4.0"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Asset\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev"
}

30
vendor/symfony/asset/phpunit.xml.dist vendored Normal file
View File

@@ -0,0 +1,30 @@
<?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>