[Asset] Add type-hints to public interfaces
This commit is contained in:
parent
aac5765779
commit
065fdc146c
@ -35,7 +35,7 @@ class Package implements PackageInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getVersion($path)
|
public function getVersion(string $path)
|
||||||
{
|
{
|
||||||
return $this->versionStrategy->getVersion($path);
|
return $this->versionStrategy->getVersion($path);
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ class Package implements PackageInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getUrl($path)
|
public function getUrl(string $path)
|
||||||
{
|
{
|
||||||
if ($this->isAbsoluteUrl($path)) {
|
if ($this->isAbsoluteUrl($path)) {
|
||||||
return $path;
|
return $path;
|
||||||
@ -68,7 +68,7 @@ class Package implements PackageInterface
|
|||||||
return $this->versionStrategy;
|
return $this->versionStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isAbsoluteUrl($url)
|
protected function isAbsoluteUrl(string $url)
|
||||||
{
|
{
|
||||||
return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
|
return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
|
||||||
}
|
}
|
||||||
|
@ -21,18 +21,14 @@ interface PackageInterface
|
|||||||
/**
|
/**
|
||||||
* Returns the asset version for an asset.
|
* Returns the asset version for an asset.
|
||||||
*
|
*
|
||||||
* @param string $path A path
|
|
||||||
*
|
|
||||||
* @return string The version string
|
* @return string The version string
|
||||||
*/
|
*/
|
||||||
public function getVersion($path);
|
public function getVersion(string $path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an absolute or root-relative public path.
|
* Returns an absolute or root-relative public path.
|
||||||
*
|
*
|
||||||
* @param string $path A path
|
|
||||||
*
|
|
||||||
* @return string The public path
|
* @return string The public path
|
||||||
*/
|
*/
|
||||||
public function getUrl($path);
|
public function getUrl(string $path);
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,8 @@ class Packages
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a package.
|
* Adds a package.
|
||||||
*
|
|
||||||
* @param string $name The package name
|
|
||||||
* @param PackageInterface $package The package
|
|
||||||
*/
|
*/
|
||||||
public function addPackage($name, PackageInterface $package)
|
public function addPackage(string $name, PackageInterface $package)
|
||||||
{
|
{
|
||||||
$this->packages[$name] = $package;
|
$this->packages[$name] = $package;
|
||||||
}
|
}
|
||||||
@ -64,7 +61,7 @@ class Packages
|
|||||||
* @throws InvalidArgumentException If there is no package by that name
|
* @throws InvalidArgumentException If there is no package by that name
|
||||||
* @throws LogicException If no default package is defined
|
* @throws LogicException If no default package is defined
|
||||||
*/
|
*/
|
||||||
public function getPackage($name = null)
|
public function getPackage(string $name = null)
|
||||||
{
|
{
|
||||||
if (null === $name) {
|
if (null === $name) {
|
||||||
if (null === $this->defaultPackage) {
|
if (null === $this->defaultPackage) {
|
||||||
@ -89,7 +86,7 @@ class Packages
|
|||||||
*
|
*
|
||||||
* @return string The current version
|
* @return string The current version
|
||||||
*/
|
*/
|
||||||
public function getVersion($path, $packageName = null)
|
public function getVersion(string $path, string $packageName = null)
|
||||||
{
|
{
|
||||||
return $this->getPackage($packageName)->getVersion($path);
|
return $this->getPackage($packageName)->getVersion($path);
|
||||||
}
|
}
|
||||||
@ -104,7 +101,7 @@ class Packages
|
|||||||
*
|
*
|
||||||
* @return string A public path which takes into account the base path and URL path
|
* @return string A public path which takes into account the base path and URL path
|
||||||
*/
|
*/
|
||||||
public function getUrl($path, $packageName = null)
|
public function getUrl(string $path, string $packageName = null)
|
||||||
{
|
{
|
||||||
return $this->getPackage($packageName)->getUrl($path);
|
return $this->getPackage($packageName)->getUrl($path);
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class PathPackage extends Package
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getUrl($path)
|
public function getUrl(string $path)
|
||||||
{
|
{
|
||||||
$versionedPath = parent::getUrl($path);
|
$versionedPath = parent::getUrl($path);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class UrlPackage extends Package
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getUrl($path)
|
public function getUrl(string $path)
|
||||||
{
|
{
|
||||||
if ($this->isAbsoluteUrl($path)) {
|
if ($this->isAbsoluteUrl($path)) {
|
||||||
return $path;
|
return $path;
|
||||||
@ -95,11 +95,9 @@ class UrlPackage extends Package
|
|||||||
/**
|
/**
|
||||||
* Returns the base URL for a path.
|
* Returns the base URL for a path.
|
||||||
*
|
*
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @return string The base URL
|
* @return string The base URL
|
||||||
*/
|
*/
|
||||||
public function getBaseUrl($path)
|
public function getBaseUrl(string $path)
|
||||||
{
|
{
|
||||||
if (1 === \count($this->baseUrls)) {
|
if (1 === \count($this->baseUrls)) {
|
||||||
return $this->baseUrls[0];
|
return $this->baseUrls[0];
|
||||||
@ -114,16 +112,14 @@ class UrlPackage extends Package
|
|||||||
* Override this method to change the default distribution strategy.
|
* Override this method to change the default distribution strategy.
|
||||||
* This method should always return the same base URL index for a given path.
|
* 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
|
* @return int The base URL index for the given path
|
||||||
*/
|
*/
|
||||||
protected function chooseBaseUrl($path)
|
protected function chooseBaseUrl(string $path)
|
||||||
{
|
{
|
||||||
return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls));
|
return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSslUrls($urls)
|
private function getSslUrls(array $urls)
|
||||||
{
|
{
|
||||||
$sslUrls = [];
|
$sslUrls = [];
|
||||||
foreach ($urls as $url) {
|
foreach ($urls as $url) {
|
||||||
|
@ -21,7 +21,7 @@ class EmptyVersionStrategy implements VersionStrategyInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getVersion($path)
|
public function getVersion(string $path)
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ class EmptyVersionStrategy implements VersionStrategyInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function applyVersion($path)
|
public function applyVersion(string $path)
|
||||||
{
|
{
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
@ -40,17 +40,17 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
|
|||||||
* the version is. Instead, this returns the path to the
|
* the version is. Instead, this returns the path to the
|
||||||
* versioned file.
|
* versioned file.
|
||||||
*/
|
*/
|
||||||
public function getVersion($path)
|
public function getVersion(string $path)
|
||||||
{
|
{
|
||||||
return $this->applyVersion($path);
|
return $this->applyVersion($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyVersion($path)
|
public function applyVersion(string $path)
|
||||||
{
|
{
|
||||||
return $this->getManifestPath($path) ?: $path;
|
return $this->getManifestPath($path) ?: $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getManifestPath($path)
|
private function getManifestPath(string $path)
|
||||||
{
|
{
|
||||||
if (null === $this->manifestData) {
|
if (null === $this->manifestData) {
|
||||||
if (!file_exists($this->manifestPath)) {
|
if (!file_exists($this->manifestPath)) {
|
||||||
|
@ -34,7 +34,7 @@ class StaticVersionStrategy implements VersionStrategyInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getVersion($path)
|
public function getVersion(string $path)
|
||||||
{
|
{
|
||||||
return $this->version;
|
return $this->version;
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ class StaticVersionStrategy implements VersionStrategyInterface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function applyVersion($path)
|
public function applyVersion(string $path)
|
||||||
{
|
{
|
||||||
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));
|
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));
|
||||||
|
|
||||||
|
@ -21,18 +21,14 @@ interface VersionStrategyInterface
|
|||||||
/**
|
/**
|
||||||
* Returns the asset version for an asset.
|
* Returns the asset version for an asset.
|
||||||
*
|
*
|
||||||
* @param string $path A path
|
|
||||||
*
|
|
||||||
* @return string The version string
|
* @return string The version string
|
||||||
*/
|
*/
|
||||||
public function getVersion($path);
|
public function getVersion(string $path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies version to the supplied path.
|
* Applies version to the supplied path.
|
||||||
*
|
*
|
||||||
* @param string $path A path
|
|
||||||
*
|
|
||||||
* @return string The versionized path
|
* @return string The versionized path
|
||||||
*/
|
*/
|
||||||
public function applyVersion($path);
|
public function applyVersion(string $path);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user