Completed
Push — unit-test-view-helpers ( 96d65b...71f2bd )
by Romain
03:27
created

SectionService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 46
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addSectionClosure() 0 4 1
A getSectionClosure() 0 6 2
A resetSectionClosures() 0 4 1
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\ViewHelpers\Service;
15
16
use Romm\Formz\Service\Traits\FacadeInstanceTrait;
17
use TYPO3\CMS\Core\SingletonInterface;
18
19
class SectionService implements SingletonInterface
20
{
21
    use FacadeInstanceTrait;
22
23
    /**
24
     * Contains the closures which will render the registered sections. The keys
25
     * of this array are the names of the sections.
26
     *
27
     * @var callable[]
28
     */
29
    private $sections = [];
30
    
31
    /**
32
     * Adds a closure - which will render the section with the given name - to
33
     * the private storage in this class.
34
     *
35
     * @param string   $name
36
     * @param callable $closure
37
     */
38
    public function addSectionClosure($name, $closure)
39
    {
40
        $this->sections[$name] = $closure;
41
    }
42
43
    /**
44
     * Returns the closure which will render the section with the given name. If
45
     * nothing is found, `null` is returned.
46
     *
47
     * @param string $name
48
     * @return callable|null
49
     */
50
    public function getSectionClosure($name)
51
    {
52
        return (true === isset($this->sections[$name]))
53
            ? $this->sections[$name]
54
            : null;
55
    }
56
57
    /**
58
     * Resets the list of closures.
59
     */
60
    public function resetSectionClosures()
61
    {
62
        $this->sections = [];
63
    }
64
}
65