/**
* @throws \rmrevin\yii\minify\Exception
*/
public function init()
{
parent::init();
$minify_path = $this->minify_path = (string) \Yii::getAlias($this->minify_path);
if (!file_exists($minify_path)) {
helpers\FileHelper::createDirectory($minify_path);
}
if (!is_readable($minify_path)) {
throw new Exception('Directory for compressed assets is not readable.');
}
if (!is_writable($minify_path)) {
throw new Exception('Directory for compressed assets is not writable.');
}
if (true === $this->compress_output) {
\Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function (\yii\base\Event $Event) {
/** @var \yii\web\Response $Response */
$Response = $Event->sender;
if ($Response->format === \yii\web\Response::FORMAT_HTML) {
if (!empty($Response->data)) {
$Response->data = HtmlCompressor::compress($Response->data, $this->compress_options);
}
if (!empty($Response->content)) {
$Response->content = HtmlCompressor::compress($Response->content, $this->compress_options);
}
}
});
}
}