From 378881378aab5454c84cb1fecbbcc675f64dc27f Mon Sep 17 00:00:00 2001
From: Laria Carolin Chabowski <laria@laria.me>
Date: Fri, 25 Sep 2020 21:18:18 +0200
Subject: Refactor textprocessors

They are now managed by TextprocessorRepository and are instances of
Textprocessor. This replaces the global $textprocessors variable.
---
 .../sys/textprocessors/LegacyTextprocessor.php     | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 ratatoeskr/sys/textprocessors/LegacyTextprocessor.php

(limited to 'ratatoeskr/sys/textprocessors/LegacyTextprocessor.php')

diff --git a/ratatoeskr/sys/textprocessors/LegacyTextprocessor.php b/ratatoeskr/sys/textprocessors/LegacyTextprocessor.php
new file mode 100644
index 0000000..e7e5cc2
--- /dev/null
+++ b/ratatoeskr/sys/textprocessors/LegacyTextprocessor.php
@@ -0,0 +1,32 @@
+<?php
+
+
+namespace r7r\cms\sys\textprocessors;
+
+/**
+ * LegacyTextprocessor is used to wrap an old-style textprocessor into an Textprocessor object.
+ */
+class LegacyTextprocessor implements Textprocessor
+{
+    /** @var callable */
+    private $fx;
+
+    /** @var bool */
+    private $visible_in_backend;
+
+    public function __construct(callable $fx, $visible_in_backend)
+    {
+        $this->fx = $fx;
+        $this->visible_in_backend = (bool)$visible_in_backend;
+    }
+
+    public function apply(string $input): string
+    {
+        return (string)call_user_func($this->fx, $input);
+    }
+
+    public function showInBackend(): bool
+    {
+        return $this->visible_in_backend;
+    }
+}
-- 
cgit v1.2.3-70-g09d2