summaryrefslogtreecommitdiff
path: root/app/Core/Helper.php
blob: e6152127711551fdb056d1f8e4c4cd728a4c2d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php

namespace Kanboard\Core;

use Pimple\Container;

/**
 * Helper base class
 *
 * @package core
 * @author  Frederic Guillot
 *
 * @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
 * @property \Kanboard\Helper\ProjectHeaderHelper     $projectHeader
 */
class Helper
{
    /**
     * Helper instances
     *
     * @access private
     * @var \Pimple\Container
     */
    private $helpers;

    /**
     * Container instance
     *
     * @access private
     * @var \Pimple\Container
     */
    private $container;

    /**
     * Constructor
     *
     * @access public
     * @param  \Pimple\Container   $container
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
        $this->helpers = new Container;
    }

    /**
     * Expose helpers with magic getter
     *
     * @access public
     * @param  string $helper
     * @return mixed
     */
    public function __get($helper)
    {
        return $this->getHelper($helper);
    }

    /**
     * Expose helpers with method
     *
     * @access public
     * @param  string $helper
     * @return mixed
     */
    public function getHelper($helper)
    {
        return $this->helpers[$helper];
    }

    /**
     * Register a new Helper
     *
     * @access public
     * @param  string $property
     * @param  string $className
     * @return Helper
     */
    public function register($property, $className)
    {
        $container = $this->container;

        $this->helpers[$property] = function() use($className, $container) {
            return new $className($container);
        };

        return $this;
    }
}