aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/Util.php24
-rw-r--r--lib/public/WorkflowEngine/IOperation.php3
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/public/Util.php b/lib/public/Util.php
index 5165846707a..103b65fe874 100644
--- a/lib/public/Util.php
+++ b/lib/public/Util.php
@@ -513,4 +513,28 @@ class Util {
}
return self::$needUpgradeCache;
}
+
+ /**
+ * Sometimes a string has to be shortened to fit within a certain maximum
+ * data length in bytes. substr() you may break multibyte characters,
+ * because it operates on single byte level. mb_substr() operates on
+ * characters, so does not ensure that the shortend string satisfies the
+ * max length in bytes.
+ *
+ * For example, json_encode is messing with multibyte characters a lot,
+ * replacing them with something along "\u1234".
+ *
+ * This function shortens the string with by $accurancy (-5) from
+ * $dataLength characters, until it fits within $dataLength bytes.
+ *
+ * @since 23.0.0
+ */
+ public static function shortenMultibyteString(string $subject, int $dataLength, int $accuracy = 5): string {
+ $temp = mb_substr($subject, 0, $dataLength);
+ // json encodes encapsulates the string in double quotes, they need to be substracted
+ while ((strlen(json_encode($temp)) - 2) > $dataLength) {
+ $temp = mb_substr($temp, 0, -$accuracy);
+ }
+ return $temp;
+ }
}
diff --git a/lib/public/WorkflowEngine/IOperation.php b/lib/public/WorkflowEngine/IOperation.php
index 3ef810438e0..42aa93140f8 100644
--- a/lib/public/WorkflowEngine/IOperation.php
+++ b/lib/public/WorkflowEngine/IOperation.php
@@ -73,6 +73,9 @@ interface IOperation {
* user scope is permitted, the default behaviour should return `true`,
* otherwise `false`.
*
+ * @param int $scope
+ * @psalm-param IManager::SCOPE_* $scope
+ *
* @since 18.0.0
*/
public function isAvailableForScope(int $scope): bool;