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/CHANGELOG.md b/CHANGELOG.md index 935a564..53c4c25 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Minify Changelog +## 1.2.13 - 2024.02.10 +### 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" } } diff --git a/src/Minify.php b/src/Minify.php index 8c7569d..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 */ @@ -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/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 new file mode 100755 index 0000000..66904ef --- /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 minify service + * @throws InvalidConfigException + */ + public function getMinify(): MinifyService + { + return $this->get('minify'); + } +} 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 // =========================================================================