PropertyModifier: added split and join

This commit is contained in:
Thomas Gelf 2016-03-10 14:19:52 +01:00
parent 012a2bb577
commit 32124bbba9
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierJoin extends PropertyModifierHook
{
public static function addSettingsFormFields(QuickForm $form)
{
$form->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);
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierSplit extends PropertyModifierHook
{
public static function addSettingsFormFields(QuickForm $form)
{
$form->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
);
}
}

View File

@ -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');