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; |
15
|
|
|
|
16
|
|
|
use Closure; |
17
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
18
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
19
|
|
|
|
20
|
|
|
class SlotViewHelperService implements SingletonInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Contains the closures which will render the registered slots. The keys |
24
|
|
|
* of this array are the names of the slots. |
25
|
|
|
* |
26
|
|
|
* @var Closure[] |
27
|
|
|
*/ |
28
|
|
|
private $slots = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Adds a closure - which will render the slot with the given name - to the |
32
|
|
|
* private storage in this class. |
33
|
|
|
* |
34
|
|
|
* @param string $name |
35
|
|
|
* @param Closure $closure |
36
|
|
|
*/ |
37
|
|
|
public function addSlotClosure($name, Closure $closure) |
38
|
|
|
{ |
39
|
|
|
$this->slots[$name] = $closure; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns the closure which will render the slot with the given name. |
44
|
|
|
* |
45
|
|
|
* @param string $name |
46
|
|
|
* @return Closure |
47
|
|
|
* @throws EntryNotFoundException |
48
|
|
|
*/ |
49
|
|
|
public function getSlotClosure($name) |
50
|
|
|
{ |
51
|
|
|
if (false === $this->hasSlotClosure($name)) { |
52
|
|
|
throw EntryNotFoundException::conditionNotFound($name); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $this->slots[$name]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $name |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
public function hasSlotClosure($name) |
63
|
|
|
{ |
64
|
|
|
return true === isset($this->slots[$name]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Resets the list of closures. |
69
|
|
|
*/ |
70
|
|
|
public function resetState() |
71
|
|
|
{ |
72
|
|
|
$this->slots = []; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|