Completed
Push — bugfix/multiple-fields-level ( 9f970c )
by Romain
02:59
created

SlotViewHelperService::resetState()   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 0
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\Service\ViewHelper\Slot;
15
16
use Closure;
17
use Romm\Formz\Exceptions\EntryNotFoundException;
18
use TYPO3\CMS\Core\SingletonInterface;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
21
22
class SlotViewHelperService implements SingletonInterface
23
{
24
    /**
25
     * @var SlotContextEntry[]
26
     */
27
    protected $contextEntries = [];
28
29
    /**
30
     * @todo
31
     *
32
     * @param RenderingContextInterface $renderingContext
33
     */
34
    public function initialize(RenderingContextInterface $renderingContext)
35
    {
36
        $this->contextEntries[] = GeneralUtility::makeInstance(SlotContextEntry::class, $renderingContext);
37
    }
38
39
    /**
40
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::addSlot()
41
     *
42
     * @param string  $name
43
     * @param Closure $closure
44
     * @param array   $arguments
45
     */
46
    public function addSlot($name, Closure $closure, array $arguments)
47
    {
48
        $this->getCurrentContext()->addSlot($name, $closure, $arguments);
49
    }
50
51
    /**
52
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::getSlotClosure()
53
     *
54
     * @param string $name
55
     * @return Closure
56
     * @throws EntryNotFoundException
57
     */
58
    public function getSlotClosure($name)
59
    {
60
        return $this->getCurrentContext()->getSlotClosure($name);
61
    }
62
63
    /**
64
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::getSlotArguments()
65
     *
66
     * @param string $name
67
     * @return array
68
     * @throws EntryNotFoundException
69
     */
70
    public function getSlotArguments($name)
71
    {
72
        return $this->getCurrentContext()->getSlotArguments($name);
73
    }
74
75
    /**
76
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::hasSlot()
77
     *
78
     * @param string $name
79
     * @return bool
80
     */
81
    public function hasSlot($name)
82
    {
83
        return $this->getCurrentContext()->hasSlot($name);
84
    }
85
86
    /**
87
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::addTemplateVariables()
88
     *
89
     * @param string $slotName
90
     * @param array  $arguments
91
     */
92
    public function addTemplateVariables($slotName, array $arguments)
93
    {
94
        $this->getCurrentContext()->addTemplateVariables($slotName, $arguments);
95
    }
96
97
    /**
98
     * @see \Romm\Formz\Service\ViewHelper\Slot\SlotContextEntry::restoreTemplateVariables()
99
     *
100
     * @param string $slotName
101
     */
102
    public function restoreTemplateVariables($slotName)
103
    {
104
        $this->getCurrentContext()->restoreTemplateVariables($slotName);
105
    }
106
107
    /**
108
     * Removes the current context entry.
109
     */
110
    public function resetState()
111
    {
112
        array_pop($this->contextEntries);
113
    }
114
115
    /**
116
     * @return SlotContextEntry
117
     */
118
    protected function getCurrentContext()
119
    {
120
        return end($this->contextEntries);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression end($this->contextEntries); of type Romm\Formz\Service\ViewH...\SlotContextEntry|false adds false to the return on line 120 which is incompatible with the return type documented by Romm\Formz\Service\ViewH...vice::getCurrentContext of type Romm\Formz\Service\ViewH...r\Slot\SlotContextEntry. It seems like you forgot to handle an error condition.
Loading history...
121
    }
122
}
123