summaryrefslogtreecommitdiff
path: root/app/Core/Helper.php
blob: 759209f61f23d370c593399512e0e5cfe0c2509a (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
<?php

namespace Kanboard\Core;

use Pimple\Container;

/**
 * Helper base class
 *
 * @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
 */
class Helper
{
    /**
     * Helper instances
     *
     * @access private
     * @var array
     */
    private $helpers = array();

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

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

    /**
     * Load automatically helpers
     *
     * @access public
     * @param  string    $name    Helper name
     * @return mixed
     */
    public function __get($name)
    {
        if (! isset($this->helpers[$name])) {
            $class = '\Kanboard\Helper\\'.ucfirst($name);
            $this->helpers[$name] = new $class($this->container);
        }

        return $this->helpers[$name];
    }

    /**
     * HTML escaping
     *
     * @param  string   $value    Value to escape
     * @return string
     */
    public function e($value)
    {
        return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
    }
}