summaryrefslogtreecommitdiff
path: root/app/Core
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-09-20 15:53:28 -0400
committerFrederic Guillot <fred@kanboard.net>2015-09-20 15:53:28 -0400
commit2021dccc5a444f60c5ba1673d94b39999912cd26 (patch)
tree5d805496f001456baa83c0776a32bdb24511511b /app/Core
parenta0124b45f9dab8a0f7d4879d4ea147b414b25bf2 (diff)
Move subtask forecast to a plugin
Plugin repo: https://github.com/kanboard/plugin-subtask-forecast
Diffstat (limited to 'app/Core')
-rw-r--r--app/Core/Base.php1
-rw-r--r--app/Core/Plugin/Hook.php70
2 files changed, 70 insertions, 1 deletions
diff --git a/app/Core/Base.php b/app/Core/Base.php
index 5ed8f40a..2dec4b29 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -55,7 +55,6 @@ use Pimple\Container;
* @property \Model\ProjectPermission $projectPermission
* @property \Model\Subtask $subtask
* @property \Model\SubtaskExport $subtaskExport
- * @property \Model\SubtaskForecast $subtaskForecast
* @property \Model\SubtaskTimeTracking $subtaskTimeTracking
* @property \Model\Swimlane $swimlane
* @property \Model\Task $task
diff --git a/app/Core/Plugin/Hook.php b/app/Core/Plugin/Hook.php
new file mode 100644
index 00000000..4fb55569
--- /dev/null
+++ b/app/Core/Plugin/Hook.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace Core\Plugin;
+
+/**
+ * Plugin Hooks Handler
+ *
+ * @package plugin
+ * @author Frederic Guillot
+ */
+class Hook
+{
+ /**
+ * List of hooks
+ *
+ * @access private
+ * @var array
+ */
+ private $hooks = array();
+
+ /**
+ * Bind something on a hook
+ *
+ * @access public
+ * @param string $hook
+ * @param mixed $value
+ */
+ public function on($hook, $value)
+ {
+ if (! isset($this->hooks[$hook])) {
+ $this->hooks[$hook] = array();
+ }
+
+ $this->hooks[$hook][] = $value;
+ }
+
+ /**
+ * Get all bindings for a hook
+ *
+ * @access public
+ * @param string $hook
+ * @return array
+ */
+ public function getListeners($hook)
+ {
+ return isset($this->hooks[$hook]) ? $this->hooks[$hook] : array();
+ }
+
+ /**
+ * Merge listener results with input array
+ *
+ * @access public
+ * @param string $hook
+ * @param array $values
+ * @param array $params
+ * @return array
+ */
+ public function merge($hook, array &$values, array $params = array())
+ {
+ foreach ($this->getListeners($hook) as $listener) {
+ $result = call_user_func_array($listener, $params);
+
+ if (is_array($result) && ! empty($result)) {
+ $values = array_merge($values, $result);
+ }
+ }
+
+ return $values;
+ }
+}