Completed
Push — task/configuration-unit-tests ( 23860e...2b8e29 )
by Romain
02:34
created

ViewClass::setItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Configuration\View\Classes;
15
16
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessor;
17
use Romm\ConfigurationObject\Service\Items\DataPreProcessor\DataPreProcessorInterface;
18
use Romm\Formz\Configuration\AbstractFormzConfiguration;
19
use Romm\Formz\Exceptions\EntryNotFoundException;
20
21
class ViewClass extends AbstractFormzConfiguration implements DataPreProcessorInterface
22
{
23
24
    /**
25
     * @var array
26
     */
27
    protected $items = [];
28
29
    /**
30
     * This function is called before the TypoScript data is injected in this
31
     * class. We use it to put all the array data in the key `items`, so it can
32
     * be properly injected in the `$items` property.
33
     *
34
     * @param DataPreProcessor $processor
35
     */
36
    public static function dataPreProcessor(DataPreProcessor $processor)
37
    {
38
        $finalData = [];
39
        $data = $processor->getData();
40
41
        foreach ($data as $key => $value) {
42
            $finalData[$key] = (string)$value;
43
        }
44
45
        $processor->setData(['items' => $finalData]);
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getItems()
52
    {
53
        return $this->items;
54
    }
55
56
    /**
57
     * @param string $name
58
     * @return bool
59
     */
60
    public function hasItem($name)
61
    {
62
        return true === isset($this->items[$name]);
63
    }
64
65
    /**
66
     * @param string $name
67
     * @return array
68
     * @throws EntryNotFoundException
69
     */
70
    public function getItem($name)
71
    {
72
        if (false === $this->hasItem($name)) {
73
            throw EntryNotFoundException::viewClassNotFound($name);
74
        }
75
76
        return $this->items[$name];
77
    }
78
79
    /**
80
     * @param string $name
81
     * @param string $value
82
     */
83
    public function setItem($name, $value)
84
    {
85
        $this->items[$name] = $value;
86
    }
87
}
88