summaryrefslogtreecommitdiffstats
path: root/library/Director/PropertyModifier/PropertyModifierSkipDuplicates.php
blob: bf9bd313873481ae90a2ef2ff32344b686f340f5 (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
<?php

namespace Icinga\Module\Director\PropertyModifier;

use Icinga\Module\Director\Hook\PropertyModifierHook;

class PropertyModifierSkipDuplicates extends PropertyModifierHook
{
    private $seen = [];

    public function getName()
    {
        return mt('director', 'Skip row if this value appears more than once');
    }

    public function transform($value)
    {
        if (isset($this->seen[$value])) {
            $this->rejectRow();
        }

        $this->seen[$value] = true;

        return $value;
    }
}