PropertyModifiers: fix errors, style, logic

This commit is contained in:
Thomas Gelf 2016-02-18 23:21:28 +01:00
parent 81335598a6
commit d34a7dd5aa
6 changed files with 9 additions and 20 deletions

View File

@ -6,10 +6,8 @@ use Icinga\Module\Director\Hook\PropertyModifierHook;
class PropertyModifierLowercase extends PropertyModifierHook
{
public function transform($value)
{
return strtolower($value);
}
}

View File

@ -3,28 +3,25 @@
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierRegexReplace extends PropertyModifierHook
{
public static function addSettingsFormFields(QuickForm $form)
{
$form->addElement('text', 'pattern', array(
'label' => 'Regex pattern',
'required' => true,
));
$form->addElement('text', 'replacement', array(
'label' => 'Replacement',
'required' => true,
));
return $form;
}
public function transform($value)
{
return preg_replace($this->settings['pattern'], $this->settings['replacement'], $value);
}
}

View File

@ -3,26 +3,25 @@
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierReplace PropertyModifierHook
class PropertyModifierReplace extends PropertyModifierHook
{
public static function addSettingsFormFields(QuickForm $form)
{
$form->addElement('text', 'string', array(
'label' => 'Search string',
'required' => true,
));
$form->addElement('text', 'replacement', array(
'label' => 'Replacement',
'required' => true,
));
return $form;
}
public function transform($value)
{
return str_replace($this->settings['string'], $this->settings['replacement'], $value);
}
}

View File

@ -3,23 +3,21 @@
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierStripDomain extends PropertyModifierHook
{
public static function addSettingsFormFields(QuickForm $form)
{
$form->addElement('text', 'domain', array(
'label' => 'Domain name',
'description' => 'Domain to be replaced',
'description' => 'Domain to be replaced',
'required' => true,
));
return $form;
}
public function transform($value)
{
return preg_replace($this->settings['domain'], "", $value);
}
}

View File

@ -3,26 +3,25 @@
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierSubstring extends PropertyModifierHook
{
public static function addSettingsFormFields(QuickForm $form)
{
$form->addElement('text', 'pattern', array(
'label' => 'Regex pattern',
'required' => true,
));
$form->addElement('text', 'replacement', array(
'label' => 'Replacement',
'required' => true,
));
return $form;
}
public function transform($value)
{
return substr($value, $this->settings['start'], $this->settings['end'] - $this->settings['start']);
}
}

View File

@ -6,10 +6,8 @@ use Icinga\Module\Director\Hook\PropertyModifierHook;
class PropertyModifierUppercase extends PropertyModifierHook
{
public function transform($value)
{
return strtoupper($value);
}
}