diff --git a/src/Adapters/MinifykuAdapter.php b/src/Adapters/MinifykuCSSAdapter.php similarity index 50% rename from src/Adapters/MinifykuAdapter.php rename to src/Adapters/MinifykuCSSAdapter.php index e08d9f0..2c2e48a 100644 --- a/src/Adapters/MinifykuAdapter.php +++ b/src/Adapters/MinifykuCSSAdapter.php @@ -3,34 +3,22 @@ namespace PHPDevsr\Minifyku\Adapters; use MatthiasMullie\Minify\CSS as MinifyCSS; -use MatthiasMullie\Minify\JS as MinifyJS; -use PHPDevsr\Minifyku\Exceptions\MinifykuException; -class MinifykuAdapter implements AdapterInterface +class MinifykuCSSAdapter implements AdapterInterface { /** * Adapter object. * - * @var MinifyCSS|MinifyJS + * @var object */ protected $adapter; /** * __construct */ - public function __construct(string $type = 'css') + public function __construct() { - if (! in_array($type, ['js', 'css'], true)) { - throw MinifykuException::forWrongFileExtension($type); - } - - if ($type === 'js') { - $this->adapter = new MinifyJS(); - } - - if ($type === 'css') { - $this->adapter = new MinifyCSS(); - } + $this->adapter = new MinifyCSS(); } /** diff --git a/src/Adapters/MinifykuJSAdapter.php b/src/Adapters/MinifykuJSAdapter.php new file mode 100644 index 0000000..9025f16 --- /dev/null +++ b/src/Adapters/MinifykuJSAdapter.php @@ -0,0 +1,43 @@ +adapter = new MinifyJS(); + } + + /** + * Add file + * + * @param string $file File name + */ + public function add($file) + { + $this->adapter->add($file); + } + + /** + * Minify file + * + * @param string $file File name + */ + public function minify(string $file) + { + return $this->adapter->minify($file); + } +} diff --git a/src/Minifyku.php b/src/Minifyku.php index b312692..d50d970 100644 --- a/src/Minifyku.php +++ b/src/Minifyku.php @@ -4,7 +4,8 @@ namespace PHPDevsr\Minifyku; -use PHPDevsr\Minifyku\Adapters\MinifykuAdapter; +use PHPDevsr\Minifyku\Adapters\MinifykuCSSAdapter; +use PHPDevsr\Minifyku\Adapters\MinifykuJSAdapter; use PHPDevsr\Minifyku\Config\Minifyku as MinifykuConfig; use PHPDevsr\Minifyku\Exceptions\MinifykuException; @@ -272,10 +273,11 @@ protected function deployFiles(string $fileType, array $assets, string $dir, ?st $minDir = $dir; } - $results = []; + $classMinify = $fileType === 'js' ? MinifykuJSAdapter::class : MinifykuCSSAdapter::class; + $results = []; foreach ($assets as $asset => $files) { - $class = new MinifykuAdapter($fileType); + $class = new $classMinify(); foreach ($files as $file) { $class->add($dir . DIRECTORY_SEPARATOR . $file);