diff --git a/composer.json b/composer.json index cfab85f..92e6012 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,12 @@ "symfony/console": "8.1.*", "symfony/dotenv": "8.1.*", "symfony/flex": "^2", + "symfony/form": "8.1.*", "symfony/framework-bundle": "8.1.*", "symfony/runtime": "8.1.*", "symfony/security-bundle": "8.1.*", "symfony/twig-bundle": "8.1.*", + "symfony/validator": "8.1.*", "symfony/webpack-encore-bundle": "^2.4", "symfony/yaml": "8.1.*" }, diff --git a/composer.lock b/composer.lock index 32a615c..f4e21af 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4727574c12cc62460fbd970446c9b9e1", + "content-hash": "7cb3f6fd0346d6768d6618db5e43671d", "packages": [ { "name": "doctrine/collections", @@ -2666,6 +2666,103 @@ ], "time": "2026-05-29T17:25:22+00:00" }, + { + "name": "symfony/form", + "version": "v8.1.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/form.git", + "reference": "2cf2f9062fedefb9f21d015585efbfc65f1fa760" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/form/zipball/2cf2f9062fedefb9f21d015585efbfc65f1fa760", + "reference": "2cf2f9062fedefb9f21d015585efbfc65f1fa760", + "shasum": "" + }, + "require": { + "php": ">=8.4.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/event-dispatcher": "^7.4|^8.0", + "symfony/options-resolver": "^7.4|^8.0", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-intl-icu": "^1.21", + "symfony/polyfill-mbstring": "^1.0", + "symfony/property-access": "^7.4|^8.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/var-exporter": "^8.1" + }, + "conflict": { + "symfony/intl": "<7.4", + "symfony/translation-contracts": "<2.5", + "symfony/validator": "<7.4" + }, + "require-dev": { + "doctrine/collections": "^1.0|^2.0", + "symfony/clock": "^7.4|^8.0", + "symfony/config": "^7.4|^8.0", + "symfony/console": "^7.4|^8.0", + "symfony/dependency-injection": "^7.4|^8.0", + "symfony/expression-language": "^7.4|^8.0", + "symfony/html-sanitizer": "^7.4|^8.0", + "symfony/http-foundation": "^7.4|^8.0", + "symfony/http-kernel": "^7.4|^8.0", + "symfony/intl": "^7.4|^8.0", + "symfony/security-core": "^7.4|^8.0", + "symfony/security-csrf": "^7.4|^8.0", + "symfony/translation": "^7.4|^8.0", + "symfony/uid": "^7.4|^8.0", + "symfony/validator": "^7.4|^8.0", + "symfony/var-dumper": "^7.4|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Form\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows to easily create, process and reuse HTML forms", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/form/tree/v8.1.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-08-07T15:02:39+00:00" + }, { "name": "symfony/framework-bundle", "version": "v8.1.1", @@ -2999,6 +3096,77 @@ ], "time": "2026-06-27T09:27:36+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v8.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "88f9c561f678a02d54b897014049fa839e33ff82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/88f9c561f678a02d54b897014049fa839e33ff82", + "reference": "88f9c561f678a02d54b897014049fa839e33ff82", + "shasum": "" + }, + "require": { + "php": ">=8.4.1", + "symfony/deprecation-contracts": "^2.5|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an improved replacement for the array_replace PHP function", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "support": { + "source": "https://github.com/symfony/options-resolver/tree/v8.1.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-05-29T05:06:50+00:00" + }, { "name": "symfony/password-hasher", "version": "v8.1.0", @@ -3241,6 +3409,94 @@ ], "time": "2026-05-26T05:58:03+00:00" }, + { + "name": "symfony/polyfill-intl-icu", + "version": "v1.38.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-icu.git", + "reference": "445c90e341fccda10311019cf82ff73bb7343945" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/445c90e341fccda10311019cf82ff73bb7343945", + "reference": "445c90e341fccda10311019cf82ff73bb7343945", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "suggest": { + "ext-intl": "For best performance and support of other locales than \"en\"" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Icu\\": "" + }, + "classmap": [ + "Resources/stubs" + ], + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's ICU-related data and classes", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "icu", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-icu/tree/v1.38.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-05-25T11:52:53+00:00" + }, { "name": "symfony/polyfill-intl-normalizer", "version": "v1.38.0", @@ -4765,6 +5021,103 @@ ], "time": "2026-05-29T05:06:50+00:00" }, + { + "name": "symfony/validator", + "version": "v8.1.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/validator.git", + "reference": "1642533ef70c41781b8696163fcf0050c9fc68fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/validator/zipball/1642533ef70c41781b8696163fcf0050c9fc68fe", + "reference": "1642533ef70c41781b8696163fcf0050c9fc68fe", + "shasum": "" + }, + "require": { + "php": ">=8.4.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.0", + "symfony/translation-contracts": "^2.5|^3" + }, + "conflict": { + "doctrine/lexer": "<1.1", + "symfony/doctrine-bridge": "<7.4", + "symfony/expression-language": "<7.4" + }, + "require-dev": { + "egulias/email-validator": "^2.1.10|^3|^4", + "symfony/cache": "^7.4|^8.0", + "symfony/clock": "^7.4|^8.0", + "symfony/config": "^7.4|^8.0", + "symfony/console": "^7.4|^8.0", + "symfony/dependency-injection": "^7.4|^8.0", + "symfony/expression-language": "^7.4|^8.0", + "symfony/finder": "^7.4|^8.0", + "symfony/http-client": "^7.4|^8.0", + "symfony/http-foundation": "^7.4|^8.0", + "symfony/http-kernel": "^7.4|^8.0", + "symfony/intl": "^7.4|^8.0", + "symfony/mime": "^7.4|^8.0", + "symfony/process": "^7.4|^8.0", + "symfony/property-access": "^7.4|^8.0", + "symfony/property-info": "^7.4|^8.0", + "symfony/string": "^7.4|^8.0", + "symfony/translation": "^7.4|^8.0", + "symfony/type-info": "^7.4|^8.0", + "symfony/yaml": "^7.4|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Validator\\": "" + }, + "exclude-from-classmap": [ + "/Tests/", + "/Resources/bin/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools to validate values", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/validator/tree/v8.1.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-08-06T09:53:08+00:00" + }, { "name": "symfony/var-dumper", "version": "v8.1.1", @@ -5487,5 +5840,5 @@ "ext-iconv": "*" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } diff --git a/config/packages/csrf.yaml b/config/packages/csrf.yaml new file mode 100644 index 0000000..40d4040 --- /dev/null +++ b/config/packages/csrf.yaml @@ -0,0 +1,11 @@ +# Enable stateless CSRF protection for forms and logins/logouts +framework: + form: + csrf_protection: + token_id: submit + + csrf_protection: + stateless_token_ids: + - submit + - authenticate + - logout diff --git a/config/packages/validator.yaml b/config/packages/validator.yaml new file mode 100644 index 0000000..dd47a6a --- /dev/null +++ b/config/packages/validator.yaml @@ -0,0 +1,11 @@ +framework: + validation: + # Enables validator auto-mapping support. + # For instance, basic validation constraints will be inferred from Doctrine's metadata. + #auto_mapping: + # App\Entity\: [] + +when@test: + framework: + validation: + not_compromised_password: false diff --git a/config/reference.php b/config/reference.php index 540fc18..5785616 100644 --- a/config/reference.php +++ b/config/reference.php @@ -154,7 +154,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * cookie_name?: scalar|Param|null, // The name of the cookie to use when using stateless protection. // Default: "csrf-token" * }, * form?: bool|array{ // Form configuration - * enabled?: bool|Param, // Default: false + * enabled?: bool|Param, // Default: true * csrf_protection?: bool|array{ * enabled?: scalar|Param|null, // Default: null * token_id?: scalar|Param|null, // Default: null @@ -333,7 +333,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * }>, * }, * validation?: bool|array{ // Validation configuration - * enabled?: bool|Param, // Default: false + * enabled?: bool|Param, // Default: true * enable_attributes?: bool|Param, // Default: true * static_method?: string|list, * translation_domain?: scalar|Param|null, // Default: "validators" diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index 17a2c2b..616f71f 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -24,7 +24,7 @@ spec: containers: - name: symfony - image: symfony-k3s:dev-5 + image: symfony-k3s:dev-6 imagePullPolicy: Never ports: diff --git a/src/Controller/TaskController.php b/src/Controller/TaskController.php new file mode 100644 index 0000000..8e57aee --- /dev/null +++ b/src/Controller/TaskController.php @@ -0,0 +1,81 @@ +render('task/index.html.twig', [ + 'tasks' => $taskRepository->findAll(), + ]); + } + + #[Route('/new', name: 'app_task_new', methods: ['GET', 'POST'])] + public function new(Request $request, EntityManagerInterface $entityManager): Response + { + $task = new Task(); + $form = $this->createForm(TaskType::class, $task); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->persist($task); + $entityManager->flush(); + + return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->render('task/new.html.twig', [ + 'task' => $task, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'app_task_show', methods: ['GET'])] + public function show(Task $task): Response + { + return $this->render('task/show.html.twig', [ + 'task' => $task, + ]); + } + + #[Route('/{id}/edit', name: 'app_task_edit', methods: ['GET', 'POST'])] + public function edit(Request $request, Task $task, EntityManagerInterface $entityManager): Response + { + $form = $this->createForm(TaskType::class, $task); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->flush(); + + return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER); + } + + return $this->render('task/edit.html.twig', [ + 'task' => $task, + 'form' => $form, + ]); + } + + #[Route('/{id}', name: 'app_task_delete', methods: ['POST'])] + public function delete(Request $request, Task $task, EntityManagerInterface $entityManager): Response + { + if ($this->isCsrfTokenValid('delete'.$task->getId(), $request->getPayload()->getString('_token'))) { + $entityManager->remove($task); + $entityManager->flush(); + } + + return $this->redirectToRoute('app_task_index', [], Response::HTTP_SEE_OTHER); + } +} diff --git a/src/Form/TaskType.php b/src/Form/TaskType.php new file mode 100644 index 0000000..0fa4359 --- /dev/null +++ b/src/Form/TaskType.php @@ -0,0 +1,37 @@ +add('title') + ->add('description') + ->add('estimatedDurationMinutes') + ->add('priority') + ->add('category') + ->add('isRecurring') + ->add('isActive') + ->add('createdAt', null, [ + 'widget' => 'single_text', + ]) + ->add('updatedAt', null, [ + 'widget' => 'single_text', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Task::class, + ]); + } +} diff --git a/symfony.lock b/symfony.lock index c5c6915..767c298 100644 --- a/symfony.lock +++ b/symfony.lock @@ -60,6 +60,18 @@ ".env.dev" ] }, + "symfony/form": { + "version": "8.1", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "7.2", + "ref": "7d86a6723f4a623f59e2bf966b6aad2fc461d36b" + }, + "files": [ + "config/packages/csrf.yaml" + ] + }, "symfony/framework-bundle": { "version": "8.1", "recipe": { @@ -140,6 +152,18 @@ "templates/base.html.twig" ] }, + "symfony/validator": { + "version": "8.1", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "7.0", + "ref": "8c1c4e28d26a124b0bb273f537ca8ce443472bfd" + }, + "files": [ + "config/packages/validator.yaml" + ] + }, "symfony/web-profiler-bundle": { "version": "8.1", "recipe": { diff --git a/templates/task/_delete_form.html.twig b/templates/task/_delete_form.html.twig new file mode 100644 index 0000000..e73f163 --- /dev/null +++ b/templates/task/_delete_form.html.twig @@ -0,0 +1,4 @@ +
+ + +
diff --git a/templates/task/_form.html.twig b/templates/task/_form.html.twig new file mode 100644 index 0000000..bf20b98 --- /dev/null +++ b/templates/task/_form.html.twig @@ -0,0 +1,4 @@ +{{ form_start(form) }} + {{ form_widget(form) }} + +{{ form_end(form) }} diff --git a/templates/task/edit.html.twig b/templates/task/edit.html.twig new file mode 100644 index 0000000..ed4e828 --- /dev/null +++ b/templates/task/edit.html.twig @@ -0,0 +1,13 @@ +{% extends 'base.html.twig' %} + +{% block title %}Edit Task{% endblock %} + +{% block body %} +

