Skip to content

Commit 7deef08

Browse files
committed
FormMacros: <tag n:name> always uses getControlPart() and getLabelPart(), removed method_exists checking (BC break)
1 parent a00cf2d commit 7deef08

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

src/Bridges/FormsLatte/FormMacros.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
177177
. '$this->global->formsCurrent[%0.word]; echo $_input->%1.raw'
178178
. ($node->htmlNode->attrs ? '->addAttributes(%2.var)' : '') . '->attributes()',
179179
$name,
180-
$words
181-
? $method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')'
182-
: "{method_exists(\$_input, '{$method}Part')?'{$method}Part':'{$method}'}()",
180+
$method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')',
183181
array_fill_keys(array_keys($node->htmlNode->attrs), NULL)
184182
);
185183
}
@@ -203,7 +201,7 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
203201
$node->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($this->global->formsCurrent, FALSE) ?>';
204202
} elseif ($tagName === 'label') {
205203
if ($node->htmlNode->isEmpty) {
206-
$node->innerContent = "<?php echo \$_input->{method_exists(\$_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?>";
204+
$node->innerContent = "<?php echo \$_input->getLabelPart()->getHtml() ?>";
207205
}
208206
} elseif ($tagName === 'button') {
209207
if ($node->htmlNode->isEmpty) {

tests/Forms.Latte/expected/FormMacros.button.phtml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ class Template%a% extends Latte\Template
1111
), FALSE) ?>>
1212
<button<?php
1313
$_input = $this->global->formsCurrent["send"];
14-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>
14+
echo $_input->getControlPart()->attributes() ?>>
1515
description of button
1616
</button>
1717

1818
<button<?php
1919
$_input = $this->global->formsCurrent["send"];
20-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>></button>
20+
echo $_input->getControlPart()->attributes() ?>></button>
2121

2222
<button<?php
2323
$_input = $this->global->formsCurrent["send"];
24-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>><?php
25-
echo htmlspecialchars($_input->caption) ?></button>
24+
echo $_input->getControlPart()->attributes() ?>><?php echo htmlspecialchars($_input->caption) ?></button>
2625
<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($this->global->formsCurrent, FALSE) ?></form>
2726
<?php
2827
}

tests/Forms.Latte/expected/FormMacros.forms.phtml

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,26 @@ class Template%a% extends Latte\Template
5252

5353
<LABEL title=hello<?php
5454
$_input = $this->global->formsCurrent["username"];
55-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
55+
echo $_input->getLabelPart()->addAttributes(array (
5656
'title' => NULL,
5757
))->attributes() ?>>Name</LABEL>
5858
<input value=val type class="hello"<?php
5959
$_input = $this->global->formsCurrent["username"];
60-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->addAttributes(array (
60+
echo $_input->getControlPart()->addAttributes(array (
6161
'value' => NULL,
6262
'type' => NULL,
6363
'class' => NULL,
6464
))->attributes() ?>>
6565

6666
<label<?php
6767
$_input = is_object($form['username']) ? $form['username'] : $this->global->formsCurrent[$form['username']];
68-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
68+
echo $_input->getLabelPart()->attributes() ?>></label>
6969
<label<?php
7070
$_input = is_object($form['username']) ? $form['username'] : $this->global->formsCurrent[$form['username']];
71-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>><?php
72-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
71+
echo $_input->getLabelPart()->attributes() ?>><?php echo $_input->getLabelPart()->getHtml() ?></label>
7372
<input<?php
7473
$_input = is_object($form['username']) ? $form['username'] : $this->global->formsCurrent[$form['username']];
75-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>
74+
echo $_input->getControlPart()->attributes() ?>>
7675

7776
<?php
7877
if ($_label = $this->global->formsCurrent["my"]->getLabel()) echo $_label;
@@ -110,16 +109,15 @@ class Template%a% extends Latte\Template
110109
}
111110
?><label<?php
112111
$_input = $this->global->formsCurrent["sex"];
113-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
112+
echo $_input->getLabelPart()->attributes() ?>></label>
114113
<label<?php
115114
$_input = $this->global->formsCurrent["sex"];
116-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>><?php
117-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
115+
echo $_input->getLabelPart()->attributes() ?>><?php echo $_input->getLabelPart()->getHtml() ?></label>
118116
<label title="hello"<?php
119117
$_input = $this->global->formsCurrent["sex"];
120-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
118+
echo $_input->getLabelPart()->addAttributes(array (
121119
'title' => NULL,
122-
))->attributes() ?>><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
120+
))->attributes() ?>><?php echo $_input->getLabelPart()->getHtml() ?></label>
123121

