From 7fd8e16ab91b002ab2f4579fd127680733abd224 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 10 Feb 2024 17:54:20 -0500 Subject: [PATCH 1/5] refactor: Added `ServicesTrait` for the plugin service component registration --- src/Minify.php | 8 +++-- src/services/ServicesTrait.php | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100755 src/services/ServicesTrait.php diff --git a/src/Minify.php b/src/Minify.php index 8c7569d..c2853c7 100644 --- a/src/Minify.php +++ b/src/Minify.php @@ -12,7 +12,7 @@ use Craft; use craft\base\Plugin; use nystudio107\minify\models\Settings; -use nystudio107\minify\services\MinifyService; +use nystudio107\minify\services\ServicesTrait; use nystudio107\minify\twigextensions\MinifyTwigExtension; /** @@ -22,11 +22,15 @@ * @package Minify * @since 1.2.0 * - * @property MinifyService $minify * @method Settings getSettings() */ class Minify extends Plugin { + // Traits + // ========================================================================= + + use ServicesTrait; + /** * @var Minify */ diff --git a/src/services/ServicesTrait.php b/src/services/ServicesTrait.php new file mode 100755 index 0000000..ae75e89 --- /dev/null +++ b/src/services/ServicesTrait.php @@ -0,0 +1,53 @@ + [ + 'minify' => MinifyService::class, + ], + ], $config); + + parent::__construct($id, $parent, $config); + } + + /** + * Returns the helper service + * + * @return MinifyService The helper service + * @throws InvalidConfigException + */ + public function getMinify(): MinifyService + { + return $this->get('minify'); + } +} From b1f22f6ac6946b5f96a1a3cc0e156d6883292a28 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 10 Feb 2024 17:54:27 -0500 Subject: [PATCH 2/5] chore: Version 1.2.13 --- CHANGELOG.md | 4 ++++ composer.json | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 935a564..113e85c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Minify Changelog +## 1.2.13 - UNRELEASED +### Added +* Added `ServicesTrait` for the plugin service component registration + ## 1.2.12 - 2024.02.09 ### Added * Add `phpstan` and `ecs` code linting diff --git a/composer.json b/composer.json index ca923c3..f7a1879 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-minify", "description": "A simple plugin that allows you to minify blocks of HTML, CSS, and JS inline in Craft CMS templates.", "type": "craft-plugin", - "version": "1.2.12", + "version": "1.2.13", "keywords": [ "craft", "cms", @@ -55,9 +55,6 @@ "hasCpSettings": false, "hasCpSection": false, "changelogUrl": "https://raw.githubusercontent.com/nystudio107/craft-minify/v1/CHANGELOG.md", - "class": "nystudio107\\minify\\Minify", - "components": { - "minify": "nystudio107\\minify\\services\\MinifyService" - } + "class": "nystudio107\\minify\\Minify" } } From d0ba3548290923bc9cd3e2940af9fa254162bdf1 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 10 Feb 2024 18:02:40 -0500 Subject: [PATCH 3/5] refactor: Code & comment cleanup --- .gitignore | 2 +- src/Minify.php | 2 +- src/config.php | 2 +- src/models/Settings.php | 4 +--- src/services/MinifyService.php | 14 ++++++++------ src/services/ServicesTrait.php | 2 +- src/translations/en/minify.php | 2 +- src/twigextensions/MinifyNode.php | 2 +- src/twigextensions/MinifyTokenParser.php | 2 +- src/twigextensions/MinifyTwigExtension.php | 6 ++++-- 10 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index ead0b9d..e916568 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ # Example .gitignore file for Craft CMS projects # # @author nystudio107 -# @copyright Copyright (c) 2017 nystudio107 +# @copyright Copyright (c) nystudio107 # @link https://nystudio107.com/ # @package craft-scripts # @since 1.1.0 diff --git a/src/Minify.php b/src/Minify.php index c2853c7..85214c7 100644 --- a/src/Minify.php +++ b/src/Minify.php @@ -3,7 +3,7 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ diff --git a/src/config.php b/src/config.php index 4eddac3..ad0ff3f 100755 --- a/src/config.php +++ b/src/config.php @@ -3,7 +3,7 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ diff --git a/src/models/Settings.php b/src/models/Settings.php index 70a74bc..bb9e93d 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -3,7 +3,7 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ @@ -11,8 +11,6 @@ use craft\base\Model; -use nystudio107\minify\Minify; - /** * Minify Settings model * diff --git a/src/services/MinifyService.php b/src/services/MinifyService.php index 98b9a77..c40b6a3 100644 --- a/src/services/MinifyService.php +++ b/src/services/MinifyService.php @@ -3,15 +3,17 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ namespace nystudio107\minify\services; use Craft; - use craft\base\Component; +use JSMin\JSMin; +use Minify_CSSmin; +use Minify_HTML; use nystudio107\minify\Minify; /** @@ -54,7 +56,7 @@ public function minify($htmlText = "") 'cssMinifier' => '\Minify_CSSmin::minify', 'jsMinifier' => '\JSMin\JSMin::minify', ]; - $htmlText = \Minify_HTML::minify($htmlText, $options); + $htmlText = Minify_HTML::minify($htmlText, $options); } return $htmlText; @@ -70,7 +72,7 @@ public function minify($htmlText = "") public function htmlMin($htmlText = "") { if ($this->shouldMinify) { - $htmlText = \Minify_HTML::minify($htmlText); + $htmlText = Minify_HTML::minify($htmlText); } return $htmlText; @@ -86,7 +88,7 @@ public function htmlMin($htmlText = "") public function cssMin($cssText = "") { if ($this->shouldMinify) { - $cssText = \Minify_CSSmin::minify($cssText); + $cssText = Minify_CSSmin::minify($cssText); } return $cssText; @@ -102,7 +104,7 @@ public function cssMin($cssText = "") public function jsMin($jsText = "") { if ($this->shouldMinify) { - $jsText = \JSMin\JSMin::minify($jsText); + $jsText = JSMin::minify($jsText); } return $jsText; diff --git a/src/services/ServicesTrait.php b/src/services/ServicesTrait.php index ae75e89..11fe2b1 100755 --- a/src/services/ServicesTrait.php +++ b/src/services/ServicesTrait.php @@ -3,7 +3,7 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ diff --git a/src/translations/en/minify.php b/src/translations/en/minify.php index be5ee20..17859cc 100644 --- a/src/translations/en/minify.php +++ b/src/translations/en/minify.php @@ -3,7 +3,7 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ diff --git a/src/twigextensions/MinifyNode.php b/src/twigextensions/MinifyNode.php index 484f553..6d0d1f5 100644 --- a/src/twigextensions/MinifyNode.php +++ b/src/twigextensions/MinifyNode.php @@ -3,7 +3,7 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ diff --git a/src/twigextensions/MinifyTokenParser.php b/src/twigextensions/MinifyTokenParser.php index 9b960d8..26d2423 100644 --- a/src/twigextensions/MinifyTokenParser.php +++ b/src/twigextensions/MinifyTokenParser.php @@ -3,7 +3,7 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ diff --git a/src/twigextensions/MinifyTwigExtension.php b/src/twigextensions/MinifyTwigExtension.php index 6258b77..8f0eede 100644 --- a/src/twigextensions/MinifyTwigExtension.php +++ b/src/twigextensions/MinifyTwigExtension.php @@ -3,12 +3,14 @@ * Minify plugin for Craft CMS 3.x * * @link https://nystudio107.com/ - * @copyright Copyright (c) 2017 nystudio107 + * @copyright Copyright (c) nystudio107 * @license MIT License https://opensource.org/licenses/MIT */ namespace nystudio107\minify\twigextensions; +use Twig_Extension; + /** * Minify twig extension * @@ -16,7 +18,7 @@ * @package Minify * @since 1.2.0 */ -class MinifyTwigExtension extends \Twig_Extension +class MinifyTwigExtension extends Twig_Extension { // Public Methods // ========================================================================= From 48cf0665e82b5e03264ece3157c7153161a2a259 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 10 Feb 2024 18:09:52 -0500 Subject: [PATCH 4/5] refactor: minify --- src/services/ServicesTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/ServicesTrait.php b/src/services/ServicesTrait.php index 11fe2b1..66904ef 100755 --- a/src/services/ServicesTrait.php +++ b/src/services/ServicesTrait.php @@ -43,7 +43,7 @@ public function __construct($id, $parent = null, array $config = []) /** * Returns the helper service * - * @return MinifyService The helper service + * @return MinifyService The minify service * @throws InvalidConfigException */ public function getMinify(): MinifyService From e923eb0ead673d02aed59f5e8f9639fbd9eb7f3a Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 10 Feb 2024 19:06:00 -0500 Subject: [PATCH 5/5] chore: Version 1.2.13 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 113e85c..53c4c25 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Minify Changelog -## 1.2.13 - UNRELEASED +## 1.2.13 - 2024.02.10 ### Added * Added `ServicesTrait` for the plugin service component registration