for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @package s9e\TextFormatter
* @copyright Copyright (c) 2010-2017 The s9e Authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
use DOMAttr;
use s9e\TextFormatter\Configurator\Helpers\TemplateHelper;
class MinifyInlineCSS extends AbstractNormalization
{
* {@inheritdoc}
protected function getNodes()
return TemplateHelper::getCSSNodes($this->ownerDocument);
}
protected function normalizeAttribute(DOMAttr $attribute)
$css = $attribute->nodeValue;
// Only minify if the value does not contain any XPath expression that's not an attribute
if (!preg_match('(\\{(?!@\\w+\\}))', $css))
$attribute->nodeValue = $this->minify($css);
* Minify a CSS string
*
* @param string $css Original CSS
* @return string Minified CSS
protected function minify($css)
$css = trim($css, " \n\t;");
$css = preg_replace('(([:;])\\s+)', '$1', $css);
$css = preg_replace('(#([0-9a-f])\\1([0-9a-f])\\2([0-9a-f])\\3)i', '#$1$2$3', $css);
$css = str_replace(':0px', ':0', $css);
return $css;