diff --git a/library/Director/PropertyModifier/PropertyModifierJoin.php b/library/Director/PropertyModifier/PropertyModifierJoin.php new file mode 100644 index 00000000..771b7e63 --- /dev/null +++ b/library/Director/PropertyModifier/PropertyModifierJoin.php @@ -0,0 +1,29 @@ +addElement('text', 'glue', array( + 'label' => $form->translate('Glue'), + 'required' => false, + 'description' => $form->translate( + 'One or more characters that will be used to glue an input array to a string. Can be left empty' + ) + )); + } + + public function transform($value) + { + if ($value === null) { + return null; + } + + return implode($this->getSetting('glue'), $value); + } +} diff --git a/library/Director/PropertyModifier/PropertyModifierSplit.php b/library/Director/PropertyModifier/PropertyModifierSplit.php new file mode 100644 index 00000000..e3f78bc3 --- /dev/null +++ b/library/Director/PropertyModifier/PropertyModifierSplit.php @@ -0,0 +1,30 @@ +addElement('text', 'delimiter', array( + 'label' => $form->translate('Delimiter'), + 'required' => true, + 'description' => $form->translate( + 'One or more characters that should be used to split this string' + ) + )); + } + + public function transform($value) + { + return preg_split( + '/' . preg_quote($this->getSetting('delimiter'), '/') . '/', + $value, + -1, + PREG_SPLIT_NO_EMPTY + ); + } +} diff --git a/run.php b/run.php index e58e842a..17887809 100644 --- a/run.php +++ b/run.php @@ -23,5 +23,7 @@ $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\Pro $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierSubstring'); $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierUppercase'); $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierMap'); +$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierSplit'); +$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierJoin'); $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierGetHostByName'); $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierExtractFromDN');