2015-07-23 14:29:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\PropertyModifier;
|
|
|
|
|
2016-02-17 11:11:05 +01:00
|
|
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
2016-02-18 23:21:28 +01:00
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
2015-07-23 14:29:15 +02:00
|
|
|
|
|
|
|
class PropertyModifierRegexReplace extends PropertyModifierHook
|
|
|
|
{
|
2015-07-23 14:42:53 +02:00
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
|
|
{
|
2015-07-23 15:13:07 +02:00
|
|
|
$form->addElement('text', 'pattern', array(
|
2016-03-06 00:37:03 +01:00
|
|
|
'label' => 'Regex pattern',
|
|
|
|
'description' => $form->translate(
|
|
|
|
'The pattern you want to search for. This can be a regular expression like /^www\d+\./'
|
|
|
|
),
|
|
|
|
'required' => true,
|
2015-07-23 14:42:53 +02:00
|
|
|
));
|
2016-02-18 23:21:28 +01:00
|
|
|
|
2015-07-23 15:13:07 +02:00
|
|
|
$form->addElement('text', 'replacement', array(
|
2016-03-06 00:37:03 +01:00
|
|
|
'label' => 'Replacement',
|
|
|
|
'description' => $form->translate(
|
|
|
|
'The string that should be used as a preplacement'
|
|
|
|
),
|
2015-07-23 14:42:53 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2016-03-06 00:37:03 +01:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'Regular expression based replacement';
|
|
|
|
}
|
|
|
|
|
2015-07-23 14:29:15 +02:00
|
|
|
public function transform($value)
|
|
|
|
{
|
2016-03-06 00:37:03 +01:00
|
|
|
return preg_replace(
|
|
|
|
$this->getSetting('pattern'),
|
|
|
|
$this->getSetting('replacement'),
|
|
|
|
$value
|
|
|
|
);
|
2015-07-23 14:29:15 +02:00
|
|
|
}
|
|
|
|
}
|