blob: e3446f9ddeafde9384953044662fde6fdcd81c1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<?php
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Exception\InvalidPropertyException;
use Icinga\Module\Director\Hook\PropertyModifierHook;
use function array_unique;
use function array_values;
use function is_array;
class PropertyModifierArrayUnique extends PropertyModifierHook
{
public function getName()
{
return 'Unique Array Values';
}
public function hasArraySupport()
{
return true;
}
public function transform($value)
{
if (empty($value)) {
return $value;
}
if (! is_array($value)) {
throw new InvalidPropertyException(
'The ArrayUnique property modifier can be applied to arrays only'
);
}
return array_values(array_unique($value));
}
}
|