AbstractViewModel::append()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Cqrs\ViewModel;
12
13
use ArrayIterator;
14
use Borobudur\Cqrs\Exception\BadMethodCallException;
15
16
/**
17
 * @author      Iqbal Maulana <[email protected]>
18
 * @created     8/20/15
19
 */
20
abstract class AbstractViewModel implements ViewModelInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getIterator()
26
    {
27
        return new ArrayIterator($this->build());
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function offsetExists($offset)
34
    {
35
        $builds = $this->build();
36
37
        return isset($builds[$offset]);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function offsetGet($offset)
44
    {
45
        $builds = $this->build();
46
47
        if (isset($builds[$offset])) {
48
            return $builds[$offset];
49
        }
50
51
        return null;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function offsetSet($offset, $value)
58
    {
59
        throw BadMethodCallException::immutableViewModel();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function offsetUnset($offset)
66
    {
67
        throw BadMethodCallException::immutableViewModel();
68
    }
69
70
    /**
71
     * Register fields that should be viewed.
72
     *
73
     * @return array|null
74
     */
75
    abstract protected function fields();
76
77
    /**
78
     * Append custom fields.
79
     *
80
     * @return array|null
81
     */
82
    abstract protected function append();
83
84
    /**
85
     * Register hidden fields.
86
     *
87
     * @return array|null
88
     */
89
    abstract protected function hidden();
90
}
91