refactor
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
function inlineLocalStylesFromHref($inputString) {
|
||||
function inlineLocalStylesFromHref($inputString): string
|
||||
{
|
||||
$pattern = '/<link[^>]*?\srel=["\']?stylesheet["\'].*?\shref=["\']?\/(.*?)["\'][^>]*?>/i';
|
||||
|
||||
$outputString = preg_replace_callback($pattern, function($match) {
|
||||
return preg_replace_callback($pattern, function($match) {
|
||||
$href = $match[1];
|
||||
$cssFilePath = $_SERVER['DOCUMENT_ROOT'] . '/' . $href;
|
||||
$cssContent = file_get_contents($cssFilePath);
|
||||
@@ -28,14 +29,13 @@ function inlineLocalStylesFromHref($inputString) {
|
||||
|
||||
return "<style>{$cssContent}</style>";
|
||||
}, $inputString);
|
||||
|
||||
return $outputString;
|
||||
}
|
||||
|
||||
function inlineScriptFromSrc($inputString) {
|
||||
function inlineScriptFromSrc($inputString): string
|
||||
{
|
||||
$pattern = '/<script.*?src=["\']\/(.*?)["\'].*?>\s*<\/script>/i';
|
||||
|
||||
$outputString = preg_replace_callback($pattern, function($match) {
|
||||
return preg_replace_callback($pattern, function($match) {
|
||||
$src = $match[1];
|
||||
$jsContent = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . $src);
|
||||
|
||||
@@ -43,11 +43,10 @@ function inlineScriptFromSrc($inputString) {
|
||||
$jsContent = minifyJs($jsContent);
|
||||
return "<script>{$jsContent}</script>";
|
||||
}, $inputString);
|
||||
|
||||
return $outputString;
|
||||
}
|
||||
|
||||
function minifyCss($css) {
|
||||
function minifyCss($css): string
|
||||
{
|
||||
// Remove comments
|
||||
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
|
||||
|
||||
@@ -66,7 +65,8 @@ function minifyCss($css) {
|
||||
return trim($css);
|
||||
}
|
||||
|
||||
function minifyJs($js) {
|
||||
function minifyJs($js): string
|
||||
{
|
||||
|
||||
// Remove newlines and tabs
|
||||
$js = str_replace("\t", '', $js);
|
||||
|
Reference in New Issue
Block a user