Completed
Push — unit-test-form-view-helper ( 0f93da...73a792 )
by Romain
07:03 queued 50s
created

SectionViewHelperService::resetState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * 2016 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;
15
16
use TYPO3\CMS\Core\SingletonInterface;
17
18
class SectionViewHelperService implements SingletonInterface
19
{
20
    /**
21
     * Contains the closures which will render the registered sections. The keys
22
     * of this array are the names of the sections.
23
     *
24
     * @var callable[]
25
     */
26
    private $sections = [];
27
28
    /**
29
     * Adds a closure - which will render the section with the given name - to
30
     * the private storage in this class.
31
     *
32
     * @param string   $name
33
     * @param callable $closure
34
     */
35
    public function addSectionClosure($name, $closure)
36
    {
37
        $this->sections[$name] = $closure;
38
    }
39
40
    /**
41
     * Returns the closure which will render the section with the given name. If
42
     * nothing is found, `null` is returned.
43
     *
44
     * @param string $name
45
     * @return callable|null
46
     */
47
    public function getSectionClosure($name)
48
    {
49
        return (true === isset($this->sections[$name]))
50
            ? $this->sections[$name]
51
            : null;
52
    }
53
54
    /**
55
     * Resets the list of closures.
56
     */
57
    public function resetState()
58
    {
59
        $this->sections = [];
60
    }
61
}
62