From 4f2468fc3881ebeefc70e19479606496cec0c6cb Mon Sep 17 00:00:00 2001 From: Busfreak Date: Wed, 23 Mar 2016 18:06:16 +0100 Subject: Loader for Helper-Classes from Plugin --- app/Core/Plugin/Base.php | 11 +++++++++++ app/Core/Plugin/Loader.php | 2 ++ app/Core/Tool.php | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/app/Core/Plugin/Base.php b/app/Core/Plugin/Base.php index 15265370..381b8bb3 100644 --- a/app/Core/Plugin/Base.php +++ b/app/Core/Plugin/Base.php @@ -40,6 +40,17 @@ abstract class Base extends \Kanboard\Core\Base return array(); } + /** + * Returns all helper classes that needs to be stored in the DI container + * + * @access public + * @return array + */ + public function getHelpers() + { + return array(); + } + /** * Listen on internal events * diff --git a/app/Core/Plugin/Loader.php b/app/Core/Plugin/Loader.php index ff4f2c14..775673de 100644 --- a/app/Core/Plugin/Loader.php +++ b/app/Core/Plugin/Loader.php @@ -70,6 +70,8 @@ class Loader extends \Kanboard\Core\Base Tool::buildDic($this->container, $instance->getClasses()); + Tool::buildDICHelpers($this->container, $instance->getHelpers()); + $instance->initialize(); $this->plugins[] = $instance; } diff --git a/app/Core/Tool.php b/app/Core/Tool.php index edd2e609..db2445a1 100644 --- a/app/Core/Tool.php +++ b/app/Core/Tool.php @@ -55,6 +55,27 @@ class Tool return $container; } + /** + * Build dependency injection container for custom helpers from an array + * + * @static + * @access public + * @param Container $container + * @param array $namespaces + * @return Container + */ + public static function buildDICHelpers(Container $container, array $namespaces) + { + foreach ($namespaces as $namespace => $classes) { + foreach ($classes as $name) { + $class = '\\Kanboard\\'.$namespace.'\\'.$name; + $container['helper']->register($name, $class); + } + } + + return $container; + } + /** * Generate a jpeg thumbnail from an image * -- cgit v1.2.3