span { width: 5px; height: 5px; background-color: #5b5b5b; } EOL; /** @var FeaturesController */ private $featuresController; /** * @param FeaturesController $featuresController */ public function __construct( FeaturesController $featuresController = null ) { if ($featuresController === null) { $featuresController = ContainerWrapper::getInstance()->get(FeaturesController::class); } $this->featuresController = $featuresController; } public function getDefaultStyles() { if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { $textInputWidth = 'width: 100%;'; $labelFontWeight = 'font-weight: normal;'; } else { $textInputWidth = 'width: 200px;'; $labelFontWeight = 'font-weight: bold;'; } $styles = str_replace('[TEXT_INPUTS_WIDTH_RULE]', $textInputWidth, $this->defaultStyles); $styles = str_replace('[LABELS_FONT_WEIGHT_RULE]', $labelFontWeight, $styles); return $styles; } public function render($stylesheet, $prefix = '') { if (!$stylesheet) return; $styles = new CSSParser($stylesheet); $styles = $styles->parse(); $formattedStyles = []; foreach ($styles->getAllDeclarationBlocks() as $styleDeclaration) { $selectors = array_map(function($selector) use ($prefix) { return sprintf('%s %s', $prefix, $selector->__toString()); }, $styleDeclaration->getSelectors()); $selectors = implode(', ', $selectors); $rules = array_map(function($rule) { return $rule->__toString(); }, $styleDeclaration->getRules()); $rules = sprintf('{ %s }', implode(' ', $rules)); $formattedStyles[] = sprintf('%s %s', $selectors, $rules); } return implode(PHP_EOL, $formattedStyles); } }