Completed
Push — feature/improve-form-definitio... ( a3c595...bf8e8a )
by Romain
02:54
created

LayoutGroup::__construct()   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 1
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\Layouts;
15
16
use Romm\Formz\Configuration\AbstractConfiguration;
17
use Romm\Formz\Exceptions\EntryNotFoundException;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20
class LayoutGroup extends AbstractConfiguration
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $name;
26
27
    /**
28
     * @var \Romm\Formz\Configuration\View\Layouts\Layout[]
29
     */
30
    protected $items = [];
31
32
    /**
33
     * @var string
34
     * @validate NotEmpty
35
     */
36
    protected $templateFile;
37
38
    /**
39
     * @param string $name
40
     */
41
    public function __construct($name)
42
    {
43
        $this->name = $name;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getName()
50
    {
51
        return $this->name;
52
    }
53
54
    /**
55
     * @return Layout[]
56
     */
57
    public function getItems()
58
    {
59
        return $this->items;
60
    }
61
62
    /**
63
     * @param string $name
64
     * @return bool
65
     */
66
    public function hasItem($name)
67
    {
68
        return true === isset($this->items[$name]);
69
    }
70
71
    /**
72
     * @param string $name
73
     * @return Layout
74
     * @throws EntryNotFoundException
75
     */
76
    public function getItem($name)
77
    {
78
        if (false === $this->hasItem($name)) {
79
            throw EntryNotFoundException::viewLayoutItemNotFound($name);
80
        }
81
82
        return $this->items[$name];
83
    }
84
85
    /**
86
     * @param string $name
87
     * @return Layout
88
     */
89
    public function addItem($name)
90
    {
91
        if ($this->hasItem($name)) {
92
            throw new \Exception('todo'); // @todo
93
        }
94
95
        /** @var Layout $layout */
96
        $layout = GeneralUtility::makeInstance(Layout::class);
97
        $layout->attachParent($this);
0 ignored issues
show
Documentation Bug introduced by
The method attachParent does not exist on object<Romm\Formz\Config...on\View\Layouts\Layout>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
98
99
        $this->items[$name] = $layout;
100
101
        return $layout;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getTemplateFile()
108
    {
109
        return $this->templateFile;
110
    }
111
112
    /**
113
     * @param string $templateFile
114
     */
115
    public function setTemplateFile($templateFile)
116
    {
117
        $this->templateFile = $templateFile;
118
    }
119
}
120