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 PropertyModifierStripDomain extends PropertyModifierHook
|
|
|
|
{
|
2015-07-23 14:42:53 +02:00
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
|
|
{
|
|
|
|
$form->addElement('text', 'domain', array(
|
|
|
|
'label' => 'Domain name',
|
2016-03-06 00:37:03 +01:00
|
|
|
'description' => $form->translate('The domain name you want to be stripped'),
|
2015-07-23 14:42:53 +02:00
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2016-03-06 00:37:03 +01:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'Strip a domain name';
|
|
|
|
}
|
|
|
|
|
2015-07-23 14:29:15 +02:00
|
|
|
public function transform($value)
|
|
|
|
{
|
2016-03-06 00:37:03 +01:00
|
|
|
$domain = preg_quote(ltrim($this->getSetting('domain'), '.'), '/');
|
|
|
|
|
|
|
|
return preg_replace(
|
|
|
|
'/\.' . $domain . '$/',
|
|
|
|
'',
|
|
|
|
$value
|
|
|
|
);
|
2015-07-23 14:29:15 +02:00
|
|
|
}
|
|
|
|
}
|