Removed huge regex and replaced with strtr call

This commit is contained in:
vladimmi 2015-03-12 17:24:31 +03:00
parent 74a3ffd65d
commit 500c487543

View File

@ -327,26 +327,7 @@ abstract class Minify
return $content;
}
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier) {
return $minifier->extracted[$match[0]];
};
/*
* I basically want a str_replace to put back all of the extracted data.
* However, str_replace iteratively goes over the full content for every
* value, which means that if I've replaced the first extracted thingy,
* it will again search the full content for the second extracted thing.
* Which means that, if the original value for the first extract looks
* similar to a placeholder that has yet to be restored, that value
* would get replaced.
* Instead, I'll go a preg_replace, which just processes the content
* until it finds a match, replaces that, and continues from that point.
*/
$delimiter = array_fill(0, count($this->extracted), '/');
$keys = array_map('preg_quote', array_keys($this->extracted), $delimiter);
$content = preg_replace_callback('/(' . implode('|', $keys) . ')/', $callback, $content);
$content = strtr($content, $this->extracted);
$this->extracted = array();