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 class PropertyModifierLowercase extends PropertyModifierHook
{ {
public function transform($value) public function transform($value)
{ {
return strtolower($value); return strtolower($value);
} }
} }

View File

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

View File

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

View File

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

View File

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