Edit Task

+ + {{ include('task/_form.html.twig', {'button_label': 'Update'}) }} + + back to list + + {{ include('task/_delete_form.html.twig') }} +{% endblock %} diff --git a/templates/task/index.html.twig b/templates/task/index.html.twig new file mode 100644 index 0000000..fe02498 --- /dev/null +++ b/templates/task/index.html.twig @@ -0,0 +1,51 @@ +{% extends 'base.html.twig' %} + +{% block title %}Task index{% endblock %} + +{% block body %} +

Task index

+ + + + + + + + + + + + + + + + + + + {% for task in tasks %} + + + + + + + + + + + + + + {% else %} + + + + {% endfor %} + +
IdTitleDescriptionEstimatedDurationMinutesPriorityCategoryIsRecurringIsActiveCreatedAtUpdatedAtactions
{{ task.id }}{{ task.title }}{{ task.description }}{{ task.estimatedDurationMinutes }}{{ task.priority }}{{ task.category }}{{ task.isRecurring ? 'Yes' : 'No' }}{{ task.isActive ? 'Yes' : 'No' }}{{ task.createdAt ? task.createdAt|date('Y-m-d H:i:s') : '' }}{{ task.updatedAt ? task.updatedAt|date('Y-m-d H:i:s') : '' }} + show + edit +
no records found
+ + Create new +{% endblock %} diff --git a/templates/task/new.html.twig b/templates/task/new.html.twig new file mode 100644 index 0000000..613191a --- /dev/null +++ b/templates/task/new.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block title %}New Task{% endblock %} + +{% block body %} +

Create new Task

+ + {{ include('task/_form.html.twig') }} + + back to list +{% endblock %} diff --git a/templates/task/show.html.twig b/templates/task/show.html.twig new file mode 100644 index 0000000..6abf1ec --- /dev/null +++ b/templates/task/show.html.twig @@ -0,0 +1,58 @@ +{% extends 'base.html.twig' %} + +{% block title %}Task{% endblock %} + +{% block body %} +

Task

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Id{{ task.id }}
Title{{ task.title }}
Description{{ task.description }}
EstimatedDurationMinutes{{ task.estimatedDurationMinutes }}
Priority{{ task.priority }}
Category{{ task.category }}
IsRecurring{{ task.isRecurring ? 'Yes' : 'No' }}
IsActive{{ task.isActive ? 'Yes' : 'No' }}
CreatedAt{{ task.createdAt ? task.createdAt|date('Y-m-d H:i:s') : '' }}
UpdatedAt{{ task.updatedAt ? task.updatedAt|date('Y-m-d H:i:s') : '' }}
+ + back to list + + edit + + {{ include('task/_delete_form.html.twig') }} +{% endblock %}