Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PHP advanced version. #874

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
],
"require": {
"php": ">=5.3.1",
"symfony/process": "~2.1|~3.0"
"php": ">=7.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is dropping support for old versions, not adding support for new versions of PHP (which were already allowed by the range

"symfony/process": "~4.0"
},
"conflict": {
"twig/twig": "<1.27"
Expand All @@ -29,7 +29,7 @@
"phpunit/phpunit": "~4.8 || ^5.6",
"psr/log": "~1.0",
"ptachoire/cssembed": "~1.0",
"symfony/phpunit-bridge": "~2.7|~3.0",
"symfony/phpunit-bridge": "~4.0",
"twig/twig": "~1.23|~2.0",
"yfix/packager": "dev-master"
},
Expand Down
9 changes: 4 additions & 5 deletions src/Assetic/Asset/AssetCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,10 @@ private static function getCacheKey(AssetInterface $asset, FilterInterface $addi
$cacheKey .= $asset->getLastModified();

foreach ($asset->getFilters() as $filter) {
if ($filter instanceof HashableInterface) {
$cacheKey .= $filter->hash();
} else {
$cacheKey .= serialize($filter);
}

$cacheKey .= $filter instanceof HashableInterface
? $filter->hash()
: serialize($filter);
}

if ($values = $asset->getValues()) {
Expand Down
18 changes: 9 additions & 9 deletions src/Assetic/Asset/AssetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class AssetCollection implements \IteratorAggregate, AssetCollectionInterface
* @param string $sourceRoot The root directory
* @param array $vars
*/
public function __construct($assets = array(), $filters = array(), $sourceRoot = null, array $vars = array())
public function __construct($assets = [], $filters = [], $sourceRoot = null, array $vars = [])
{
$this->assets = array();
$this->assets = [];
foreach ($assets as $asset) {
$this->add($asset);
}
Expand All @@ -51,7 +51,7 @@ public function __construct($assets = array(), $filters = array(), $sourceRoot =
$this->sourceRoot = $sourceRoot;
$this->clones = new \SplObjectStorage();
$this->vars = $vars;
$this->values = array();
$this->values = [];
}

public function __clone()
Expand All @@ -73,8 +73,8 @@ public function add(AssetInterface $asset)
public function removeLeaf(AssetInterface $needle, $graceful = false)
{
foreach ($this->assets as $i => $asset) {
$clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
if (in_array($needle, array($asset, $clone), true)) {
$clone = $this->clones[$asset] ?? null;
if (in_array($needle, [$asset, $clone], true)) {
unset($this->clones[$asset], $this->assets[$i]);

return true;
Expand All @@ -95,8 +95,8 @@ public function removeLeaf(AssetInterface $needle, $graceful = false)
public function replaceLeaf(AssetInterface $needle, AssetInterface $replacement, $graceful = false)
{
foreach ($this->assets as $i => $asset) {
$clone = isset($this->clones[$asset]) ? $this->clones[$asset] : null;
if (in_array($needle, array($asset, $clone), true)) {
$clone = $this->clones[$asset] ?? null;
if (in_array($needle, [$asset, $clone], true)) {
unset($this->clones[$asset]);
$this->assets[$i] = $replacement;

Expand Down Expand Up @@ -134,7 +134,7 @@ public function clearFilters()
public function load(FilterInterface $additionalFilter = null)
{
// loop through leaves and load each asset
$parts = array();
$parts = [];
foreach ($this as $asset) {
$asset->load($additionalFilter);
$parts[] = $asset->getContent();
Expand All @@ -146,7 +146,7 @@ public function load(FilterInterface $additionalFilter = null)
public function dump(FilterInterface $additionalFilter = null)
{
// loop through leaves and dump each asset
$parts = array();
$parts = [];
foreach ($this as $asset) {
$parts[] = $asset->dump($additionalFilter);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Assetic/Asset/AssetReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AssetReference implements AssetInterface
{
private $am;
private $name;
private $filters = array();
private $filters = [];
private $clone = false;
private $asset;

Expand Down Expand Up @@ -56,22 +56,22 @@ public function getFilters()

public function clearFilters()
{
$this->filters = array();
$this->filters = [];
$this->callAsset(__FUNCTION__);
}

public function load(FilterInterface $additionalFilter = null)
{
$this->flushFilters();

return $this->callAsset(__FUNCTION__, array($additionalFilter));
return $this->callAsset(__FUNCTION__, [$additionalFilter]);
}

public function dump(FilterInterface $additionalFilter = null)
{
$this->flushFilters();

return $this->callAsset(__FUNCTION__, array($additionalFilter));
return $this->callAsset(__FUNCTION__, [$additionalFilter]);
}

public function getContent()
Expand All @@ -81,7 +81,7 @@ public function getContent()

public function setContent($content)
{
$this->callAsset(__FUNCTION__, array($content));
$this->callAsset(__FUNCTION__, [$content]);
}

public function getSourceRoot()
Expand All @@ -106,7 +106,7 @@ public function getTargetPath()

public function setTargetPath($targetPath)
{
$this->callAsset(__FUNCTION__, array($targetPath));
$this->callAsset(__FUNCTION__, [$targetPath]);
}

public function getLastModified()
Expand All @@ -126,16 +126,16 @@ public function getValues()

public function setValues(array $values)
{
$this->callAsset(__FUNCTION__, array($values));
$this->callAsset(__FUNCTION__, [$values]);
}

// private

private function callAsset($method, $arguments = array())
private function callAsset($method, $arguments = [])
{
$asset = $this->resolve();

return call_user_func_array(array($asset, $method), $arguments);
return call_user_func_array([$asset, $method], $arguments);
}

private function flushFilters()
Expand Down
4 changes: 2 additions & 2 deletions src/Assetic/Asset/BaseAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class BaseAsset implements AssetInterface
* @param string $sourcePath The asset path
* @param array $vars
*/
public function __construct($filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array())
public function __construct($filters = [], $sourceRoot = null, $sourcePath = null, array $vars = [])
{
$this->filters = new FilterCollection($filters);
$this->sourceRoot = $sourceRoot;
Expand All @@ -51,7 +51,7 @@ public function __construct($filters = array(), $sourceRoot = null, $sourcePath
$this->sourceDir = dirname("$sourceRoot/$sourcePath");
}
$this->vars = $vars;
$this->values = array();
$this->values = [];
$this->loaded = false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Assetic/Asset/FileAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FileAsset extends BaseAsset
*
* @throws \InvalidArgumentException If the supplied root doesn't match the source when guessing the path
*/
public function __construct($source, $filters = array(), $sourceRoot = null, $sourcePath = null, array $vars = array())
public function __construct($source, $filters = [], $sourceRoot = null, $sourcePath = null, array $vars = [])
{
if (null === $sourceRoot) {
$sourceRoot = dirname($source);
Expand Down
6 changes: 3 additions & 3 deletions src/Assetic/Asset/GlobAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class GlobAsset extends AssetCollection
* @param string $root The root directory
* @param array $vars
*/
public function __construct($globs, $filters = array(), $root = null, array $vars = array())
public function __construct($globs, $filters = [], $root = null, array $vars = [])
{
$this->globs = (array) $globs;
$this->initialized = false;

parent::__construct(array(), $filters, $root, $vars);
parent::__construct([], $filters, $root, $vars);
}

public function all()
Expand Down Expand Up @@ -102,7 +102,7 @@ private function initialize()
if (false !== $paths = glob($glob)) {
foreach ($paths as $path) {
if (is_file($path)) {
$asset = new FileAsset($path, array(), $this->getSourceRoot(), null, $this->getVars());
$asset = new FileAsset($path, [], $this->getSourceRoot(), null, $this->getVars());
$asset->setValues($this->getValues());
$this->add($asset);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Assetic/Asset/HttpAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HttpAsset extends BaseAsset
*
* @throws \InvalidArgumentException If the first argument is not an URL
*/
public function __construct($sourceUrl, $filters = array(), $ignoreErrors = false, array $vars = array())
public function __construct($sourceUrl, $filters = [], $ignoreErrors = false, array $vars = [])
{
if (0 === strpos($sourceUrl, '//')) {
$sourceUrl = 'http:'.$sourceUrl;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function load(FilterInterface $additionalFilter = null)

public function getLastModified()
{
if (false !== @file_get_contents($this->sourceUrl, false, stream_context_create(array('http' => array('method' => 'HEAD'))))) {
if (false !== @file_get_contents($this->sourceUrl, false, stream_context_create(['http' => ['method' => 'HEAD']]))) {
foreach ($http_response_header as $header) {
if (0 === stripos($header, 'Last-Modified: ')) {
list(, $mtime) = explode(':', $header, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AssetCollectionFilterIterator extends \RecursiveFilterIterator
* @param array $visited An array of visited asset objects
* @param array $sources An array of visited source strings
*/
public function __construct(AssetCollectionIterator $iterator, array $visited = array(), array $sources = array())
public function __construct(AssetCollectionIterator $iterator, array $visited = [], array $sources = [])
{
parent::__construct($iterator);

Expand Down
2 changes: 1 addition & 1 deletion src/Assetic/Asset/StringAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class StringAsset extends BaseAsset
* @param string $sourceRoot The source asset root directory
* @param string $sourcePath The source asset path
*/
public function __construct($content, $filters = array(), $sourceRoot = null, $sourcePath = null)
public function __construct($content, $filters = [], $sourceRoot = null, $sourcePath = null)
{
$this->string = $content;

Expand Down
4 changes: 2 additions & 2 deletions src/Assetic/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class AssetManager
{
private $assets = array();
private $assets = [];

/**
* Gets an asset by name.
Expand Down Expand Up @@ -84,6 +84,6 @@ public function getNames()
*/
public function clear()
{
$this->assets = array();
$this->assets = [];
}
}
2 changes: 1 addition & 1 deletion src/Assetic/AssetWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AssetWriter
*
* @throws \InvalidArgumentException if a variable value is not a string
*/
public function __construct($dir, array $values = array())
public function __construct($dir, array $values = [])
{
foreach ($values as $var => $vals) {
foreach ($vals as $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Assetic/Cache/ArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class ArrayCache implements CacheInterface
{
private $cache = array();
private $cache = [];

/**
* @see CacheInterface::has()
Expand Down
29 changes: 14 additions & 15 deletions src/Assetic/Extension/Twig/AsseticExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,32 @@ class AsseticExtension extends \Twig_Extension implements \Twig_Extension_Global
protected $functions;
protected $valueSupplier;

public function __construct(AssetFactory $factory, $functions = array(), ValueSupplierInterface $valueSupplier = null)
public function __construct(AssetFactory $factory, $functions = [], ValueSupplierInterface $valueSupplier = null)
{
$this->factory = $factory;
$this->functions = array();
$this->functions = [];
$this->valueSupplier = $valueSupplier;

foreach ($functions as $function => $options) {
if (is_integer($function) && is_string($options)) {
$this->functions[$options] = array('filter' => $options);
} else {
$this->functions[$function] = $options + array('filter' => $function);
}

$this->functions[$options] = is_integer($function) && is_string($options)
? ['filter' => $options]
: $options + ['filter' => $function];
}
}

public function getTokenParsers()
{
return array(
return [
new AsseticTokenParser($this->factory, 'javascripts', 'js/*.js'),
new AsseticTokenParser($this->factory, 'stylesheets', 'css/*.css'),
new AsseticTokenParser($this->factory, 'image', 'images/*', true),
);
];
}

public function getFunctions()
{
$functions = array();
$functions = [];
foreach ($this->functions as $function => $filter) {
$functions[] = new AsseticFilterFunction($function);
}
Expand All @@ -56,12 +55,12 @@ public function getFunctions()

public function getGlobals()
{
return array(
'assetic' => array(
return [
'assetic' => [
'debug' => $this->factory->isDebug(),
'vars' => null !== $this->valueSupplier ? new ValueContainer($this->valueSupplier) : array(),
),
);
'vars' => null !== $this->valueSupplier ? new ValueContainer($this->valueSupplier) : [],
],
];
}

public function getFilterInvoker($function)
Expand Down
8 changes: 4 additions & 4 deletions src/Assetic/Extension/Twig/AsseticFilterFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

class AsseticFilterFunction extends \Twig_SimpleFunction
{
public function __construct($name, $options = array())
public function __construct($name, $options = [])
{
parent::__construct($name, null, array_merge($options, array(
'needs_environment' => false,
parent::__construct($name, null, array_merge($options, [
'needs_environment' => false,
'needs_context' => false,
'node_class' => '\Assetic\Extension\Twig\AsseticFilterNode',
)));
]));
}
}
9 changes: 4 additions & 5 deletions src/Assetic/Extension/Twig/AsseticFilterInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ public function __construct($factory, $filter)
{
$this->factory = $factory;

$this->filters = (array) $filter;
$this->options = [];
if (is_array($filter) && isset($filter['filter'])) {
$this->filters = (array) $filter['filter'];
$this->options = isset($filter['options']) ? (array) $filter['options'] : array();
} else {
$this->filters = (array) $filter;
$this->options = array();
$this->options = (array) $filter['options'] ?? [];
}
}

Expand All @@ -50,7 +49,7 @@ public function getOptions()
return $this->options;
}

public function invoke($input, array $options = array())
public function invoke($input, array $options = [])
{
$asset = $this->factory->createAsset($input, $this->filters, $options + $this->options);

Expand Down
Loading