Plugins.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. ###
  3. # @name Plugins Module
  4. # @author Tobias Reich
  5. # @copyright 2014 by Tobias Reich
  6. ###
  7. if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
  8. class Plugins implements \SplSubject {
  9. private $files = array();
  10. private $observers = array();
  11. public $action = null;
  12. public $args = null;
  13. public function __construct($files, $database, $settings) {
  14. if (!isset($files)) return false;
  15. # Init vars
  16. $plugins = $this;
  17. $this->files = $files;
  18. # Load plugins
  19. foreach ($this->files as $file) {
  20. if ($file==='') continue;
  21. include(LYCHEE_PLUGINS . $file);
  22. }
  23. return true;
  24. }
  25. public function attach(\SplObserver $observer) {
  26. if (!isset($observer)) return false;
  27. # Add observer
  28. $this->observers[] = $observer;
  29. return true;
  30. }
  31. public function detach(\SplObserver $observer) {
  32. if (!isset($observer)) return false;
  33. # Remove observer
  34. $key = array_search($observer, $this->observers, true);
  35. if ($key) unset($this->observers[$key]);
  36. return true;
  37. }
  38. public function notify() {
  39. # Notify each observer
  40. foreach ($this->observers as $value) $value->update($this);
  41. return true;
  42. }
  43. public function activate($action, $args) {
  44. if (!isset($action, $args)) return false;
  45. # Save vars
  46. $this->action = $action;
  47. $this->args = $args;
  48. # Notify observers
  49. $this->notify();
  50. return true;
  51. }
  52. }
  53. ?>