File: PluginManager.class.php

package info (click to toggle)
phpmyadmin 4%3A4.2.12-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 33,240 kB
  • sloc: php: 133,253; sql: 510; sh: 240; makefile: 192; python: 187
file content (132 lines) | stat: -rw-r--r-- 3,006 bytes parent folder | download | duplicates (2)
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
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * The PluginManager class is used alongside PluginObserver to implement
 * the Observer Design Pattern.
 *
 * @package PhpMyAdmin
 */
if (! defined('PHPMYADMIN')) {
    exit;
}

/**
 * This class implements the SplSubject interface
 *
 * @todo    implement all methods
 * @package PhpMyAdmin
 * @link    http://php.net/manual/en/class.splsubject.php
 *
 */
class PluginManager implements SplSubject
{
    /**
     * Contains a list with all the plugins that attach to it
     *
     * @var SplObjectStorage
     */
    private $_storage;

    /**
     * Contains information about the current plugin state
     *
     * @var string
     */
    private $_status;

    /**
     * Constructor
     * Initializes $_storage with an empty SplObjectStorage
     */
    public function __construct()
    {
        $this->_storage = new SplObjectStorage();
    }

    /**
     * Attaches an SplObserver so that it can be notified of updates
     *
     * @param SplObserver $observer The SplObserver to attach
     *
     * @return void
     */
    function attach (SplObserver $observer )
    {
        $this->_storage->attach($observer);
    }

    /**
     * Detaches an observer from the subject to no longer notify it of updates
     *
     * @param SplObserver $observer The SplObserver to detach
     *
     * @return void
     */
    function detach (SplObserver $observer)
    {
         $this->_storage->detach($observer);
    }

    /**
     * It is called after setStatus() was run by a certain plugin, and has
     * the role of sending a notification to all of the plugins in $_storage,
     * by calling the update() method for each of them.
     *
     * @todo implement
     * @return void
     */
    function notify ()
    {
    }

    /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */

    /**
     * Gets the list with all the plugins that attach to it
     *
     * @return SplObjectStorage
     */
    public function getStorage()
    {
        return $this->_storage;
    }

    /**
     * Setter for $_storage
     *
     * @param SplObjectStorage $_storage the list with all the plugins that
     *                                  attach to it
     *
     * @return void
     */
    public function setStorage($_storage)
    {
        $this->_storage = $_storage;
    }

    /**
     * Gets the information about the current plugin state
     * It is called by all the plugins in $_storage in their update() method
     *
     * @return string
     */
    public function getStatus()
    {
        return $this->_status;
    }

    /**
     * Setter for $_status
     * If a plugin changes its status, this has to be remembered in order to
     * notify the rest of the plugins that they should update
     *
     * @param string $_status contains information about the current plugin state
     *
     * @return void
     */
    public function setStatus($_status)
    {
        $this->_status = $_status;
    }
}
?>