From 2021dccc5a444f60c5ba1673d94b39999912cd26 Mon Sep 17 00:00:00 2001
From: Frederic Guillot <fred@kanboard.net>
Date: Sun, 20 Sep 2015 15:53:28 -0400
Subject: Move subtask forecast to a plugin

Plugin repo: https://github.com/kanboard/plugin-subtask-forecast
---
 app/Core/Plugin/Hook.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 app/Core/Plugin/Hook.php

(limited to 'app/Core/Plugin/Hook.php')

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;
+    }
+}
-- 
cgit v1.2.3