PluginManager.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * The PluginManager class is used alongside PluginObserver to implement
  5. * the Observer Design Pattern.
  6. *
  7. * @package PhpMyAdmin
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /**
  13. * This class implements the SplSubject interface
  14. *
  15. * @todo implement all methods
  16. * @package PhpMyAdmin
  17. * @link http://php.net/manual/en/class.splsubject.php
  18. *
  19. */
  20. class PluginManager implements SplSubject
  21. {
  22. /**
  23. * Contains a list with all the plugins that attach to it
  24. *
  25. * @var type SplObjectStorage
  26. */
  27. private $_storage;
  28. /**
  29. * Contains information about the current plugin state
  30. *
  31. * @var type string
  32. */
  33. private $_status;
  34. /**
  35. * Constructor
  36. * Initializes $_storage with an empty SplObjectStorage
  37. */
  38. public function __construct()
  39. {
  40. $this->_storage = new SplObjectStorage();
  41. }
  42. /**
  43. * Attaches an SplObserver so that it can be notified of updates
  44. *
  45. * @param SplObserver $observer The SplObserver to attach
  46. *
  47. * @return void
  48. */
  49. function attach (SplObserver $observer )
  50. {
  51. $this->_storage->attach($observer);
  52. }
  53. /**
  54. * Detaches an observer from the subject to no longer notify it of updates
  55. *
  56. * @param SplObserver $observer The SplObserver to detach
  57. *
  58. * @return void
  59. */
  60. function detach (SplObserver $observer)
  61. {
  62. $this->_storage->detach($observer);
  63. }
  64. /**
  65. * It is called after setStatus() was run by a certain plugin, and has
  66. * the role of sending a notification to all of the plugins in $_storage,
  67. * by calling the update() method for each of them.
  68. *
  69. * @todo implement
  70. * @return void
  71. */
  72. function notify ()
  73. {
  74. }
  75. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  76. /**
  77. * Gets the list with all the plugins that attach to it
  78. *
  79. * @return type SplObjectStorage
  80. */
  81. public function getStorage()
  82. {
  83. return $this->_storage;
  84. }
  85. /**
  86. * Setter for $_storage
  87. *
  88. * @param SplObjectStorage $_storage the list with all the plugins that
  89. * attach to it
  90. *
  91. * @return void
  92. */
  93. public function setStorage($_storage)
  94. {
  95. $this->_storage = $_storage;
  96. }
  97. /**
  98. * Gets the information about the current plugin state
  99. * It is called by all the plugins in $_storage in their update() method
  100. *
  101. * @return type mixed
  102. */
  103. public function getStatus()
  104. {
  105. return $this->_status;
  106. }
  107. /**
  108. * Setter for $_status
  109. * If a plugin changes its status, this has to be remembered in order to
  110. * notify the rest of the plugins that they should update
  111. *
  112. * @param mixed $_status contains information about the current plugin state
  113. *
  114. * @return void
  115. */
  116. public function setStatus($_status)
  117. {
  118. $this->_status = $_status;
  119. }
  120. }
  121. ?>