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\Condition\Parser\Node; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Condition\Items\AbstractConditionItem; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* A condition node, which contains an instance of `AbstractConditionItem`. |
20
|
|
|
*/ |
21
|
|
|
class ConditionNode extends AbstractNode |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $conditionName; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var AbstractConditionItem |
31
|
|
|
*/ |
32
|
|
|
protected $condition; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Contains a list of all condition classes which where used since the |
36
|
|
|
* function `distinctUsedConditions()` was called. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected static $distinctUsedConditions = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor, which needs a name for the condition and an instance of a |
44
|
|
|
* condition item. |
45
|
|
|
* |
46
|
|
|
* @param string $conditionName Name of the condition. |
47
|
|
|
* @param AbstractConditionItem $condition Instance of the condition item. |
48
|
|
|
*/ |
49
|
|
|
public function __construct($conditionName, AbstractConditionItem $condition) |
50
|
|
|
{ |
51
|
|
|
$this->conditionName = $conditionName; |
52
|
|
|
$this->condition = $condition; |
53
|
|
|
|
54
|
|
|
self::$distinctUsedConditions[get_class($condition)] = true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @inheritdoc |
59
|
|
|
*/ |
60
|
|
|
public function getCssResult() |
61
|
|
|
{ |
62
|
|
|
return $this->toArray($this->condition->getCssResult()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritdoc |
67
|
|
|
*/ |
68
|
|
|
public function getJavaScriptResult() |
69
|
|
|
{ |
70
|
|
|
return $this->toArray($this->condition->getJavaScriptResult()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @inheritdoc |
75
|
|
|
*/ |
76
|
|
|
public function getPhpResult() |
77
|
|
|
{ |
78
|
|
|
// /** @var PhpProcessor $processor */ |
79
|
|
|
// $processor = $this->getProcessor(); |
80
|
|
|
$formInstance = $processor->getFormInstance(); |
|
|
|
|
81
|
|
|
$formValidator = $processor->getFormValidator(); |
82
|
|
|
|
83
|
|
|
return $this->condition->getPhpResult($formInstance, $formValidator); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Resets the list of distinct condition classes. Use the function |
88
|
|
|
* `getDistinctUsedConditions()` to get them. |
89
|
|
|
*/ |
90
|
|
|
public static function distinctUsedConditions() |
91
|
|
|
{ |
92
|
|
|
self::$distinctUsedConditions = []; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public static function getDistinctUsedConditions() |
99
|
|
|
{ |
100
|
|
|
return array_keys(self::$distinctUsedConditions); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.