Plugins.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @name Plugins Module
  4. * @author Tobias Reich
  5. * @copyright 2014 by Tobias Reich
  6. */
  7. class Plugins implements \SplSubject {
  8. private $files = array();
  9. private $observers = array();
  10. public $action = null;
  11. public $args = null;
  12. public function __construct($files) {
  13. if (!isset($files)) return false;
  14. $plugins = $this;
  15. $this->files = $files;
  16. foreach ($this->files as $file) {
  17. if ($file==='') continue;
  18. include('../plugins/' . $file);
  19. }
  20. return true;
  21. }
  22. public function attach(\SplObserver $observer) {
  23. if (!isset($observer)) return false;
  24. $this->observers[] = $observer;
  25. return true;
  26. }
  27. public function detach(\SplObserver $observer) {
  28. if (!isset($observer)) return false;
  29. $key = array_search($observer, $this->observers, true);
  30. if ($key) unset($this->observers[$key]);
  31. return true;
  32. }
  33. public function notify() {
  34. foreach ($this->observers as $value) $value->update($this);
  35. return true;
  36. }
  37. public function activate($action, $args) {
  38. if (!isset($action, $args)) return false;
  39. $this->action = $action;
  40. $this->args = $args;
  41. $this->notify();
  42. return true;
  43. }
  44. }
  45. ?>