Completed
Push — master ( bd4c23...b341c0 )
by Filipe
10:29
created

Controller::getRouteAttributes()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 6
nop 2
crap 4
1
<?php
2
3
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc;
11
12
use Slick\Mvc\Controller\ControllerContextInterface;
13
14
/**
15
 * Controller
16
 *
17
 * @package Slick\Mvc
18
 * @author  Filipe Silva <[email protected]>
19
 */
20
abstract class Controller implements ControllerInterface
21
{
22
23
    /**
24
     * @var ControllerContextInterface
25
     */
26
    protected $context;
27
28
    /**
29
     * @var array
30
     */
31
    private $viewData = [];
32
33
    /**
34
     * Sets te context for this controller execution
35
     *
36
     * @param ControllerContextInterface $context
37
     *
38
     * @return self|ControllerInterface
39
     */
40
    public function setContext(ControllerContextInterface $context)
41
    {
42
        $this->context = $context;
43
        return $this;
44
    }
45
46
    /**
47
     * Sets a variable to the view data model
48
     *
49
     * If you provide an associative array in the $name argument it will be
50
     * set all the elements using the key as the variable name on view
51
     * data model.
52
     *
53
     * @param string|array $name
54
     * @param mixed$value
55
     *
56 26
     * @return self|ControllerInterface
57
     */
58
    public function set($name, $value = null)
59 26
    {
60 26
        if (is_array($name)) {
61 26
            foreach ($name as $key => $value) {
62
                $this->set($key, $value);
63
            }
64
            return $this;
65
        }
66
67
        $this->viewData[$name] = $value;
68
        return $this;
69 10
    }
70
71 10
    /**
72
     * A view data model used by renderer
73
     *
74
     * @return array
75
     */
76
    public function getViewData()
77
    {
78
        return $this->viewData;
79
    }
80
}