File: EventDetailsExtensionHook.php

package info (click to toggle)
icingaweb2 2.12.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,124 kB
  • sloc: php: 73,980; javascript: 5,009; sql: 333; xml: 75; sh: 72; makefile: 5
file content (79 lines) | stat: -rw-r--r-- 1,823 bytes parent folder | download | duplicates (3)
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
<?php
/* Icinga Web 2 | (c) 2017 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Monitoring\Hook;

use Icinga\Application\ClassLoader;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;

/**
 * Base class for hooks extending the event view of monitored objects
 *
 * Extend this class if you want to extend the event view of monitored objects with custom HTML.
 */
abstract class EventDetailsExtensionHook
{
    /**
     * The module of the derived class
     *
     * @var Module
     */
    private $module;

    /**
     * Create a new hook
     *
     * @see init() For hook initialization.
     */
    final public function __construct()
    {
        $this->init();
    }
    /**
     * Overwrite this function for hook initialization, e.g. loading the hook's config
     */
    protected function init()
    {
    }


    /**
     * Shall return valid HTML to include in the detail view
     *
     * @param   object $event     The object to generate HTML for
     *
     * @return  string
     */
    abstract public function getHtmlForEvent($event);

    /**
     * Get the module of the derived class
     *
     * @return Module
     * @throws \Icinga\Exception\ProgrammingError
     */
    public function getModule()
    {
        if ($this->module === null) {
            $class = get_class($this);
            if (ClassLoader::classBelongsToModule($class)) {
                $this->module = Icinga::app()->getModuleManager()->getModule(ClassLoader::extractModuleName($class));
            }
        }
        return $this->module;
    }

    /**
     * Set the module of the derived class
     *
     * @param Module $module
     *
     * @return $this
     */
    public function setModule(Module $module)
    {
        $this->module = $module;
        return $this;
    }
}