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.php72
1 files changed, 45 insertions, 27 deletions
diff --git a/app/Core/Helper.php b/app/Core/Helper.php
index 5edaa3f0..3764a67c 100644
--- a/app/Core/Helper.php
+++ b/app/Core/Helper.php
@@ -10,16 +10,18 @@ use Pimple\Container;
* @package core
* @author Frederic Guillot
*
- * @property \Helper\App $app
- * @property \Helper\Asset $asset
- * @property \Helper\Dt $dt
- * @property \Helper\File $file
- * @property \Helper\Form $form
- * @property \Helper\Subtask $subtask
- * @property \Helper\Task $task
- * @property \Helper\Text $text
- * @property \Helper\Url $url
- * @property \Helper\User $user
+ * @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
{
@@ -27,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
@@ -48,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;
}
}