From f4a8599193a37beec09dc6b80837aaf2afc2839b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 15 Jan 2021 16:32:06 +0100 Subject: [PATCH] Introduce and utilize class `Icinga\Util\LessParser` --- icingaweb2.ruleset.xml | 1 + library/Icinga/Util/LessParser.php | 38 +++++++++++++++++++++++++++++ library/Icinga/Web/LessCompiler.php | 7 +++--- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 library/Icinga/Util/LessParser.php diff --git a/icingaweb2.ruleset.xml b/icingaweb2.ruleset.xml index 93cb742cc..537a6be9b 100644 --- a/icingaweb2.ruleset.xml +++ b/icingaweb2.ruleset.xml @@ -22,6 +22,7 @@ library/Icinga/Application/LegacyWeb.php library/Icinga/Application/Web.php library/Icinga/File/Pdf.php + library/Icinga/Util/LessParser.php modules/doc/library/Doc/Renderer/DocSectionRenderer.php modules/monitoring/library/Monitoring/Plugin.php diff --git a/library/Icinga/Util/LessParser.php b/library/Icinga/Util/LessParser.php new file mode 100644 index 000000000..84541fd8e --- /dev/null +++ b/library/Icinga/Util/LessParser.php @@ -0,0 +1,38 @@ +getMessage()); + } + + return ['string', '', []]; + } + + protected function compileProp($prop, $block, $out) + { + try { + parent::compileProp($prop, $block, $out); + } catch (Exception $e) { + if (strpos($e->getMessage(), 'is undefined:') === false) { + // We silence mixin errors only + throw $e; + } + + Logger::error($e->getMessage()); + } + } +} diff --git a/library/Icinga/Web/LessCompiler.php b/library/Icinga/Web/LessCompiler.php index 1d9aec05c..55c0614da 100644 --- a/library/Icinga/Web/LessCompiler.php +++ b/library/Icinga/Web/LessCompiler.php @@ -4,7 +4,7 @@ namespace Icinga\Web; use Icinga\Application\Logger; -use lessc; +use Icinga\Util\LessParser; /** * Compile LESS into CSS @@ -16,7 +16,7 @@ class LessCompiler /** * lessphp compiler * - * @var lessc + * @var LessParser */ protected $lessc; @@ -60,8 +60,7 @@ class LessCompiler */ public function __construct() { - require_once 'lessphp/lessc.inc.php'; - $this->lessc = new lessc(); + $this->lessc = new LessParser(); // Discourage usage of import because we're caching based on an explicit list of LESS files to compile $this->lessc->importDisabled = true; }