Skip to content

Commit

Permalink
Merge pull request #30 from assetic-php/wip/php8.1
Browse files Browse the repository at this point in the history
v3.0 - Support PHP 8.1
  • Loading branch information
LukeTowers authored Feb 22, 2022
2 parents a39be45 + b8df2e7 commit 5515149
Show file tree
Hide file tree
Showing 54 changed files with 502 additions and 424 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
strategy:
max-parallel: 6
matrix:
phpVersion: ['7.2', '7.3', '7.4', '8.0']
phpVersion: ['7.3', '7.4', '8.0', '8.1']
fail-fast: false
runs-on: ubuntu-latest
name: Linux / PHP ${{ matrix.phpVersion }}
env:
extensions: curl, fileinfo, gd, mbstring, openssl, pdo, pdo_sqlite, sqlite3, xml
key: october-rain-cache-v1
key: assetic-php-cache-v1
steps:
- name: Checkout changes
uses: actions/checkout@v2
Expand Down
33 changes: 33 additions & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
v3.0.0 (2022-02-22)
------------------

Assetic v3 is another refresh of the project in order to keep the core lean and
up to date with modern standards. More deprecated / abandoned filters have been
removed and replaced with modern maintained alternatives.

New filters are still recommended to be added in external packages and the core
is to be kept as minimal as possible.

### New features

* Support for PHP 8.0 & PHP 8.1
* Support for `symfony/process: v6.x`
* Added `Assetic\Filter\JavaScriptMinifierFilter`
* Added `Assetic\Filter\CSSMinFilter`
* Added `Assetic\Filter\StylesheetMinfyFilter`

### BC breaks

- Minimum PHP version required is now PHP 7.3
- Removed support for the unmaintained `mrclay/minify`, `patchwork/jsqueeze`, & `natxet/CssMin` packages in favour of `wikimedia/minify`.

