ViewFactory::displayView()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * @package    EBloodBank
4
 * @subpackage Views
5
 * @since      1.6
6
 */
7
namespace EBloodBank\Views;
8
9
use EBloodBank\Traits\AclTrait;
10
use Psr\Container\ContainerInterface;
11
12
/**
13
 * @since 1.6
14
 */
15
class ViewFactory
16
{
17
    use AclTrait;
18
19
    /**
20
     * @var   array
21
     * @since 1.6
22
     */
23
    protected $data = [];
24
25
    /**
26
     * @since 1.6
27
     */
28
    public function __construct(ContainerInterface $container)
29
    {
30
        $this->setAcl($container->get('acl'));
31
    }
32
33
    /**
34
     * @return \EBloodBank\Views\View
35
     * @since  1.6
36
     */
37
    public function forgeView(string $name, array $data = [])
38
    {
39
        $data = array_merge($this->getAllData(), $data);
40
        $view = new View($name, $data);
41
        $view->setAcl($this->getAcl());
42
43
        return $view;
44
    }
45
46
    /**
47
     * @return void
48
     * @since  1.6
49
     */
50
    public function displayView(string $name, array $data = [])
51
    {
52
        $view = $this->forgeView($name, $data);
53
        $view();
54
    }
55
56
    /**
57
     * @return void
58
     * @since 1.0
59
     */
60
    public function setData(string $key, $value)
61
    {
62
        $this->data[$key] = $value;
63
    }
64
65
    /**
66
     * @return mixed
67
     * @since 1.6
68
     */
69
    public function getData(string $key)
70
    {
71
        return $this->data[$key];
72
    }
73
74
    /**
75
     * @return array
76
     * @since 1.6
77
     */
78
    public function getAllData()
79
    {
80
        return $this->data;
81
    }
82
}
83