summaryrefslogtreecommitdiffstats
path: root/library/Icinga/Application/Hook/Ticket/TicketPattern.php
blob: e37fcc1f8712003b257a82a7a6f038761ec6d1e3 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */

namespace Icinga\Application\Hook\Ticket;

use ArrayAccess;

/**
 * A ticket pattern
 *
 * This class should be used by modules which provide implementations for the Web 2 ticket hook.
 * Have a look at the GenericTTS module for a possible use case.
 */
class TicketPattern implements ArrayAccess
{
    /**
     * The result of a performed ticket match
     *
     * @var array
     */
    protected $match = array();

    /**
     * The name of the TTS integration
     *
     * @var string
     */
    protected $name;

    /**
     * The ticket pattern
     *
     * @var string
     */
    protected $pattern;

    public function offsetExists($offset): bool
    {
        return isset($this->match[$offset]);
    }

    public function offsetGet($offset): ?string
    {
        return array_key_exists($offset, $this->match) ? $this->match[$offset] : null;
    }

    public function offsetSet($offset, $value): void
    {
        if ($offset === null) {
            $this->match[] = $value;
        } else {
            $this->match[$offset] = $value;
        }
    }

    public function offsetUnset($offset): void
    {
        unset($this->match[$offset]);
    }


    /**
     * Get the result of a performed ticket match
     *
     * @return  array
     */
    public function getMatch()
    {
        return $this->match;
    }

    /**
     * Set the result of a performed ticket match
     *
     * @param   array   $match
     *
     * @return  $this
     */
    public function setMatch(array $match)
    {
        $this->match = $match;
        return $this;
    }

    /**
     * Get the name of the TTS integration
     *
     * @return  string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set the name of the TTS integration
     *
     * @param   string  $name
     *
     * @return  $this
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * Get the ticket pattern
     *
     * @return  string
     */
    public function getPattern()
    {
        return $this->pattern;
    }

    /**
     * Set the ticket pattern
     *
     * @param   string  $pattern
     *
     * @return  $this
     */
    public function setPattern($pattern)
    {
        $this->pattern = $pattern;
        return $this;
    }

    /**
     * Whether the integration is properly configured, i.e. the pattern and the URL are not empty
     *
     * @return bool
     */
    public function isValid()
    {
        return ! empty($this->pattern);
    }
}