mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2026-05-04 17:09:27 -04:00
32 lines
667 B
PHP
32 lines
667 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Icinga\Module\Director\PropertyModifier;
|
||
|
|
|
||
|
|
use Icinga\Module\Director\Data\InvalidDataException;
|
||
|
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
||
|
|
|
||
|
|
class PropertyModifierToString extends PropertyModifierHook
|
||
|
|
{
|
||
|
|
public function getName()
|
||
|
|
{
|
||
|
|
return 'Cast an integer value to a string';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function transform($value)
|
||
|
|
{
|
||
|
|
if ($value === null) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (is_string($value)) {
|
||
|
|
return $value;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (is_int($value)) {
|
||
|
|
return (string) $value;
|
||
|
|
}
|
||
|
|
|
||
|
|
throw new InvalidDataException('String, integer or null', $value);
|
||
|
|
}
|
||
|
|
}
|