2015-07-23 08:29:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\PropertyModifier;
|
|
|
|
|
|
2016-02-17 05:11:05 -05:00
|
|
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
2016-02-18 17:21:28 -05:00
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
2015-07-23 08:29:15 -04:00
|
|
|
|
|
|
|
|
class PropertyModifierStripDomain extends PropertyModifierHook
|
|
|
|
|
{
|
2015-07-23 08:42:53 -04:00
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
|
|
|
{
|
|
|
|
|
$form->addElement('text', 'domain', array(
|
|
|
|
|
'label' => 'Domain name',
|
2016-03-05 18:37:03 -05:00
|
|
|
'description' => $form->translate('The domain name you want to be stripped'),
|
2015-07-23 08:42:53 -04:00
|
|
|
'required' => true,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-05 18:37:03 -05:00
|
|
|
public function getName()
|
|
|
|
|
{
|
|
|
|
|
return 'Strip a domain name';
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 08:29:15 -04:00
|
|
|
public function transform($value)
|
|
|
|
|
{
|
2021-08-12 05:45:40 -04:00
|
|
|
if ($value === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-05 18:37:03 -05:00
|
|
|
$domain = preg_quote(ltrim($this->getSetting('domain'), '.'), '/');
|
|
|
|
|
|
|
|
|
|
return preg_replace(
|
|
|
|
|
'/\.' . $domain . '$/',
|
|
|
|
|
'',
|
|
|
|
|
$value
|
|
|
|
|
);
|
2015-07-23 08:29:15 -04:00
|
|
|
}
|
|
|
|
|
}
|