Completed
Push — master ( 40c1d5...c7125f )
by Adam
02:42
created

Row::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Boduch\Grid;
4
5
use Symfony\Component\HttpFoundation\ParameterBag;
6
7
/**
8
 * @property string $class
9
 * @property string $style
10
 */
11
class Row implements \IteratorAggregate
12
{
13
    use AttributesTrait;
14
15
    /**
16
     * @var Grid
17
     */
18
    protected $grid;
19
20
    /**
21
     * @var mixed|null
22
     */
23
    protected $raw;
24
25
    /**
26
     * @var CellInterface[]
27
     */
28
    protected $cells = [];
29
30
    /**
31
     * @param mixed|null $raw
32
     */
33
    public function __construct($raw = null)
34
    {
35
        $this->attributes = new ParameterBag();
36
        $this->raw = $raw;
37
    }
38
39
    /**
40
     * @param Grid $grid
41
     * @return $this
42
     */
43
    public function setGrid($grid)
44
    {
45
        $this->grid = $grid;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return Grid
52
     */
53
    public function getGrid()
54
    {
55
        return $this->grid;
56
    }
57
58
    /**
59
     * @param CellInterface $cell
60
     * @return $this
61
     */
62
    public function addCell(CellInterface $cell)
63
    {
64
        $this->cells[$cell->getColumn()->getName()] = $cell;
65
66
        return $this;
67
    }
68
69
    /**
70
     * @see IteratorAggregate::getIterator()
71
     */
72
    public function getIterator()
73
    {
74
        return new \ArrayIterator($this->cells);
75
    }
76
77
    /**
78
     * Get cell object by name.
79
80
     * @param string $name  Column name
81
     * @return CellInterface|null
82
     */
83
    public function get($name)
84
    {
85
        return $this->cells[$name] ?? null;
86
    }
87
88
    /**
89
     * Get raw row data.
90
     *
91
     * @param string $name
92
     * @return mixed|null
93
     */
94
    public function raw($name)
95
    {
96
        return $this->raw[$name] ?? null;
97
    }
98
99
    /**
100
     * Get cell value.
101
     *
102
     * @param string $name  Column name
103
     * @return mixed
104
     */
105
    public function getValue($name)
106
    {
107
        return $this->cells[$name]->getValue();
108
    }
109
}
110