summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/Storage/Storage.php
blob: c8a07ba0e94f5682ab53fc8138960c98d9f0f2e2 (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
<?php

namespace Icinga\Module\Businessprocess\Storage;

use Icinga\Application\Config;
use Icinga\Data\ConfigObject;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Metadata;

abstract class Storage
{
    /**
     * @var static
     */
    protected static $instance;

    /**
     * @var ConfigObject
     */
    protected $config;

    /**
     * Storage constructor.
     * @param ConfigObject $config
     */
    public function __construct(ConfigObject $config)
    {
        $this->config = $config;
        $this->init();
    }

    protected function init()
    {
    }

    public static function getInstance()
    {
        if (static::$instance === null) {
            static::$instance = new static(Config::module('businessprocess')->getSection('global'));
        }

        return static::$instance;
    }

    /**
     * All processes readable by the current user
     *
     * The returned array has the form <process name> => <nice title>, sorted
     * by title
     *
     * @return array
     */
    abstract public function listProcesses();

    /**
     * All process names readable by the current user
     *
     * The returned array has the form <process name> => <process name> and is
     * sorted
     *
     * @return array
     */
    abstract public function listProcessNames();

    /**
     * All available process names, regardless of eventual restrictions
     *
     * @return array
     */
    abstract public function listAllProcessNames();

    /**
     * Whether a configuration with the given name exists
     *
     * @param $name
     *
     * @return bool
     */
    abstract public function hasProcess($name);

    /**
     * @param $name
     * @return BpConfig
     */
    abstract public function loadProcess($name);

    /**
     * Store eventual changes applied to the given configuration
     *
     * @param BpConfig $config
     *
     * @return mixed
     */
    abstract public function storeProcess(BpConfig $config);

    /**
     * @param $name
     * @return bool Whether the process has been deleted
     */
    abstract public function deleteProcess($name);

    /**
     * @param  string $name
     * @return Metadata
     */
    abstract public function loadMetadata($name);
}