From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- .../PropertyModifierRegexSplit.php | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 library/Director/PropertyModifier/PropertyModifierRegexSplit.php (limited to 'library/Director/PropertyModifier/PropertyModifierRegexSplit.php') diff --git a/library/Director/PropertyModifier/PropertyModifierRegexSplit.php b/library/Director/PropertyModifier/PropertyModifierRegexSplit.php new file mode 100644 index 0000000..829810f --- /dev/null +++ b/library/Director/PropertyModifier/PropertyModifierRegexSplit.php @@ -0,0 +1,51 @@ +addElement('text', 'pattern', array( + 'label' => $form->translate('Pattern'), + 'required' => true, + 'description' => $form->translate( + 'Regular expression pattern to split the string (e.g. /\s+/ or /[,;]/)' + ) + )); + + $form->addElement('select', 'when_empty', array( + 'label' => $form->translate('When empty'), + 'required' => true, + 'description' => $form->translate( + 'What should happen when the given string is empty?' + ), + 'value' => 'empty_array', + 'multiOptions' => $form->optionalEnum(array( + 'empty_array' => $form->translate('return an empty array'), + 'null' => $form->translate('return NULL'), + )) + )); + } + + public function transform($value) + { + if (! strlen(trim($value))) { + if ($this->getSetting('when_empty', 'empty_array') === 'empty_array') { + return array(); + } else { + return null; + } + } + + return preg_split( + $this->getSetting('pattern'), + $value, + -1, + PREG_SPLIT_NO_EMPTY + ); + } +} -- cgit v1.2.3