diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..2e00f42
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,56 @@
+name: Build Symftony/form-handler
+run-name: 🧑💻${{ github.actor }} Run build.
+on: [ push ]
+jobs:
+ Build:
+ name: PHP ${{ matrix.php-versions }} // composer ${{ matrix.composer-command }}
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ php-versions: [ '8.1', '8.2', '8.3' ]
+ composer-command:
+ - 'install'
+ - 'update --prefer-lowest'
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup PHP ${{ matrix.php-versions }}
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-versions }}
+ coverage: xdebug
+
+ - name: "Composer -> Get cache directory"
+ id: composer-cache
+ run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
+
+ - name: "Composer -> Cache dependencies"
+ uses: actions/cache@v4
+ with:
+ path: ${{ steps.composer-cache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+ restore-keys: ${{ runner.os }}-composer-
+
+ - name: "Composer -> Install dependencies"
+ run: composer ${{ matrix.composer-command }} --no-progress --prefer-dist --optimize-autoloader
+
+ - name: "Composer -> Show"
+ run: composer show
+
+ - name: "Composer -> check platform requirements"
+ run: composer check-platform-reqs
+
+# - name: "Rector -> Run"
+# run: rector --dry-run
+
+ - name: "PHP cs fixer -> check"
+ run: vendor/bin/php-cs-fixer check src
+
+ - name: "PHPStan -> Run"
+ run: vendor/bin/phpstan analyse src
+
+ - name: "PHPUnit -> Run"
+ run: vendor/bin/phpunit --coverage-text
+ env:
+ XDEBUG_MODE: coverage
diff --git a/.gitignore b/.gitignore
index 50b321e..4091b78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,7 @@
vendor
composer.lock
+
+.phpunit.cache
.phpunit.result.cache
+
+.php-cs-fixer.cache
diff --git a/composer.json b/composer.json
index cc9e48c..afa3e27 100644
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,7 @@
"symfony/form": "^6.1"
},
"require-dev": {
- "phpunit/phpunit": "^9.1",
+ "phpunit/phpunit": "^10",
"symfony/dependency-injection": "^6.1",
"symfony/config": "^6.1",
"symfony/http-kernel": "^6.1",
@@ -23,7 +23,10 @@
"phpspec/prophecy-phpunit": "^2.1",
"symfony/translation": "^6.1",
"symfony/contracts": "^3.5@dev",
- "symfony/validator": "^6.1"
+ "symfony/validator": "^6.1",
+ "phpstan/phpstan": "^1.11",
+ "friendsofphp/php-cs-fixer": "dev-master",
+ "rector/rector": "dev-main"
},
"suggest": {
"symfony/dependency-injection": "^6.1",
diff --git a/examples/CustomFormHandler.php b/examples/CustomFormHandler.php
index 4663456..eb0ca92 100644
--- a/examples/CustomFormHandler.php
+++ b/examples/CustomFormHandler.php
@@ -1,5 +1,7 @@
createForm(ChoiceType::class, 'my-value', null, [
'method' => 'GET',
@@ -30,7 +29,7 @@ public function formChoice()
]);
}
- public function createFromRequest($request = null, $notSubmitted = true, $invalid = true)
+ public function createFromRequest(?mixed $request = null, $notSubmitted = true, $invalid = true)
{
$form = $this->createForm(ChoiceType::class, 'my-value', null, [
'method' => 'GET',
@@ -49,4 +48,4 @@ public function createFromRequest($request = null, $notSubmitted = true, $invali
return $this->handleRequest($form, $request);
}
-}
\ No newline at end of file
+}
diff --git a/examples/custom-form-api.php b/examples/custom-form-api.php
index 6929448..049412c 100644
--- a/examples/custom-form-api.php
+++ b/examples/custom-form-api.php
@@ -1,9 +1,11 @@
addTypeExtension(new TransformationFailedTypeExtension())
->addExtension(new ValidatorExtension(Validation::createValidator()))
->getFormFactory();
-
// Initialize form handler
$formHandler = new CustomFormHandler();
$formHandler->setFormFactory($formFactory);
-
// Create the form
// Handle request
$exception = null;
try {
$result = $formHandler->createFromRequest();
-} catch (FormException $e) {
- $exception = $e;
+} catch (FormException $formException) {
+ $exception = $formException;
}
?>
@@ -41,7 +40,9 @@
Form handler throw NotSubmitted/Invalid Exception example
-
+
Form handler will return default data when exception append
@@ -67,13 +68,22 @@
/!\ When you use the handler to do some API you dont need the form in your controller. You just need your data or Exception /!\
- $formHandler->handleRequest($form) :
-
- = get_class($exception) . ' : ' . $exception->getMessage() ?>
+ $formHandler->handleRequest($form) :
+
+ = $exception::class . ' : ' . $exception->getMessage() ?>
+
+?>