From 71fe76bf5ad11cc49062fae6666731b59eb8820c Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Mon, 9 Sep 2019 15:17:38 +0500 Subject: [PATCH 01/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd53bdc..106d614 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Laravel HTMLMin is currently maintained by [Raza Mehdi](https://github.com/srmkl ## Installation -Laravel HTMLMin requires [PHP](https://php.net) 5.5+. This particular version supports Laravel 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, and 5.8 only. +Laravel HTMLMin requires [PHP](https://php.net) 5.5+. This particular version supports Laravel 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8 and 6.0 only. To get the latest version, simply require the project using [Composer](https://getcomposer.org): From 5351960ee6a9e48d9562b57003db5782a4cc5eab Mon Sep 17 00:00:00 2001 From: Alexandre D'Eschambeault Date: Sun, 20 Oct 2019 10:34:11 -0400 Subject: [PATCH 02/19] Fix Laravel 6.x dependency (#139) --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index fefe942..2464e75 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ ], "require": { "php": ">=5.5.9", - "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.0.*", - "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.0.*", - "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.0.*", - "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.0.*", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.0.*", - "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|6.0.*", + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", + "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", + "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", + "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", + "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", "mrclay/minify": "^2.2" }, "require-dev": { From f619d0d52864623261b76ee56084797879cb7a5d Mon Sep 17 00:00:00 2001 From: "Milad.Nouri" Date: Fri, 13 Mar 2020 19:29:06 +0330 Subject: [PATCH 03/19] Laravel 7 support (#148) Laravel 7 support --- composer.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 2464e75..317c670 100644 --- a/composer.json +++ b/composer.json @@ -15,18 +15,18 @@ ], "require": { "php": ">=5.5.9", - "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", - "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", - "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", - "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", - "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0", + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", + "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", + "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", + "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", + "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", "mrclay/minify": "^2.2" }, "require-dev": { "graham-campbell/testbench": "^3.1|^4.0|^5.0", "mockery/mockery": "^0.9.4|^1.0", - "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0" + "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0" }, "autoload": { "psr-4": { From d0e21a5282eeed1adafd1aaaecf2251d1b0d143c Mon Sep 17 00:00:00 2001 From: shovhan <37126140+shovhan@users.noreply.github.com> Date: Sat, 27 Jun 2020 14:42:05 +0300 Subject: [PATCH 04/19] Add support for blade directives and component aliases (#151) * feat(blade): add support for blade directives and component aliases * fix(blade): change minify compiler init * feat(viewComponent): add support for laravel 7 view components & refactor my tests Co-authored-by: Stas Shovhan --- src/Compilers/MinifyCompiler.php | 37 ++++++++++++++++++- src/HTMLMinServiceProvider.php | 10 ++++- tests/Functional/ComponentsTest.php | 37 +++++++++++++++++++ tests/Functional/DirectivesTest.php | 34 +++++++++++++++++ .../Provider/TestComponentsProvider.php | 28 ++++++++++++++ .../Provider/TestDirectivesProvider.php | 29 +++++++++++++++ tests/Mock/MinifyCompilerMock.php | 29 +++++++++++++++ tests/Mock/ViewComponentMock.php | 27 ++++++++++++++ 8 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 tests/Functional/ComponentsTest.php create mode 100644 tests/Functional/DirectivesTest.php create mode 100644 tests/Functional/Provider/TestComponentsProvider.php create mode 100644 tests/Functional/Provider/TestDirectivesProvider.php create mode 100644 tests/Mock/MinifyCompilerMock.php create mode 100644 tests/Mock/ViewComponentMock.php diff --git a/src/Compilers/MinifyCompiler.php b/src/Compilers/MinifyCompiler.php index 3c441e1..54a898c 100644 --- a/src/Compilers/MinifyCompiler.php +++ b/src/Compilers/MinifyCompiler.php @@ -36,6 +36,10 @@ class MinifyCompiler extends BladeCompiler * @var string */ protected $ignoredPaths; + /** + * @var \Illuminate\View\Compilers\BladeCompiler|null + */ + private $previousCompiler; /** * Create a new instance. @@ -44,15 +48,22 @@ class MinifyCompiler extends BladeCompiler * @param \Illuminate\Filesystem\Filesystem $files * @param string $cachePath * @param array $ignoredPaths + * @param \Illuminate\View\Compilers\BladeCompiler $previousCompiler * * @return void */ - public function __construct(BladeMinifier $blade, Filesystem $files, $cachePath, $ignoredPaths = []) - { + public function __construct( + BladeMinifier $blade, + Filesystem $files, + $cachePath, + $ignoredPaths = [], + $previousCompiler = null + ) { parent::__construct($files, $cachePath); $this->blade = $blade; $this->ignoredPaths = $ignoredPaths; $this->compilers[] = 'Minify'; + $this->previousCompiler = $previousCompiler; } /** @@ -96,4 +107,26 @@ public function getBladeMinifier() { return $this->blade; } + + /** + * @return void + */ + public function initMinifyCompiler() + { + if ($this->previousCompiler === null) { + return; + } + + if (property_exists($this->previousCompiler, 'customDirectives')) { + foreach ($this->previousCompiler->customDirectives as $name => $handler) { + $this->directive($name, $handler); + } + } + + if (property_exists($this->previousCompiler, 'classComponentAliases')) { + foreach ($this->previousCompiler->classComponentAliases as $name => $handler) { + $this->component($handler, $name); + } + } + } } diff --git a/src/HTMLMinServiceProvider.php b/src/HTMLMinServiceProvider.php index aeee44e..0dd2ac4 100644 --- a/src/HTMLMinServiceProvider.php +++ b/src/HTMLMinServiceProvider.php @@ -73,6 +73,7 @@ protected function enableBladeOptimisations() $app->view->getEngineResolver()->register('blade', function () use ($app) { $compiler = $app['htmlmin.compiler']; + $compiler->initMinifyCompiler(); return new CompilerEngine($compiler); }); @@ -163,13 +164,18 @@ protected function registerBladeMinifier() */ protected function registerMinifyCompiler() { - $this->app->singleton('htmlmin.compiler', function (Container $app) { + $previousCompiler = $this->app->make('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + + $this->app->singleton('htmlmin.compiler', function (Container $app) use ($previousCompiler) { $blade = $app['htmlmin.blade']; $files = $app['files']; $storagePath = $app->config->get('view.compiled'); $ignoredPaths = $app->config->get('htmlmin.ignore', []); - return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths); + return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $previousCompiler); }); $this->app->alias('htmlmin.compiler', MinifyCompiler::class); diff --git a/tests/Functional/ComponentsTest.php b/tests/Functional/ComponentsTest.php new file mode 100644 index 0000000..2313fc3 --- /dev/null +++ b/tests/Functional/ComponentsTest.php @@ -0,0 +1,37 @@ +app->version(), '7.0', '<')) { + $this->markTestSkipped('Class components were released in Laravel version 7.0.0'); + } + + /** @var MinifyCompiler $minifyCompiler */ + $minifyCompiler = $this->app->make('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + + $this->assertArrayHasKey('test-component', $minifyCompiler->getClassComponentAliases()); + } +} + diff --git a/tests/Functional/DirectivesTest.php b/tests/Functional/DirectivesTest.php new file mode 100644 index 0000000..45f3369 --- /dev/null +++ b/tests/Functional/DirectivesTest.php @@ -0,0 +1,34 @@ +app->make('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + + $compilerMock = MinifyCompilerMock::newInstance(); + $this->assertArrayHasKey('test_directive', $compilerMock->getCompilerCustomDirectives($minifyCompiler)); + } +} diff --git a/tests/Functional/Provider/TestComponentsProvider.php b/tests/Functional/Provider/TestComponentsProvider.php new file mode 100644 index 0000000..f98d25f --- /dev/null +++ b/tests/Functional/Provider/TestComponentsProvider.php @@ -0,0 +1,28 @@ + true]); + } + + public function boot() + { + /** @var BladeCompiler $previousCompiler */ + $previousCompiler = $this->app->make('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + + if (version_compare($this->app->version(), '7.0', '>=')) { + $previousCompiler->component(ViewComponentMock::class, 'test-component'); + } + } +} diff --git a/tests/Functional/Provider/TestDirectivesProvider.php b/tests/Functional/Provider/TestDirectivesProvider.php new file mode 100644 index 0000000..e9b4896 --- /dev/null +++ b/tests/Functional/Provider/TestDirectivesProvider.php @@ -0,0 +1,29 @@ +app->make('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + + $previousCompiler->directive('test_directive', [$this, 'testDirective']); + } +} diff --git a/tests/Mock/MinifyCompilerMock.php b/tests/Mock/MinifyCompilerMock.php new file mode 100644 index 0000000..fd0eba8 --- /dev/null +++ b/tests/Mock/MinifyCompilerMock.php @@ -0,0 +1,29 @@ +customDirectives; + } +} diff --git a/tests/Mock/ViewComponentMock.php b/tests/Mock/ViewComponentMock.php new file mode 100644 index 0000000..6f98482 --- /dev/null +++ b/tests/Mock/ViewComponentMock.php @@ -0,0 +1,27 @@ +content = $content; + } + + public function render() + { + return $this->content; + } +} From 6ae776686f4fed552281dda38857728002217a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Tue, 8 Sep 2020 07:54:57 +0100 Subject: [PATCH 05/19] Update readme with supported Laravel versions (#153) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 106d614..9bd5be0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Laravel HTMLMin =============== -Laravel HTMLMin is currently maintained by [Raza Mehdi](https://github.com/srmklive), and is a simple HTML minifier for [Laravel 5](http://laravel.com). It utilises Mr Clay's [Minify](https://github.com/mrclay/minify) package to minify entire responses, but can also minify blade at compile time. Feel free to check out the [change log](CHANGELOG.md), [releases](https://github.com/HTMLMin/Laravel-HTMLMin/releases), [license](LICENSE), and [contribution guidelines](CONTRIBUTING.md). +Laravel HTMLMin is currently maintained by [Raza Mehdi](https://github.com/srmklive), and is a simple HTML minifier for [Laravel](http://laravel.com). It utilises Mr Clay's [Minify](https://github.com/mrclay/minify) package to minify entire responses, but can also minify blade at compile time. Feel free to check out the [change log](CHANGELOG.md), [releases](https://github.com/HTMLMin/Laravel-HTMLMin/releases), [license](LICENSE), and [contribution guidelines](CONTRIBUTING.md).

Build Status @@ -12,7 +12,7 @@ Laravel HTMLMin is currently maintained by [Raza Mehdi](https://github.com/srmkl ## Installation -Laravel HTMLMin requires [PHP](https://php.net) 5.5+. This particular version supports Laravel 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8 and 6.0 only. +Laravel HTMLMin requires [PHP](https://php.net) 5.5+. This particular version supports Laravel 5.1-5.8, 6.x and 7.x. To get the latest version, simply require the project using [Composer](https://getcomposer.org): From b9ce99e6de3c77660cae79e33417feada733976b Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Tue, 8 Sep 2020 12:01:26 +0500 Subject: [PATCH 06/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bd5be0..472c805 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Laravel HTMLMin is currently maintained by [Raza Mehdi](https://github.com/srmkl ## Installation -Laravel HTMLMin requires [PHP](https://php.net) 5.5+. This particular version supports Laravel 5.1-5.8, 6.x and 7.x. +Laravel HTMLMin requires [PHP](https://php.net) 5.5+. This particular version supports Laravel 5.1-5.8, 6.x, 7.x and 8.x. To get the latest version, simply require the project using [Composer](https://getcomposer.org): From e67fe976e3fd1e92568341ce84f338fa4c0ffc47 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Tue, 8 Sep 2020 12:03:59 +0500 Subject: [PATCH 07/19] Support Laravel 8 --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 317c670..c2ac9f4 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ ], "require": { "php": ">=5.5.9", - "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", - "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", - "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", - "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", - "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0", + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", + "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", + "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", + "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", + "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", "mrclay/minify": "^2.2" }, "require-dev": { From 6c00109bca44cd226fd6f534b28dfb2884fbfd46 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Thu, 10 Feb 2022 12:53:54 +0700 Subject: [PATCH 08/19] Update composer.json to allow newer version mrclay/minify (#165) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c2ac9f4..986e32a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "mrclay/minify": "^2.2" + "mrclay/minify": "^2.2|^3.0" }, "require-dev": { "graham-campbell/testbench": "^3.1|^4.0|^5.0", From 79d5af0a03763eb866d7ebf23f3a0339e6e8fe3c Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Thu, 10 Feb 2022 06:56:24 +0100 Subject: [PATCH 09/19] Support Laravel 9 (#167) --- composer.json | 14 +++++++------- phpunit.xml.dist | 12 +++++++----- tests/AbstractTestCase.php | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 986e32a..f4c21a8 100644 --- a/composer.json +++ b/composer.json @@ -15,18 +15,18 @@ ], "require": { "php": ">=5.5.9", - "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", - "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0", + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", "mrclay/minify": "^2.2|^3.0" }, "require-dev": { "graham-campbell/testbench": "^3.1|^4.0|^5.0", "mockery/mockery": "^0.9.4|^1.0", - "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0" + "phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0|^9.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 986bc30..bd51815 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,7 @@ -./tests - - + + ./src - - + + diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 2a1cd4d..cd75a82 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -29,7 +29,7 @@ abstract class AbstractTestCase extends AbstractPackageTestCase * * @return string */ - protected function getServiceProviderClass($app) + protected function getServiceProviderClass() { return HTMLMinServiceProvider::class; } From a5531cc9e5c0b97b3a416cb6fcaaab9f5d9cc95b Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 11:43:15 +0500 Subject: [PATCH 10/19] Use Github Actions. --- .github/workflows/tests.yml | 35 +++++++++++++++++++++++++++++++++++ src/Minifiers/JsMinifier.php | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..a9ccf30 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,35 @@ +name: HTMLMinTests +on: [push, pull_request] +jobs: + htmlmin: + name: PHP ${{ matrix.php-versions }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP with Composer and extensions + with: + php-version: ${{ matrix.php-versions }} + uses: shivammathur/setup-php@v2 + - name: Get Composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache Composer dependencies + uses: actions/cache@v2 + with: + php-version: ${{ matrix.php-versions }} + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Composer dependencies + env: + PHP_VERSION: ${{ matrix.php-versions }} + run: composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) + - name: Run tests with code coverage + env: + PHP_VERSION: ${{ matrix.php-versions }} + run: vendor/bin/phpunit $(if [ "$PHP_VERSION" == "7.2" ]; then echo "-c phpunit.xml.dist.php72"; fi;) --coverage-clover build/logs/clover.xml diff --git a/src/Minifiers/JsMinifier.php b/src/Minifiers/JsMinifier.php index df30c7c..66ec879 100644 --- a/src/Minifiers/JsMinifier.php +++ b/src/Minifiers/JsMinifier.php @@ -12,7 +12,7 @@ namespace HTMLMin\HTMLMin\Minifiers; -use JSMin; +use JSMin\JSMin; /** * This is the js minifier class. From e8ab07a19fc79f041aef25002b86e6af6bd7fe9b Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 11:45:58 +0500 Subject: [PATCH 11/19] Fix build for PHP 7.2 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a9ccf30..74c961d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,4 +32,4 @@ jobs: - name: Run tests with code coverage env: PHP_VERSION: ${{ matrix.php-versions }} - run: vendor/bin/phpunit $(if [ "$PHP_VERSION" == "7.2" ]; then echo "-c phpunit.xml.dist.php72"; fi;) --coverage-clover build/logs/clover.xml + run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml From 678b9597fe69c0e2a3539582220b07c022bde8ab Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 12:08:56 +0500 Subject: [PATCH 12/19] Fix builds --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 74c961d..d59d14e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] steps: - name: Checkout uses: actions/checkout@v2 From b23349bb8fc3b15d256f56c78a6e484efe0a12de Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 14:45:30 +0500 Subject: [PATCH 13/19] Avoid resolving view when retrieving the previous compiler (Resolves #162). --- src/HTMLMinServiceProvider.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/HTMLMinServiceProvider.php b/src/HTMLMinServiceProvider.php index 0dd2ac4..8a78f4e 100644 --- a/src/HTMLMinServiceProvider.php +++ b/src/HTMLMinServiceProvider.php @@ -30,6 +30,11 @@ */ class HTMLMinServiceProvider extends ServiceProvider { + /** + * @var \Illuminate\View\Compilers\CompilerInterface|null + */ + protected $previousCompiler; + /** * Boot the service provider. * @@ -164,18 +169,22 @@ protected function registerBladeMinifier() */ protected function registerMinifyCompiler() { - $previousCompiler = $this->app->make('view') - ->getEngineResolver() - ->resolve('blade') - ->getCompiler(); + if (method_exists($this, 'callAfterResolving')) { + $this->callAfterResolving('view', function () { + $this->previousCompiler = $this->app->make('view') + ->getEngineResolver() + ->resolve('blade') + ->getCompiler(); + }); + } - $this->app->singleton('htmlmin.compiler', function (Container $app) use ($previousCompiler) { + $this->app->singleton('htmlmin.compiler', function (Container $app) { $blade = $app['htmlmin.blade']; $files = $app['files']; $storagePath = $app->config->get('view.compiled'); $ignoredPaths = $app->config->get('htmlmin.ignore', []); - return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $previousCompiler); + return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler); }); $this->app->alias('htmlmin.compiler', MinifyCompiler::class); From 59c3297a8ce7d9b173c5262be4a786176fdc438d Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 14:54:47 +0500 Subject: [PATCH 14/19] Allow failures in build. --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d59d14e..46a0dd9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] steps: - name: Checkout uses: actions/checkout@v2 @@ -33,3 +33,4 @@ jobs: env: PHP_VERSION: ${{ matrix.php-versions }} run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml + continue-on-error: true From abbd504e58822d002609ad515497f1760454fcf3 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 10 Feb 2022 15:14:10 +0500 Subject: [PATCH 15/19] Update badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 472c805..258792f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Laravel HTMLMin Laravel HTMLMin is currently maintained by [Raza Mehdi](https://github.com/srmklive), and is a simple HTML minifier for [Laravel](http://laravel.com). It utilises Mr Clay's [Minify](https://github.com/mrclay/minify) package to minify entire responses, but can also minify blade at compile time. Feel free to check out the [change log](CHANGELOG.md), [releases](https://github.com/HTMLMin/Laravel-HTMLMin/releases), [license](LICENSE), and [contribution guidelines](CONTRIBUTING.md).

-Build Status +Tests Software License Latest Version

From 2b112875f5f5c994907a82ea6d746de597e23be1 Mon Sep 17 00:00:00 2001 From: Scott Bedard Date: Wed, 10 Aug 2022 22:59:35 -0500 Subject: [PATCH 16/19] Update README (#168) --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 258792f..7194a4c 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,21 @@ To get the latest version, simply require the project using [Composer](https://g $ composer require htmlmin/htmlmin ``` -Once installed, you need to register the `HTMLMin\HTMLMin\HTMLMinServiceProvider` service provider in your `config/app.php`, and optionally alias our facade: +Once installed, register the service provider in your `config/app.php` ```php - 'HTMLMin' => HTMLMin\HTMLMin\Facades\HTMLMin::class, +'providers' => [ + HTMLMin\HTMLMin\HTMLMinServiceProvider::class +] ``` +If you want, a facade is available to alias + +```php +'aliases' => [ + 'HTMLMin' => HTMLMin\HTMLMin\Facades\HTMLMin::class +] +``` ## Configuration From 09b9cb44a113854cbe1f55e37fb98879e1417d49 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 11 Aug 2022 09:25:33 +0500 Subject: [PATCH 17/19] Fix #144 and tests for PHP 5.6 & 7.0. --- .github/workflows/tests.yml | 2 +- src/Compilers/MinifyCompiler.php | 10 +++++++++- src/HTMLMinServiceProvider.php | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 46a0dd9..fbaaae2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Install Composer dependencies env: PHP_VERSION: ${{ matrix.php-versions }} - run: composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) + run: $(if [ "$PHP_VERSION" == "5.6" || "$PHP_VERSION" == "7.0" ]; then echo "composer config --no-plugins allow-plugins.kylekatarnls/update-helper true &&"; fi;) composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) - name: Run tests with code coverage env: PHP_VERSION: ${{ matrix.php-versions }} diff --git a/src/Compilers/MinifyCompiler.php b/src/Compilers/MinifyCompiler.php index 54a898c..c0164ba 100644 --- a/src/Compilers/MinifyCompiler.php +++ b/src/Compilers/MinifyCompiler.php @@ -49,6 +49,7 @@ class MinifyCompiler extends BladeCompiler * @param string $cachePath * @param array $ignoredPaths * @param \Illuminate\View\Compilers\BladeCompiler $previousCompiler + * @param array $customDirectives * * @return void */ @@ -57,13 +58,20 @@ public function __construct( Filesystem $files, $cachePath, $ignoredPaths = [], - $previousCompiler = null + $previousCompiler = null, + $customDirectives = [] ) { parent::__construct($files, $cachePath); $this->blade = $blade; $this->ignoredPaths = $ignoredPaths; $this->compilers[] = 'Minify'; $this->previousCompiler = $previousCompiler; + + if (count($customDirectives)) { + foreach ($customDirectives as $key => $value) { + $this->directive($key, $value); + } + } } /** diff --git a/src/HTMLMinServiceProvider.php b/src/HTMLMinServiceProvider.php index 8a78f4e..7eed413 100644 --- a/src/HTMLMinServiceProvider.php +++ b/src/HTMLMinServiceProvider.php @@ -184,7 +184,7 @@ protected function registerMinifyCompiler() $storagePath = $app->config->get('view.compiled'); $ignoredPaths = $app->config->get('htmlmin.ignore', []); - return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler); + return new MinifyCompiler($blade, $files, $storagePath, $ignoredPaths, $this->previousCompiler, $this->previousCompiler->getCustomDirectives()); }); $this->app->alias('htmlmin.compiler', MinifyCompiler::class); From b628c87d1a6c9eac6a119f36ca1cdd577392abd2 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Thu, 11 Aug 2022 09:31:03 +0500 Subject: [PATCH 18/19] Allow plugin. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fbaaae2..019bb8a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Install Composer dependencies env: PHP_VERSION: ${{ matrix.php-versions }} - run: $(if [ "$PHP_VERSION" == "5.6" || "$PHP_VERSION" == "7.0" ]; then echo "composer config --no-plugins allow-plugins.kylekatarnls/update-helper true &&"; fi;) composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) + run: composer config --no-plugins allow-plugins.kylekatarnls/update-helper true && composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) - name: Run tests with code coverage env: PHP_VERSION: ${{ matrix.php-versions }} From 347d5776b321b8d6bf9fd0285984dcd1d2589f3f Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Tue, 14 Feb 2023 00:44:53 +0500 Subject: [PATCH 19/19] Laravel 10 compatibility --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f4c21a8..a686cac 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ ], "require": { "php": ">=5.5.9", - "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", - "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0", + "illuminate/contracts": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/filesystem": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/http": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/routing": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/view": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0", "mrclay/minify": "^2.2|^3.0" }, "require-dev": {