diff --git a/.gitattributes b/.gitattributes
index e1bccc4bf..1c022ece0 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,9 +1,10 @@
.gitattributes export-ignore
.github/ export-ignore
.gitignore export-ignore
-ncs.* export-ignore
+dresscode.neon export-ignore
phpstan*.neon export-ignore
tests/ export-ignore
+* text=auto
*.php* diff=php
*.sh text eol=lf
diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml
index a7b9fcc1a..9f9722039 100644
--- a/.github/workflows/coding-style.yml
+++ b/.github/workflows/coding-style.yml
@@ -3,38 +3,39 @@ name: Coding Style
on: [push, pull_request]
jobs:
- nette_cc:
- name: Nette Code Checker
+ dresscode:
+ name: DressCode
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
- php-version: 8.3
+ php-version: 8.4
coverage: none
- - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
- - run: php temp/code-checker/code-checker --strict-types --no-progress --ignore expected --ignore Forms.Latte2
+ - run: composer install --no-progress --prefer-dist
+ - run: composer create-project dresscode/dresscode temp/dresscode ^1.1 --no-progress
+ - run: php temp/dresscode/bin/dresscode check
- nette_cs:
- name: Nette Coding Standard
+ nette_cc:
+ name: Nette Code Checker
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
- php-version: 8.3
+ php-version: 8.4
coverage: none
- - run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress
- - run: php temp/coding-standard/ecs check src tests
+ - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
+ - run: php temp/code-checker/code-checker --strict-types --no-progress --ignore expected --ignore Forms.Latte2
eslint:
name: ESLint
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- run: npm install
- run: npm run lint
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index b5b0dffcd..d2471c593 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -7,10 +7,10 @@ jobs:
name: PHPStan
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
- php-version: 8.2
+ php-version: 8.6
coverage: none
- run: composer install --no-progress --prefer-dist
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index d37351408..9ac74cefa 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -7,13 +7,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- php: ['8.1', '8.2', '8.3', '8.4', '8.5']
+ php: ['8.1', '8.2', '8.3', '8.4', '8.5', '8.6']
fail-fast: false
name: PHP ${{ matrix.php }} tests
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
@@ -22,7 +22,7 @@ jobs:
- run: composer install --no-progress --prefer-dist
- run: composer tester
- if: failure()
- uses: actions/upload-artifact@v4
+ uses: actions/upload-artifact@v7
with:
name: output-${{ matrix.php }}
path: tests/**/output
@@ -32,7 +32,7 @@ jobs:
name: Lowest Dependencies
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
@@ -45,26 +45,26 @@ jobs:
code_coverage:
name: Code Coverage
runs-on: ubuntu-latest
- continue-on-error: true
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- coverage: none
+ coverage: pcov
- run: composer install --no-progress --prefer-dist
- - run: composer tester -- -p phpdbg --coverage ./coverage.xml --coverage-src ./src
- - run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
- - env:
- COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: php php-coveralls.phar --verbose --config tests/.coveralls.yml
+ - run: composer tester -- --coverage ./coverage.xml --coverage-src ./src
+ continue-on-error: true
+ - uses: coverallsapp/github-action@v2
+ with:
+ file: coverage.xml
+ format: clover
jasmine:
name: JavaScript tests
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v6
+ - uses: actions/checkout@v7
- run: npm install
- run: npm run test
diff --git a/composer.json b/composer.json
index fbe5d3edc..2bcd0ffaa 100644
--- a/composer.json
+++ b/composer.json
@@ -1,21 +1,17 @@
{
"name": "nette/forms",
- "description": "📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.",
- "keywords": ["nette", "forms", "validation", "csrf", "javascript", "bootstrap"],
- "homepage": "https://nette.org",
+ "description": "📝 Nette Forms: secure forms with one set of validation rules for server and browser, CSRF protection, and rendering done automatically or by hand in Latte.",
+ "keywords": ["nette", "forms", "form validation", "form builder", "client-side validation", "csrf"],
+ "homepage": "https://doc.nette.org/forms",
"license": ["BSD-3-Clause", "GPL-2.0-only", "GPL-3.0-only"],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
- },
- {
- "name": "Nette Community",
- "homepage": "https://nette.org/contributors"
}
],
"require": {
- "php": "8.1 - 8.5",
+ "php": "8.1 - 8.6",
"nette/component-model": "^3.1",
"nette/http": "^3.3",
"nette/utils": "^4.0.4"
diff --git a/dresscode.neon b/dresscode.neon
new file mode 100644
index 000000000..61da722e7
--- /dev/null
+++ b/dresscode.neon
@@ -0,0 +1,45 @@
+use:
+ - nette
+ - modernizations
+
+typeAnalysis: phpstan
+
+paths:
+ - src
+ - tests
+ - examples
+
+excludePaths:
+ - tests/**/expected
+
+fileExtensions:
+ - php
+ - phpt
+
+imports: {grouping: {class: grouped}}
+
+overrides:
+ -
+ paths: [src]
+ nameResolution: certain
+ use:
+ - compilerOptimizations
+ - deprecations
+ - # the BC branch of the deprecated addProtection() and its message
+ paths: [src/Forms/Form.php, src/Forms/Validator.php]
+ upgrading: {declarations: {deprecatedClass: keep}}
+ - # Form::URL is established public API
+ paths: [src/Forms/Form.php]
+ naming: {constant: keep}
+ - # setValue($values) keeps its name, renaming it breaks named arguments
+ paths: [src/Forms/Controls/MultiChoiceControl.php]
+ classes: {overridingMethod: {parameterName: keep}}
+ - # setDisabled($value) keeps its name, renaming it breaks named arguments
+ paths: [src/Forms/Controls/ChoiceControl.php]
+ classes: {overridingMethod: {parameterName: keep}}
+ - # the parameter names come from the trait of nette/component-model
+ paths: [src/Forms/Container.php]
+ classes: {overridingMethod: {parameterName: keep}}
+ - # the alternative syntax suits PHP inside HTML
+ paths: [examples/manual-rendering.php]
+ braces: {alternativeSyntax: keep}
diff --git a/examples/basic-example.php b/examples/basic-example.php
index 5d3654e77..f60c352a1 100644
--- a/examples/basic-example.php
+++ b/examples/basic-example.php
@@ -5,14 +5,13 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
use Nette\Utils\Html;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
@@ -21,7 +20,10 @@
// group Personal data
$form->addGroup('Personal data')
- ->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.');
+ ->setOption(
+ 'description',
+ 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.',
+ );
$form->addText('name', 'Your name:')
->setRequired('Enter your name');
diff --git a/examples/bootstrap4-rendering.php b/examples/bootstrap4-rendering.php
index a674674a1..c2374b14b 100644
--- a/examples/bootstrap4-rendering.php
+++ b/examples/bootstrap4-rendering.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/bootstrap5-rendering.php b/examples/bootstrap5-rendering.php
index 22065e221..68db86ff0 100644
--- a/examples/bootstrap5-rendering.php
+++ b/examples/bootstrap5-rendering.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/containers.php b/examples/containers.php
index 6537cb6e0..e323d4d60 100644
--- a/examples/containers.php
+++ b/examples/containers.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/custom-control.php b/examples/custom-control.php
index c02fc6960..aa407f339 100644
--- a/examples/custom-control.php
+++ b/examples/custom-control.php
@@ -5,12 +5,11 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
-use Nette\Forms\Form;
-use Nette\Forms\Helpers;
+use Nette\Forms\{Form, Helpers};
use Nette\Utils\Html;
diff --git a/examples/custom-rendering.php b/examples/custom-rendering.php
index 8ae60f8e4..129928c5f 100644
--- a/examples/custom-rendering.php
+++ b/examples/custom-rendering.php
@@ -5,14 +5,13 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
use Nette\Utils\Html;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/custom-validator.php b/examples/custom-validator.php
index d27df2f8d..9af0c1d42 100644
--- a/examples/custom-validator.php
+++ b/examples/custom-validator.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/html5.php b/examples/html5.php
index 2c8f43628..da1f8d0c1 100644
--- a/examples/html5.php
+++ b/examples/html5.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/latte.php b/examples/latte.php
index 256e4e4fd..271679192 100644
--- a/examples/latte.php
+++ b/examples/latte.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/live-validation.php b/examples/live-validation.php
index 8ebd3a518..fb83f41e2 100644
--- a/examples/live-validation.php
+++ b/examples/live-validation.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/localization.php b/examples/localization.php
index 876f64f5c..9523d080f 100644
--- a/examples/localization.php
+++ b/examples/localization.php
@@ -5,14 +5,13 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/examples/manual-rendering.php b/examples/manual-rendering.php
index 6c54f7cfe..28cdd5466 100644
--- a/examples/manual-rendering.php
+++ b/examples/manual-rendering.php
@@ -5,13 +5,12 @@
*/
-if (@!include __DIR__ . '/../vendor/autoload.php') {
+if (@!include __DIR__ . '/../vendor/autoload.php') { // @ dependencies may not be installed
die('Install packages using `composer install`');
}
use Nette\Forms\Form;
-use Tracy\Debugger;
-use Tracy\Dumper;
+use Tracy\{Debugger, Dumper};
Debugger::enable();
diff --git a/phpstan.neon b/phpstan.neon
index 7d9a63e92..9307b6370 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -37,6 +37,15 @@ parameters:
path: src/Forms/Controls/SubmitButton.php
count: 1
+ - # isSameSite() exists on the Nette\Http\Request implementation but the IRequest
+ # interface does not declare it (it is deprecated there in favour of isFrom()).
+ # We deliberately keep calling isSameSite() for compatibility with older nette/http
+ # ^3.3 releases where isFrom() does not yet exist.
+ identifier: method.notFound
+ message: '#^Call to an undefined method Nette\\Http\\IRequest::isSameSite\(\)\.$#'
+ path: src/Forms/Form.php
+ count: 1
+
- # Nette\Forms\Control interface is intentionally minimal and missing common methods
# (getControl, getLabel, getForm, getOption, setOption, getHtmlName, getName, getParent,
# lookupPath, hasErrors, isRequired, isFilled, isDisabled, addError). In practice all
@@ -130,6 +139,7 @@ parameters:
# for better type safety - the contravariance is by design.
identifier: method.childParameterType
message: '#^Parameter \#1 \$value \([^)]+\) of method Nette\\Forms\\Controls\\\w+::setValue\(\) should be contravariant with parameter \$value \(mixed\) of method Nette\\Forms\\(Control|Controls\\BaseControl)::setValue\(\)$#'
+ path: src/Forms/Controls
- # Rules::getCallback() returns callable-array [class, method] without value type.
message: '#^Method Nette\\Forms\\Rules::getCallback\(\) return type has no value type specified in iterable type array\.$#'
@@ -179,9 +189,3 @@ parameters:
identifier: function.alreadyNarrowedType
count: 1
path: src/Forms/Controls/ColorPicker.php
-
- -
- message: '#^Strict comparison using \=\=\= between '''' and '''' will always evaluate to true\.$#'
- identifier: identical.alwaysTrue
- count: 1
- path: src/Forms/Helpers.php
diff --git a/readme.md b/readme.md
index ebcd0fd44..9c61b0ffb 100644
--- a/readme.md
+++ b/readme.md
@@ -44,7 +44,7 @@ The recommended way to install is via Composer:
composer require nette/forms
```
-It requires PHP version 8.1 and supports PHP up to 8.5.
+It requires PHP version 8.1 and supports PHP up to 8.6.
Client-side support can be installed with npm or yarn:
diff --git a/src/Bridges/FormsDI/FormsExtension.php b/src/Bridges/FormsDI/FormsExtension.php
index 95207d0c5..cff15e247 100644
--- a/src/Bridges/FormsDI/FormsExtension.php
+++ b/src/Bridges/FormsDI/FormsExtension.php
@@ -8,7 +8,6 @@
namespace Nette\Bridges\FormsDI;
use Nette;
-use function defined;
/**
diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php
index e7e49825f..cc8bbbfdf 100644
--- a/src/Bridges/FormsLatte/FormMacros.php
+++ b/src/Bridges/FormsLatte/FormMacros.php
@@ -8,10 +8,8 @@
namespace Nette\Bridges\FormsLatte;
use Latte;
-use Latte\CompileException;
-use Latte\MacroNode;
+use Latte\{CompileException, MacroNode, PhpWriter};
use Latte\Macros\MacroSet;
-use Latte\PhpWriter;
/**
@@ -29,9 +27,17 @@ final class FormMacros extends MacroSet
public static function install(Latte\Compiler $compiler): void
{
$me = new static($compiler);
- $me->addMacro('form', [$me, 'macroForm'], 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack));');
+ $me->addMacro(
+ 'form',
+ [$me, 'macroForm'],
+ 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack));',
+ );
$me->addMacro('formContext', [$me, 'macroFormContext'], 'array_pop($this->global->formsStack);');
- $me->addMacro('formContainer', [$me, 'macroFormContainer'], 'array_pop($this->global->formsStack); $formContainer = end($this->global->formsStack)');
+ $me->addMacro(
+ 'formContainer',
+ [$me, 'macroFormContainer'],
+ 'array_pop($this->global->formsStack); $formContainer = end($this->global->formsStack)',
+ );
$me->addMacro('label', [$me, 'macroLabel'], [$me, 'macroLabelEnd'], null, self::AUTO_EMPTY);
$me->addMacro('input', [$me, 'macroInput']);
$me->addMacro('name', [$me, 'macroName'], [$me, 'macroNameEnd'], [$me, 'macroNameAttr']);
@@ -58,7 +64,7 @@ public function macroForm(MacroNode $node, PhpWriter $writer)
}
$name = $node->tokenizer->fetchWord();
- if ($name == null) { // null or false
+ if ($name == null) { // intentionally ==, null or false
throw new CompileException('Missing form name in ' . $node->getNotation());
}
@@ -91,7 +97,7 @@ public function macroFormContext(MacroNode $node, PhpWriter $writer)
}
$name = $node->tokenizer->fetchWord();
- if ($name == null) { // null or false
+ if ($name == null) { // intentionally ==, null or false
throw new CompileException('Missing form name in ' . $node->getNotation());
}
@@ -116,7 +122,7 @@ public function macroFormContainer(MacroNode $node, PhpWriter $writer)
}
$name = $node->tokenizer->fetchWord();
- if ($name == null) { // null or false
+ if ($name == null) { // intentionally ==, null or false
throw new CompileException('Missing name in ' . $node->getNotation());
}
@@ -165,7 +171,7 @@ public function macroLabel(MacroNode $node, PhpWriter $writer)
*/
public function macroLabelEnd(MacroNode $node, PhpWriter $writer)
{
- if ($node->content != null) {
+ if ($node->content != null) { // intentionally !=
$node->openingCode = rtrim($node->openingCode, '?> ') . '->startTag() ?>';
return $writer->write('if ($ʟ_label) echo $ʟ_label->endTag()');
}
@@ -314,7 +320,7 @@ public function macroInputError(MacroNode $node, PhpWriter $writer)
public function macroFormPrint(MacroNode $node, PhpWriter $writer)
{
$name = $node->tokenizer->fetchWord();
- if ($name == null) { // null or false
+ if ($name == null) { // intentionally ==, null or false
throw new CompileException('Missing form name in ' . $node->getNotation());
}
diff --git a/src/Bridges/FormsLatte/FormsExtension.php b/src/Bridges/FormsLatte/FormsExtension.php
index d3fd98d17..50a5f5dc4 100644
--- a/src/Bridges/FormsLatte/FormsExtension.php
+++ b/src/Bridges/FormsLatte/FormsExtension.php
@@ -8,7 +8,6 @@
namespace Nette\Bridges\FormsLatte;
use Latte;
-use function strtolower;
/**
diff --git a/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php b/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php
index 90b8ac8a9..18ec02ae1 100644
--- a/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php
+++ b/src/Bridges/FormsLatte/Nodes/FieldNNameNode.php
@@ -7,18 +7,11 @@
namespace Nette\Bridges\FormsLatte\Nodes;
-use Latte\Compiler\Nodes\AreaNode;
-use Latte\Compiler\Nodes\AuxiliaryNode;
-use Latte\Compiler\Nodes\Html\AttributeNode;
-use Latte\Compiler\Nodes\Html\ElementNode;
-use Latte\Compiler\Nodes\Html\ExpressionAttributeNode;
-use Latte\Compiler\Nodes\NopNode;
+use Latte\Compiler\Nodes\{AreaNode, AuxiliaryNode, NopNode, StatementNode, TextNode};
+use Latte\Compiler\Nodes\Html\{AttributeNode, ElementNode, ExpressionAttributeNode};
use Latte\Compiler\Nodes\Php\ExpressionNode;
use Latte\Compiler\Nodes\Php\Scalar\StringNode;
-use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\Nodes\TextNode;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Nodes/FormContainerNode.php b/src/Bridges/FormsLatte/Nodes/FormContainerNode.php
index 01af392c1..c0da3e741 100644
--- a/src/Bridges/FormsLatte/Nodes/FormContainerNode.php
+++ b/src/Bridges/FormsLatte/Nodes/FormContainerNode.php
@@ -7,11 +7,9 @@
namespace Nette\Bridges\FormsLatte\Nodes;
-use Latte\Compiler\Nodes\AreaNode;
+use Latte\Compiler\Nodes\{AreaNode, StatementNode};
use Latte\Compiler\Nodes\Php\ExpressionNode;
-use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php
index f35de2a6e..7e5b34825 100644
--- a/src/Bridges/FormsLatte/Nodes/FormNNameNode.php
+++ b/src/Bridges/FormsLatte/Nodes/FormNNameNode.php
@@ -8,13 +8,10 @@
namespace Nette\Bridges\FormsLatte\Nodes;
use Latte;
-use Latte\Compiler\Nodes\AreaNode;
-use Latte\Compiler\Nodes\AuxiliaryNode;
+use Latte\Compiler\Nodes\{AreaNode, AuxiliaryNode, StatementNode};
use Latte\Compiler\Nodes\Php\ExpressionNode;
use Latte\Compiler\Nodes\Php\Scalar\StringNode;
-use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Nodes/FormNode.php b/src/Bridges/FormsLatte/Nodes/FormNode.php
index 44f50e557..cc3a3e45c 100644
--- a/src/Bridges/FormsLatte/Nodes/FormNode.php
+++ b/src/Bridges/FormsLatte/Nodes/FormNode.php
@@ -8,14 +8,11 @@
namespace Nette\Bridges\FormsLatte\Nodes;
use Latte\CompileException;
-use Latte\Compiler\Nodes\AreaNode;
+use Latte\Compiler\Nodes\{AreaNode, StatementNode};
use Latte\Compiler\Nodes\Php\Expression\ArrayNode;
use Latte\Compiler\Nodes\Php\ExpressionNode;
use Latte\Compiler\Nodes\Php\Scalar\StringNode;
-use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\Position;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{Position, PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Nodes/FormPrintNode.php b/src/Bridges/FormsLatte/Nodes/FormPrintNode.php
index ba939838d..5eaa568af 100644
--- a/src/Bridges/FormsLatte/Nodes/FormPrintNode.php
+++ b/src/Bridges/FormsLatte/Nodes/FormPrintNode.php
@@ -9,8 +9,7 @@
use Latte\Compiler\Nodes\Php\ExpressionNode;
use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Nodes/InputErrorNode.php b/src/Bridges/FormsLatte/Nodes/InputErrorNode.php
index 87ee8928b..1e356d24a 100644
--- a/src/Bridges/FormsLatte/Nodes/InputErrorNode.php
+++ b/src/Bridges/FormsLatte/Nodes/InputErrorNode.php
@@ -9,8 +9,7 @@
use Latte\Compiler\Nodes\Php\ExpressionNode;
use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Nodes/InputNode.php b/src/Bridges/FormsLatte/Nodes/InputNode.php
index 3ebb1fb7f..c6ea3d46a 100644
--- a/src/Bridges/FormsLatte/Nodes/InputNode.php
+++ b/src/Bridges/FormsLatte/Nodes/InputNode.php
@@ -11,8 +11,7 @@
use Latte\Compiler\Nodes\Php\ExpressionNode;
use Latte\Compiler\Nodes\Php\Scalar\StringNode;
use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Nodes/LabelNode.php b/src/Bridges/FormsLatte/Nodes/LabelNode.php
index 9e969c187..c5d7a18bb 100644
--- a/src/Bridges/FormsLatte/Nodes/LabelNode.php
+++ b/src/Bridges/FormsLatte/Nodes/LabelNode.php
@@ -8,14 +8,11 @@
namespace Nette\Bridges\FormsLatte\Nodes;
use Latte\CompileException;
-use Latte\Compiler\Nodes\AreaNode;
+use Latte\Compiler\Nodes\{AreaNode, StatementNode};
use Latte\Compiler\Nodes\Php\Expression\ArrayNode;
use Latte\Compiler\Nodes\Php\ExpressionNode;
use Latte\Compiler\Nodes\Php\Scalar\StringNode;
-use Latte\Compiler\Nodes\StatementNode;
-use Latte\Compiler\Position;
-use Latte\Compiler\PrintContext;
-use Latte\Compiler\Tag;
+use Latte\Compiler\{Position, PrintContext, Tag};
/**
diff --git a/src/Bridges/FormsLatte/Runtime.php b/src/Bridges/FormsLatte/Runtime.php
index e34dc45b6..d53725479 100644
--- a/src/Bridges/FormsLatte/Runtime.php
+++ b/src/Bridges/FormsLatte/Runtime.php
@@ -10,8 +10,7 @@
use Nette;
use Nette\Forms\Form;
use Nette\Utils\Html;
-use function end, explode, is_object, parse_url, preg_replace, preg_split, urldecode;
-use const PHP_URL_QUERY;
+use function is_object;
/**
@@ -59,12 +58,17 @@ public static function renderFormEnd(Form $form, bool $withTags = true): string
{
$s = '';
if ($form->isMethod('get')) {
- foreach (preg_split('#[;&]#', (string) parse_url((string) $form->getElementPrototype()->action, PHP_URL_QUERY), -1, PREG_SPLIT_NO_EMPTY) as $param) {
+ foreach (preg_split(
+ '#[;&]#',
+ (string) parse_url((string) $form->getElementPrototype()->action, PHP_URL_QUERY),
+ -1,
+ PREG_SPLIT_NO_EMPTY,
+ ) as $param) {
$parts = explode('=', $param, 2);
$name = urldecode($parts[0]);
$prefix = explode('[', $name, 2)[0];
if (!isset($form[$prefix])) {
- $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1])]);
+ $s .= Html::el('input', ['type' => 'hidden', 'name' => $name, 'value' => urldecode($parts[1] ?? '')]);
}
}
}
@@ -88,7 +92,8 @@ public static function item(object|string|int $item, object $global): object
if (is_object($item)) {
return $item;
}
- $form = end($global->formsStack) ?: throw new \LogicException('Form declaration is missing, did you use {form} or
',
Runtime::renderFormEnd($form),
);
diff --git a/tests/Forms.Latte3/forms.phpt b/tests/Forms.Latte3/forms.phpt
index c16ba8b72..cbd8ead49 100644
--- a/tests/Forms.Latte3/forms.phpt
+++ b/tests/Forms.Latte3/forms.phpt
@@ -33,7 +33,7 @@ $form->addText('username', 'Username:'); // must have just one textfield to gene
$form['username']->getControlPrototype()->addClass('control-class');
$form->addRadioList('sex', 'Sex:', ['m' => 'male', 'f' => 'female']);
$form->addSelect('select', null, ['m' => 'male', 'f' => 'female']);
-$form->addTextArea('area', null)->setValue('oneaddTextArea('area')->setValue('oneaddCheckbox('checkbox', 'Checkbox');
$form->addCheckboxList('checklist', 'CheckboxList:', ['m' => 'male', 'f' => 'female']);
$form->addSubmit('send', 'Sign in');
diff --git a/tests/Forms/Blueprint.dataClass.phpt b/tests/Forms/Blueprint.dataClass.phpt
index 4a7bd6c4f..be5d5dba0 100644
--- a/tests/Forms/Blueprint.dataClass.phpt
+++ b/tests/Forms/Blueprint.dataClass.phpt
@@ -1,10 +1,8 @@
getValues(FormWithEnum::class));
});
+
+
+test('mapping a numeric string to an int-backed enum', function () {
+ $form = new Form;
+ $form->addText('value');
+ $form->setValues(['value' => '1']);
+
+ Assert::equal(new FormWithIntEnum(IntEnum::One), $form->getValues(FormWithIntEnum::class));
+});
+
+
+test('mapping a numeric string to a string-backed enum', function () {
+ $form = new Form;
+ $form->addText('value');
+ $form->setValues(['value' => '1']);
+
+ Assert::equal(new FormWithStringIntEnum(StringIntEnum::One), $form->getValues(FormWithStringIntEnum::class));
+});
+
+
+test('incompatible values are left unchanged instead of raising TypeError/ValueError', function () {
+ $intRef = new ReflectionProperty(FormWithIntEnum::class, 'value');
+ $strRef = (new ReflectionClass(FormWithEnum::class))->getConstructor()->getParameters()[0];
+ $strIntRef = new ReflectionProperty(FormWithStringIntEnum::class, 'value');
+
+ // int-backed enum
+ Assert::same(IntEnum::One, Helpers::tryEnumConversion('1', $intRef));
+ Assert::same('abc', Helpers::tryEnumConversion('abc', $intRef)); // was TypeError
+ Assert::same('', Helpers::tryEnumConversion('', $intRef)); // empty field, was TypeError
+ Assert::same('9', Helpers::tryEnumConversion('9', $intRef)); // valid type, unknown case, was ValueError
+
+ // string-backed enum
+ Assert::same(TestEnum::Case1, Helpers::tryEnumConversion('case 1', $strRef));
+ Assert::same('zzz', Helpers::tryEnumConversion('zzz', $strRef)); // unknown case, was ValueError
+
+ // string-backed enum with numeric values (submitted as string)
+ Assert::same(StringIntEnum::One, Helpers::tryEnumConversion('1', $strIntRef));
+ Assert::same('9', Helpers::tryEnumConversion('9', $strIntRef)); // unknown case, was ValueError
+
+ Assert::null(Helpers::tryEnumConversion(null, $intRef));
+});
diff --git a/tests/Forms/Container.values.mapping.phpt b/tests/Forms/Container.values.mapping.phpt
index 94428fcbc..73d2b78ef 100644
--- a/tests/Forms/Container.values.mapping.phpt
+++ b/tests/Forms/Container.values.mapping.phpt
@@ -1,11 +1,9 @@
addComponent(createContainer(), 'child');
$form->addComponent($container, 'parent');
Assert::equal(4, count($group->getControls()));
-Assert::equal([$form['parent']['street'], $form['parent']['town'], $form['parent']['child']['street'], $form['parent']['child']['town']], $group->getControls());
+Assert::equal(
+ [$form['parent']['street'], $form['parent']['town'], $form['parent']['child']['street'], $form['parent']['child']['town']],
+ $group->getControls(),
+);
// container and controls
diff --git a/tests/Forms/Forms.crossOrigin.phpt b/tests/Forms/Forms.crossOrigin.phpt
index 5c0738e79..87238c8a4 100644
--- a/tests/Forms/Forms.crossOrigin.phpt
+++ b/tests/Forms/Forms.crossOrigin.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.enum.phpt b/tests/Forms/Forms.enum.phpt
index 34ef5fbb6..67249451a 100644
--- a/tests/Forms/Forms.enum.phpt
+++ b/tests/Forms/Forms.enum.phpt
@@ -4,8 +4,7 @@
* Test: Nette\Forms\Controls\BaseControl & enum
*/
-use Nette\Forms\Form;
-use Nette\Forms\Validator;
+use Nette\Forms\{Form, Validator};
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.getHttpData.get.2.phpt b/tests/Forms/Forms.getHttpData.get.2.phpt
index 705faa234..f75ca0c60 100644
--- a/tests/Forms/Forms.getHttpData.get.2.phpt
+++ b/tests/Forms/Forms.getHttpData.get.2.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.getHttpData.get.phpt b/tests/Forms/Forms.getHttpData.get.phpt
index ac7fa26f9..abfa8fb9c 100644
--- a/tests/Forms/Forms.getHttpData.get.phpt
+++ b/tests/Forms/Forms.getHttpData.get.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.getHttpData.post.phpt b/tests/Forms/Forms.getHttpData.post.phpt
index 39f71a045..f3d11089f 100644
--- a/tests/Forms/Forms.getHttpData.post.phpt
+++ b/tests/Forms/Forms.getHttpData.post.phpt
@@ -4,11 +4,9 @@
* Test: Nette\Forms HTTP data.
*/
-use Nette\Forms\Form;
-use Nette\Forms\Validator;
+use Nette\Forms\{Form, Validator};
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.idMask.phpt b/tests/Forms/Forms.idMask.phpt
index 2369605e7..ce22a5d43 100644
--- a/tests/Forms/Forms.idMask.phpt
+++ b/tests/Forms/Forms.idMask.phpt
@@ -4,7 +4,6 @@ use Nette\Forms\Controls\TextInput;
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.isValid.phpt b/tests/Forms/Forms.isValid.phpt
index 7623df1e3..702d31b87 100644
--- a/tests/Forms/Forms.isValid.phpt
+++ b/tests/Forms/Forms.isValid.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.maxPostSize.phpt b/tests/Forms/Forms.maxPostSize.phpt
index 67582c242..4167fc28e 100644
--- a/tests/Forms/Forms.maxPostSize.phpt
+++ b/tests/Forms/Forms.maxPostSize.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
@@ -21,4 +20,4 @@ $form->isSuccess();
$errors = $form->getErrors();
Assert::count(1, $errors);
-Assert::match('The size of the uploaded file can be up to %d% bytes.', $errors[0]);
+Assert::match('The uploaded data exceeds the limit of %d% bytes.', $errors[0]);
diff --git a/tests/Forms/Forms.no.events.phpt b/tests/Forms/Forms.no.events.phpt
index c3e9576fe..e425c6ee8 100644
--- a/tests/Forms/Forms.no.events.phpt
+++ b/tests/Forms/Forms.no.events.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.omittedValue.phpt b/tests/Forms/Forms.omittedValue.phpt
index 07d00c590..94e74eef6 100644
--- a/tests/Forms/Forms.omittedValue.phpt
+++ b/tests/Forms/Forms.omittedValue.phpt
@@ -8,7 +8,6 @@ use Nette\Forms\Controls\TextInput;
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.onClick.phpt b/tests/Forms/Forms.onClick.phpt
index 7fb445410..31ce43f13 100644
--- a/tests/Forms/Forms.onClick.phpt
+++ b/tests/Forms/Forms.onClick.phpt
@@ -4,7 +4,6 @@ use Nette\Forms\Controls\SubmitButton;
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.onRender.phpt b/tests/Forms/Forms.onRender.phpt
index 747c4d1ae..31e0d745c 100644
--- a/tests/Forms/Forms.onRender.phpt
+++ b/tests/Forms/Forms.onRender.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.onSuccess.phpt b/tests/Forms/Forms.onSuccess.phpt
index 8fd385970..6bf832bd9 100644
--- a/tests/Forms/Forms.onSuccess.phpt
+++ b/tests/Forms/Forms.onSuccess.phpt
@@ -7,7 +7,6 @@
use Nette\Forms\Form;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
diff --git a/tests/Forms/Forms.renderer.1.phpt b/tests/Forms/Forms.renderer.1.phpt
index 16033510b..1a4d97508 100644
--- a/tests/Forms/Forms.renderer.1.phpt
+++ b/tests/Forms/Forms.renderer.1.phpt
@@ -8,12 +8,24 @@ use Nette\Forms\Form;
use Nette\Utils\Html;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
$_SERVER['REQUEST_METHOD'] = 'POST';
-$_POST = ['name' => 'John Doe ', 'age' => '', 'email' => ' @ ', 'send' => 'on', 'street' => '', 'city' => '', 'country' => 'HU', 'password' => 'xxx', 'password2' => '', 'note' => '', 'submit1' => 'Send', 'userid' => '231'];
+$_POST = [
+ 'name' => 'John Doe ',
+ 'age' => '',
+ 'email' => ' @ ',
+ 'send' => 'on',
+ 'street' => '',
+ 'city' => '',
+ 'country' => 'HU',
+ 'password' => 'xxx',
+ 'password2' => '',
+ 'note' => '',
+ 'submit1' => 'Send',
+ 'userid' => '231',
+];
$countries = [
@@ -38,7 +50,10 @@ $form->allowCrossOrigin();
$form->addGroup('Personal data')
- ->setOption('description', 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.')
+ ->setOption(
+ 'description',
+ 'We value your privacy and we ensure that the information you give to us will not be shared to other entities.',
+ )
->setOption('id', 'test-group-id-set-via-option');
$form->addText('name', 'Your name:')
diff --git a/tests/Forms/Forms.renderer.2.phpt b/tests/Forms/Forms.renderer.2.phpt
index a9c1bb2f2..c542f3b43 100644
--- a/tests/Forms/Forms.renderer.2.phpt
+++ b/tests/Forms/Forms.renderer.2.phpt
@@ -8,12 +8,23 @@ use Nette\Forms\Form;
use Nette\Utils\Html;
use Tester\Assert;
-
require __DIR__ . '/../bootstrap.php';
$_SERVER['REQUEST_METHOD'] = 'POST';
-$_POST = ['name' => 'John Doe ', 'age' => '9.9', 'email' => '@', 'street' => '', 'city' => 'Troubsko', 'country' => '0', 'password' => 'xx', 'password2' => 'xx', 'note' => '', 'submit1' => 'Send', 'userid' => '231'];
+$_POST = [
+ 'name' => 'John Doe ',
+ 'age' => '9.9',
+ 'email' => '@',
+ 'street' => '',
+ 'city' => 'Troubsko',
+ 'country' => '0',
+ 'password' => 'xx',
+ 'password2' => 'xx',
+ 'note' => '',
+ 'submit1' => 'Send',
+ 'userid' => '231',
+];
$countries = [
diff --git a/tests/Forms/Forms.renderer.4.phpt b/tests/Forms/Forms.renderer.4.phpt
index b86ab47ac..38315b844 100644
--- a/tests/Forms/Forms.renderer.4.phpt
+++ b/tests/Forms/Forms.renderer.4.phpt
@@ -11,7 +11,7 @@ require __DIR__ . '/../bootstrap.php';
$form = new Nette\Forms\Form;
$form->setMethod('GET');
-$form->setAction('link?a=b&c[]=d&list[0]=1');
+$form->setAction('link?a=b&c[]=d&flag&list[0]=1');
$form->addCheckboxList('list')
->setItems(['First', 'Second']);
$form->addHidden('userid');
@@ -20,7 +20,7 @@ $form->addSubmit('submit', 'Send');
$form->fireEvents();
Assert::match('