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

namespace Core;

use Pimple\Container;

/**
 * Helper base class
 *
 * @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
 */
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 = '\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);
    }
}