summaryrefslogtreecommitdiff
path: root/app/Core/Helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Core/Helper.php')
-rw-r--r--app/Core/Helper.php74
1 files changed, 45 insertions, 29 deletions
diff --git a/app/Core/Helper.php b/app/Core/Helper.php
index 759209f6..3764a67c 100644
--- a/app/Core/Helper.php
+++ b/app/Core/Helper.php
@@ -10,18 +10,18 @@ use Pimple\Container;
* @package core
* @author Frederic Guillot
*
- * @property \Kanboard\Helper\App $app
- * @property \Kanboard\Helper\Asset $asset
- * @property \Kanboard\Helper\Dt $dt
- * @property \Kanboard\Helper\File $file
- * @property \Kanboard\Helper\Form $form
- * @property \Kanboard\Helper\Subtask $subtask
- * @property \Kanboard\Helper\Task $task
- * @property \Kanboard\Helper\Text $text
- * @property \Kanboard\Helper\Url $url
- * @property \Kanboard\Helper\User $user
- * @property \Kanboard\Helper\Layout $layout
- * @property \Kanboard\Helper\Model $model
+ * @property \Kanboard\Helper\AppHelper $app
+ * @property \Kanboard\Helper\AssetHelper $asset
+ * @property \Kanboard\Helper\DateHelper $dt
+ * @property \Kanboard\Helper\FileHelper $file
+ * @property \Kanboard\Helper\FormHelper $form
+ * @property \Kanboard\Helper\ModelHelper $model
+ * @property \Kanboard\Helper\SubtaskHelper $subtask
+ * @property \Kanboard\Helper\TaskHelper $task
+ * @property \Kanboard\Helper\TextHelper $text
+ * @property \Kanboard\Helper\UrlHelper $url
+ * @property \Kanboard\Helper\UserHelper $user
+ * @property \Kanboard\Helper\LayoutHelper $layout
*/
class Helper
{
@@ -29,17 +29,17 @@ class Helper
* Helper instances
*
* @access private
- * @var array
+ * @var \Pimple\Container
*/
- private $helpers = array();
+ private $helpers;
/**
* Container instance
*
- * @access protected
+ * @access private
* @var \Pimple\Container
*/
- protected $container;
+ private $container;
/**
* Constructor
@@ -50,33 +50,49 @@ class Helper
public function __construct(Container $container)
{
$this->container = $container;
+ $this->helpers = new Container;
}
/**
- * Load automatically helpers
+ * Expose helpers with magic getter
*
* @access public
- * @param string $name Helper name
+ * @param string $helper
* @return mixed
*/
- public function __get($name)
+ public function __get($helper)
{
- if (! isset($this->helpers[$name])) {
- $class = '\Kanboard\Helper\\'.ucfirst($name);
- $this->helpers[$name] = new $class($this->container);
- }
+ return $this->getHelper($helper);
+ }
- return $this->helpers[$name];
+ /**
+ * Expose helpers with method
+ *
+ * @access public
+ * @param string $helper
+ * @return mixed
+ */
+ public function getHelper($helper)
+ {
+ return $this->helpers[$helper];
}
/**
- * HTML escaping
+ * Register a new Helper
*
- * @param string $value Value to escape
- * @return string
+ * @access public
+ * @param string $property
+ * @param string $className
+ * @return Helper
*/
- public function e($value)
+ public function register($property, $className)
{
- return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
+ $container = $this->container;
+
+ $this->helpers[$property] = function() use($className, $container) {
+ return new $className($container);
+ };
+
+ return $this;
}
}