# Filters Removed:
- `JSMinFilter` (use `JavaScriptMinifierFilter` instead)
- `JSMinPlusFilter` (use `JavaScriptMinifierFilter` instead)
- `JSqueezeFilter` (use `JavaScriptMinifierFilter` instead)
- `CssMinFilter` (use `CssImportFilter` combined with the `CSSMinFilter` instead)
- Abandoned for all intents and purposes; maintainer has not interacted with the project for four years at least, not even able to maintain the package in the first place (https://github.com/natxet/CssMin/issues/23#issuecomment-257352700).
- Several long standing unresolved bugs in relatively common CSS use cases
- `MinifyCssCompressorFilter` (use replacement for `CssMinFilter` above or use `StylesheetMinifyFilter` instead)
- Abandoned, see: https://github.com/mrclay/minify/commit/0bc376980248f421c50b039beb869dd46cd9b043
- Considered replacing with https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port (last touched in 2018) but it is not fully supported in PHP 7.4: https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/issues/57 & is abandoned for all intents and purporses; maintainer has not interacted with the project for four years at least and maintainer seems to no longer be working with PHP in general.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ The core provides the following filters in the `Assetic\Filter` namespace:

* `CoffeeScriptFilter`: compiles CoffeeScript into Javascript
* `CssImportFilter`: inlines imported stylesheets
* `CssMinFilter`: minifies CSS
* `CSSMinFilter`: minifies CSS
* `CssRewriteFilter`: fixes relative URLs in CSS assets when moving to a new URL
* `GoogleClosure\CompilerApiFilter`: compiles Javascript using the Google Closure Compiler API
* `HandlebarsFilter`: compiles Handlebars templates into Javascript
* `JavaScriptMinifierFilter`: minifies Javascript
* `JpegoptimFilter`: optimize your JPEGs
* `JpegtranFilter`: optimize your JPEGs
* `JSMinFilter`: minifies Javascript
* `JSMinPlusFilter`: minifies Javascript
* `JSqueezeFilter`: compresses Javascript
* `LessFilter`: parses LESS into CSS (using less.js with node.js)
* `LessphpFilter`: parses LESS into CSS (using lessphp)
* `OptiPngFilter`: optimize your PNGs
Expand All @@ -95,6 +93,7 @@ The core provides the following filters in the `Assetic\Filter` namespace:
* `ReactJsxFilter`: compiles React JSX into JavaScript
* `ScssphpFilter`: parses SCSS into CSS
* `SeparatorFilter`: inserts a separator between assets to prevent merge failures
* `StylesheetMinifyFilter`: compresses stylesheet CSS files
* `StylusFilter`: parses STYL into CSS
* `TypeScriptFilter`: parses TypeScript into Javascript
* `UglifyCssFilter`: minifies CSS
Expand Down Expand Up @@ -246,15 +245,15 @@ A simple caching mechanism is provided to avoid unnecessary work.
use Assetic\Asset\AssetCache;
use Assetic\Asset\FileAsset;
use Assetic\Cache\FilesystemCache;
use Assetic\Filter\JsMinFilter;
use Assetic\Filter\JavaScriptMinifierFilter;

$jsMin = new JsMinFilter();
$jsMinifier = new JavaScriptMinifierFilter();
$js = new AssetCache(
new FileAsset('/path/to/some.js', array($jsMin)),
new FileAsset('/path/to/some.js', array($jsMinifier)),
new FilesystemCache('/path/to/cache')
);

// the JsMin compressor will only run on the first call
// the JavaScriptMinifierFilter compressor will only run on the first call
$js->dump();
$js->dump();
$js->dump();
Expand Down
27 changes: 12 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,40 @@
}
],
"require": {
"php": "^7.2 || ^8.0",
"php": ">=7.3 || ^8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-simplexml": "*",
"symfony/process": "~3.4 || ~4.0 || ~5.0",
"symfony/process": "~3.4 || ~4.0 || ~5.0 || ~6.0",
"symfony/deprecation-contracts": "^2.2.0"
},
"require-dev": {
"wikimedia/less.php": "~3.0.0",
"wikimedia/minify": "~2.2",
"scssphp/scssphp": "^1.0",
"meenie/javascript-packer": "^1.1",
"mrclay/minify": "<2.3",
"natxet/cssmin": "^3.0.6",
"patchwork/jsqueeze": "^1.0 || ^2.0",
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^9.5.8",
"psr/log": "^1.0",
"ptachoire/cssembed": "^1.0",
"symfony/phpunit-bridge": "~3.4 || ~4.0 || ~5.0",
"symfony/phpunit-bridge": "~3.4 || ~4.0 || ~5.0 || ~6.0",
"twig/twig": "^2.11",
"twig/extensions": "^1.5"
"phpspec/prophecy-phpunit": "^2.0"
},
"suggest": {
"wikimedia/less.php": "The Assetic\\Filter\\LessphpFilter requires wikimedia/less.php",
"wikimedia/minify": "The Assetic\\Filter\\JavaScriptMinifierFilter && Assetic\\Filter\\CSSMinFilter requires wikimedia/minify",
"scssphp/scssphp": "The Assetic\\Filter\\ScssphpFilter requires scssphp/scssphp",
"meenie/javascript-packer": "The Assetic\\Filter\\PackerFilter requires meenie/javascript-packer",
"mrclay/minify": "The Assetic\\Filter\\JSMinFilter requires mrclay/minify < 2.3",
"natxet/cssmin": "The Assetic\\Filter\\CssMinFilter requires natxet/cssmin",
"patchwork/jsqueeze": "The Assetic\\Filter\\JSqueezeFilter requires patchwork/jsqueeze",
"ptachoire/cssembed": "The Assetic\\Filter\\PhpCssEmbedFilter requires ptachoire/cssembed",
"twig/twig": "Assetic provides an integration with the Twig templating engine",
"twig/extensions": "Assetic provides an integration with the Twig templating engine"
"twig/twig": "Assetic provides an integration with the Twig templating engine"
},
"replace": {
"kriswallsmith/assetic": "*"
"kriswallsmith/assetic": "1.4.0"
},
"autoload": {
"psr-0": { "Assetic": "src/" },
"psr-0": {
"Assetic": "src/"
},
"files": [
"src/functions.php",
"src/aliasing.php"
Expand Down
4 changes: 2 additions & 2 deletions docs/en/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ For example, you could create a file in your web directory at

use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Filter\JsMinFilter;
use Assetic\Filter\JavaScriptMinifierFilter;

$js = new AssetCollection(array(
new FileAsset(__DIR__.'/jquery.js'),
new FileAsset(__DIR__.'/application.js'),
), array(
new JsMinFilter(),
new JavaScriptMinifierFilter(),
));

header('Content-Type: application/js');
Expand Down
4 changes: 2 additions & 2 deletions docs/ja/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Asseticを使う一番単純な方法は、次の2ステップからなります

use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Filter\JsMinFilter;
use Assetic\Filter\JavaScriptMinifierFilter;

$js = new AssetCollection(array(
new FileAsset(__DIR__.'/jquery.js'),
new FileAsset(__DIR__.'/application.js'),
), array(
new JsMinFilter(),
new JavaScriptMinifierFilter(),
));

header('Content-Type: application/js');
Expand Down
35 changes: 14 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/bootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
>
<testsuites>
<testsuite name="Assetic Test Suite">
<directory suffix="Test.php">./tests/Assetic/Test/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src/Assetic/</directory>
</whitelist>
</filter>

<php>
<server name="NODE_PATH" value="./node_modules/"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src/Assetic/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Assetic Test Suite">
<directory suffix="Test.php">./tests/Assetic/Test/</directory>
</testsuite>
</testsuites>
<php>
<server name="NODE_PATH" value="./node_modules/"/>
</php>
</phpunit>
3 changes: 2 additions & 1 deletion src/Assetic/Asset/AssetCollection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Assetic\Asset;

use Traversable;
use Assetic\Asset\Iterator\AssetCollectionFilterIterator;
use Assetic\Asset\Iterator\AssetCollectionIterator;
use Assetic\Filter\FilterCollection;
Expand Down Expand Up @@ -203,7 +204,7 @@ public function getLastModified()
/**
* Returns an iterator for looping recursively over unique leaves.
*/
public function getIterator()
public function getIterator(): Traversable
{
return new \RecursiveIteratorIterator(new AssetCollectionFilterIterator(new AssetCollectionIterator($this, $this->clones)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Assetic/Asset/BaseAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function setTargetPath($targetPath)
{
if ($this->vars) {
foreach ($this->vars as $var) {
if (false === strpos($targetPath, $var)) {
if (false === strpos($targetPath ?: '', $var)) {
throw new \RuntimeException(sprintf('The asset target path "%s" must contain the variable "{%s}".', $targetPath, $var));
}
}
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 @@ -31,7 +31,7 @@ public function __construct($source, $filters = [], $sourceRoot = null, $sourceP
$sourcePath = basename($source);
}
} elseif (null === $sourcePath) {
if (0 !== strpos($source, $sourceRoot)) {
if (0 !== strpos($source ?: '', $sourceRoot)) {
throw new \InvalidArgumentException(sprintf('The source "%s" is not in the root directory "%s"', $source, $sourceRoot));
}

Expand Down
3 changes: 2 additions & 1 deletion src/Assetic/Asset/GlobAsset.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Assetic\Asset;

use Traversable;
use Assetic\Contracts\Filter\FilterInterface;
use Assetic\Util\VarUtils;

Expand Down Expand Up @@ -65,7 +66,7 @@ public function getLastModified()
return parent::getLastModified();
}

public function getIterator()
public function getIterator(): Traversable
{
if (!$this->initialized) {
$this->initialize();
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 @@ -25,9 +25,9 @@ class HttpAsset extends BaseAsset
*/
public function __construct($sourceUrl, $filters = [], $ignoreErrors = false, array $vars = [])
{
if (0 === strpos($sourceUrl, '//')) {
if (0 === strpos($sourceUrl ?: '', '//')) {
$sourceUrl = 'http:'.$sourceUrl;
} elseif (false === strpos($sourceUrl, '://')) {
} elseif (false === strpos($sourceUrl ?: '', '://')) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL.', $sourceUrl));
}

Expand Down
8 changes: 5 additions & 3 deletions src/Assetic/Asset/Iterator/AssetCollectionFilterIterator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace Assetic\Asset\Iterator;

use RecursiveFilterIterator;

/**
* Asset collection filter iterator.
*
Expand All @@ -8,7 +10,7 @@
*
* @author Kris Wallsmith <[email protected]>
*/
class AssetCollectionFilterIterator extends \RecursiveFilterIterator
class AssetCollectionFilterIterator extends RecursiveFilterIterator
{
private $visited;
private $sources;
Expand Down Expand Up @@ -36,7 +38,7 @@ public function __construct(AssetCollectionIterator $iterator, array $visited =
*
* @return Boolean Returns true if we have not seen this asset yet
*/
public function accept()
public function accept(): bool
{
$asset = $this->getInnerIterator()->current(true);
$duplicate = false;
Expand Down Expand Up @@ -66,7 +68,7 @@ public function accept()
/**
* Passes visited objects and source URLs to the child iterator.
*/
public function getChildren()
public function getChildren(): ?RecursiveFilterIterator
{
return new self($this->getInnerIterator()->getChildren(), $this->visited, $this->sources);
}
Expand Down
Loading

0 comments on commit 5515149

Please sign in to comment.