2014-04-02 17:30:58 +00:00
|
|
|
<?php
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
###
|
|
|
|
# @name Plugins Module
|
|
|
|
# @author Tobias Reich
|
|
|
|
# @copyright 2014 by Tobias Reich
|
|
|
|
###
|
2014-04-02 17:30:58 +00:00
|
|
|
|
|
|
|
class Plugins implements \SplSubject {
|
|
|
|
|
|
|
|
private $files = array();
|
|
|
|
private $observers = array();
|
|
|
|
|
|
|
|
public $action = null;
|
|
|
|
public $args = null;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
public function __construct($files, $database) {
|
2014-04-02 17:30:58 +00:00
|
|
|
|
|
|
|
if (!isset($files)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Init vars
|
|
|
|
$plugins = $this;
|
|
|
|
$this->files = $files;
|
2014-04-02 17:30:58 +00:00
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Load plugins
|
2014-04-02 17:30:58 +00:00
|
|
|
foreach ($this->files as $file) {
|
|
|
|
if ($file==='') continue;
|
2014-04-09 18:28:59 +00:00
|
|
|
include(__DIR__ . '/../../plugins/' . $file);
|
2014-04-02 17:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attach(\SplObserver $observer) {
|
|
|
|
|
|
|
|
if (!isset($observer)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Add observer
|
2014-04-02 17:30:58 +00:00
|
|
|
$this->observers[] = $observer;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function detach(\SplObserver $observer) {
|
|
|
|
|
|
|
|
if (!isset($observer)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Remove observer
|
2014-04-02 17:30:58 +00:00
|
|
|
$key = array_search($observer, $this->observers, true);
|
|
|
|
if ($key) unset($this->observers[$key]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notify() {
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Notify each observer
|
2014-04-02 17:30:58 +00:00
|
|
|
foreach ($this->observers as $value) $value->update($this);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function activate($action, $args) {
|
|
|
|
|
|
|
|
if (!isset($action, $args)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Save vars
|
2014-04-02 17:30:58 +00:00
|
|
|
$this->action = $action;
|
|
|
|
$this->args = $args;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Notify observers
|
2014-04-02 17:30:58 +00:00
|
|
|
$this->notify();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|