124122

125123
<?php if ($_label = $this->global->formsCurrent["checkbox"]->getLabelPart("")) echo $_label->startTag() ?> <?php
@@ -134,19 +132,19 @@ class Template%a% extends Latte\Template
134132
echo $_input->getControlPart("")->attributes() ?>> </label>
135133
<label title=hello<?php
136134
$_input = $this->global->formsCurrent["checkbox"];
137-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
135+
echo $_input->getLabelPart()->addAttributes(array (
138136
'title' => NULL,
139137
))->attributes() ?>> <input<?php
140138
$_input = $this->global->formsCurrent["checkbox"];
141-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>> </label>
139+
echo $_input->getControlPart()->attributes() ?>> </label>
142140
<label<?php
143141
$_input = $this->global->formsCurrent["checkbox"];
144-
echo $_input->getLabelPart("")->attributes() ?>><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
142+
echo $_input->getLabelPart("")->attributes() ?>><?php echo $_input->getLabelPart()->getHtml() ?></label>
145143
<label title=hello<?php
146144
$_input = $this->global->formsCurrent["checkbox"];
147-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
145+
echo $_input->getLabelPart()->addAttributes(array (
148146
'title' => NULL,
149-
))->attributes() ?>><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
147+
))->attributes() ?>><?php echo $_input->getLabelPart()->getHtml() ?></label>
150148

151149

152150
<?php
@@ -171,16 +169,15 @@ class Template%a% extends Latte\Template
171169
}
172170
?><label<?php
173171
$_input = $this->global->formsCurrent["checklist"];
174-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>></label>
172+
echo $_input->getLabelPart()->attributes() ?>></label>
175173
<label<?php
176174
$_input = $this->global->formsCurrent["checklist"];
177-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->attributes() ?>><?php
178-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
175+
echo $_input->getLabelPart()->attributes() ?>><?php echo $_input->getLabelPart()->getHtml() ?></label>
179176
<label title="hello"<?php
180177
$_input = $this->global->formsCurrent["checklist"];
181-
echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->addAttributes(array (
178+
echo $_input->getLabelPart()->addAttributes(array (
182179
'title' => NULL,
183-
))->attributes() ?>><?php echo $_input->{method_exists($_input, 'getLabelPart')?'getLabelPart':'getLabel'}()->getHtml() ?></label>
180+
))->attributes() ?>><?php echo $_input->getLabelPart()->getHtml() ?></label>
184181

185182

186183
<?php
@@ -192,7 +189,7 @@ class Template%a% extends Latte\Template
192189
), FALSE) ?>>
193190
<input<?php
194191
$_input = $this->global->formsCurrent["username"];
195-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>
192+
echo $_input->getControlPart()->attributes() ?>>
196193
<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($this->global->formsCurrent, FALSE) ?></form>
197194
<?php
198195
}
@@ -204,27 +201,25 @@ class Template%a% extends Latte\Template
204201
), FALSE) ?>>
205202
<input<?php
206203
$_input = $this->global->formsCurrent["username"];
207-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>
204+
echo $_input->getControlPart()->attributes() ?>>
208205
<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($this->global->formsCurrent, FALSE) ?></FORM>
209206

210207

211208
<select<?php
212209
$_input = $this->global->formsCurrent["select"];
213-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>><?php
214-
echo $_input->getControl()->getHtml() ?></select>
210+
echo $_input->getControlPart()->attributes() ?>><?php echo $_input->getControl()->getHtml() ?></select>
215211

216212

217213
<textarea title="<?php echo LR\Filters::escapeHtmlAttr(10) ?>"<?php
218214
$_input = $this->global->formsCurrent["area"];
219-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->addAttributes(array (
215+
echo $_input->getControlPart()->addAttributes(array (
220216
'title' => NULL,
221217
))->attributes() ?>><?php echo $_input->getControl()->getHtml() ?></textarea>
222218

223219

224220
<select<?php
225221
$_input = $this->global->formsCurrent["select"];
226-
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>><?php
227-
echo $_input->getControl()->getHtml() ?></select>
222+
echo $_input->getControlPart()->attributes() ?>><?php echo $_input->getControl()->getHtml() ?></select>
228223
<?php
229224
}
230225

0 commit comments

Comments
 (0)