diff --git a/composer.json b/composer.json index 84cf62ac15b10134fbc4ee03146c24d858c1e23b..32d2eaa8ff3fc9957bdcc5b20ee76046aaa5ab73 100644 --- a/composer.json +++ b/composer.json @@ -5,13 +5,16 @@ "php": "^7.2.5", "ext-ctype": "*", "ext-iconv": "*", + "doctrine/annotations": "^1.8", "symfony/console": "5.0.*", "symfony/dotenv": "5.0.*", "symfony/flex": "^1.3.1", + "symfony/form": "5.0.*", "symfony/framework-bundle": "5.0.*", "symfony/yaml": "5.0.*" }, "require-dev": { + "symfony/maker-bundle": "^1.14" }, "config": { "preferred-install": { diff --git a/composer.lock b/composer.lock index fa92aae26cb7dfff8c3a6ff782317e6ec006c440..7b0ad7766b3c1c81762662b478d7fbbefe431ddd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,138 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7f769bc9dabc952a9e9210886c4900c8", + "content-hash": "91ff357897f2296188db5dd0fce8893b", "packages": [ + { + "name": "doctrine/annotations", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/904dca4eb10715b92569fbcd79e201d5c349b6bc", + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "^7.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2019-10-01T18:55:10+00:00" + }, + { + "name": "doctrine/lexer", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6", + "reference": "5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpstan/phpstan": "^0.11.8", + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "https://www.doctrine-project.org/projects/lexer.html", + "keywords": [ + "annotations", + "docblock", + "lexer", + "parser", + "php" + ], + "time": "2019-10-30T14:39:59+00:00" + }, { "name": "psr/cache", "version": "1.0.1", @@ -932,6 +1062,90 @@ "description": "Composer plugin for Symfony", "time": "2020-01-30T12:06:45+00:00" }, + { + "name": "symfony/form", + "version": "v5.0.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/form.git", + "reference": "7d3afc4f0776904bb199317ae71b6a0fc46e5e5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/form/zipball/7d3afc4f0776904bb199317ae71b6a0fc46e5e5d", + "reference": "7d3afc4f0776904bb199317ae71b6a0fc46e5e5d", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/event-dispatcher": "^4.4|^5.0", + "symfony/intl": "^4.4|^5.0", + "symfony/options-resolver": "^5.0", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.0", + "symfony/property-access": "^5.0", + "symfony/service-contracts": "^1.1|^2" + }, + "conflict": { + "phpunit/phpunit": "<5.4.3", + "symfony/console": "<4.4", + "symfony/dependency-injection": "<4.4", + "symfony/doctrine-bridge": "<4.4", + "symfony/framework-bundle": "<4.4", + "symfony/http-kernel": "<4.4", + "symfony/intl": "<4.4", + "symfony/translation": "<4.4", + "symfony/twig-bridge": "<4.4" + }, + "require-dev": { + "doctrine/collections": "~1.0", + "symfony/config": "^4.4|^5.0", + "symfony/console": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/http-foundation": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/security-csrf": "^4.4|^5.0", + "symfony/translation": "^4.4|^5.0", + "symfony/validator": "^4.4|^5.0", + "symfony/var-dumper": "^4.4|^5.0" + }, + "suggest": { + "symfony/security-csrf": "For protecting forms against CSRF attacks.", + "symfony/twig-bridge": "For templating with Twig.", + "symfony/validator": "For form validation." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "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": "Symfony Form Component", + "homepage": "https://symfony.com", + "time": "2020-02-29T10:07:09+00:00" + }, { "name": "symfony/framework-bundle", "version": "v5.0.5", @@ -1213,6 +1427,139 @@ "homepage": "https://symfony.com", "time": "2020-02-29T10:41:30+00:00" }, + { + "name": "symfony/inflector", + "version": "v5.0.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/inflector.git", + "reference": "e375603b6bd12e8e3aec3fc1b640ac18a4ef4cb2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/inflector/zipball/e375603b6bd12e8e3aec3fc1b640ac18a4ef4cb2", + "reference": "e375603b6bd12e8e3aec3fc1b640ac18a4ef4cb2", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/polyfill-ctype": "~1.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Inflector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Inflector Component", + "homepage": "https://symfony.com", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string", + "symfony", + "words" + ], + "time": "2020-01-04T14:08:26+00:00" + }, + { + "name": "symfony/intl", + "version": "v5.0.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/intl.git", + "reference": "2d1fb70e6e1c455a123218bebf6287d025c5bac5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/intl/zipball/2d1fb70e6e1c455a123218bebf6287d025c5bac5", + "reference": "2d1fb70e6e1c455a123218bebf6287d025c5bac5", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/polyfill-intl-icu": "~1.0" + }, + "require-dev": { + "symfony/filesystem": "^4.4|^5.0" + }, + "suggest": { + "ext-intl": "to use the component with locales other than \"en\"" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Intl\\": "" + }, + "classmap": [ + "Resources/stubs" + ], + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + }, + { + "name": "Eriksen Costa", + "email": "eriksen.costa@infranology.com.br" + }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A PHP replacement layer for the C intl extension that includes additional data from the ICU library.", + "homepage": "https://symfony.com", + "keywords": [ + "i18n", + "icu", + "internationalization", + "intl", + "l10n", + "localization" + ], + "time": "2020-02-04T09:41:09+00:00" + }, { "name": "symfony/mime", "version": "v5.0.5", @@ -1275,6 +1622,118 @@ ], "time": "2020-02-04T09:41:09+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v5.0.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "b1ab86ce52b0c0abe031367a173005a025e30e04" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/b1ab86ce52b0c0abe031367a173005a025e30e04", + "reference": "b1ab86ce52b0c0abe031367a173005a025e30e04", + "shasum": "" + }, + "require": { + "php": "^7.2.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "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": "Symfony OptionsResolver Component", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "time": "2020-01-04T14:08:26+00:00" + }, + { + "name": "symfony/polyfill-intl-icu", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-icu.git", + "reference": "9c281272735eb66476e0fa7381e03fb0d4b60197" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/9c281272735eb66476e0fa7381e03fb0d4b60197", + "reference": "9c281272735eb66476e0fa7381e03fb0d4b60197", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/intl": "~2.3|~3.0|~4.0|~5.0" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.15-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "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" + ], + "time": "2020-02-27T09:26:54+00:00" + }, { "name": "symfony/polyfill-intl-idn", "version": "v1.15.0", @@ -1454,6 +1913,73 @@ ], "time": "2020-02-27T09:26:54+00:00" }, + { + "name": "symfony/property-access", + "version": "v5.0.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/property-access.git", + "reference": "18617a8c26b97a262f816c78765eb3cd91630e19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/property-access/zipball/18617a8c26b97a262f816c78765eb3cd91630e19", + "reference": "18617a8c26b97a262f816c78765eb3cd91630e19", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/inflector": "^4.4|^5.0" + }, + "require-dev": { + "symfony/cache": "^4.4|^5.0" + }, + "suggest": { + "psr/cache-implementation": "To cache access methods." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\PropertyAccess\\": "" + }, + "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": "Symfony PropertyAccess Component", + "homepage": "https://symfony.com", + "keywords": [ + "access", + "array", + "extraction", + "index", + "injection", + "object", + "property", + "property path", + "reflection" + ], + "time": "2020-01-04T14:08:26+00:00" + }, { "name": "symfony/routing", "version": "v5.0.5", @@ -1783,7 +2309,195 @@ "time": "2020-02-03T13:51:17+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "doctrine/inflector", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "ec3a55242203ffa6a4b27c58176da97ff0a7aec1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/ec3a55242203ffa6a4b27c58176da97ff0a7aec1", + "reference": "ec3a55242203ffa6a4b27c58176da97ff0a7aec1", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2019-10-30T19:59:35+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v4.3.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/9a9981c347c5c49d6dfe5cf826bb882b824080dc", + "reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "0.0.5", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2019-11-08T13:50:10+00:00" + }, + { + "name": "symfony/maker-bundle", + "version": "v1.14.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/maker-bundle.git", + "reference": "bc4df88792fbaaeb275167101dc714218475db5f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/maker-bundle/zipball/bc4df88792fbaaeb275167101dc714218475db5f", + "reference": "bc4df88792fbaaeb275167101dc714218475db5f", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^1.2", + "nikic/php-parser": "^4.0", + "php": "^7.0.8", + "symfony/config": "^3.4|^4.0|^5.0", + "symfony/console": "^3.4|^4.0|^5.0", + "symfony/dependency-injection": "^3.4|^4.0|^5.0", + "symfony/filesystem": "^3.4|^4.0|^5.0", + "symfony/finder": "^3.4|^4.0|^5.0", + "symfony/framework-bundle": "^3.4|^4.0|^5.0", + "symfony/http-kernel": "^3.4|^4.0|^5.0" + }, + "require-dev": { + "doctrine/doctrine-bundle": "^1.8|^2.0", + "doctrine/orm": "^2.3", + "friendsofphp/php-cs-fixer": "^2.8", + "friendsoftwig/twigcs": "^3.1.2", + "symfony/http-client": "^4.3|^5.0", + "symfony/phpunit-bridge": "^4.3|^5.0", + "symfony/process": "^3.4|^4.0|^5.0", + "symfony/security-core": "^3.4|^4.0|^5.0", + "symfony/yaml": "^3.4|^4.0|^5.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\MakerBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.", + "homepage": "https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html", + "keywords": [ + "code generator", + "generator", + "scaffold", + "scaffolding" + ], + "time": "2020-03-04T13:57:29+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/config/bundles.php b/config/bundles.php index 49d3fb6fcef0acfd0f1d4920a71806ca22a69942..ffeb861013862db48598807a5f17d5066ece4f49 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -2,4 +2,5 @@ return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], ]; diff --git a/config/routes/annotations.yaml b/config/routes/annotations.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e92efc5969392ae3d73489d066d8cd625dd27718 --- /dev/null +++ b/config/routes/annotations.yaml @@ -0,0 +1,7 @@ +controllers: + resource: ../../src/Controller/ + type: annotation + +kernel: + resource: ../../src/Kernel.php + type: annotation diff --git a/src/Controller/TestVoFormController.php b/src/Controller/TestVoFormController.php new file mode 100644 index 0000000000000000000000000000000000000000..2d7e9c71285d9fc2f782060bdc51d447d7977f84 --- /dev/null +++ b/src/Controller/TestVoFormController.php @@ -0,0 +1,53 @@ +<?php + +namespace App\Controller; + +use App\Form\ColorType; +use App\Model\ColorVo; +use App\Model\ParentModel; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\DataMapperInterface; +use Symfony\Component\Form\Exception\TransformationFailedException; +use Symfony\Component\Form\Exception\UnexpectedTypeException; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Form\FormFactoryInterface; +use Symfony\Component\Routing\Annotation\Route; + +class TestVoFormController extends AbstractController +{ + /** + * @Route("/test", name="test_vo_form") + */ + public function index(FormFactoryInterface $formFactory) + { + $form = $formFactory->createNamedBuilder('', FormType::class, null, ['data_class' => ParentModel::class, 'empty_data' => function () { return new ParentModel('', new ColorVo('foo')); }]) + ->setDataMapper(new class implements DataMapperInterface { + public function mapDataToForms($viewData, iterable $forms) + { + if ($viewData === null) { + return; + } + $forms = iterator_to_array($forms); + $forms['color']->setData($viewData->getColor()); + $forms['content']->setData($viewData->getContent()); + } + + public function mapFormsToData(iterable $forms, &$viewData) + { + throw new TransformationFailedException('hello'); + $forms = iterator_to_array($forms); + $viewData = new ParentModel($forms['content']->getData(), $forms['color']->getData()); + } + }) + ->add('color', ColorType::class) + ->add('content', TextType::class) + ->getForm(); + $form->submit(['color' => '#000000', 'content' => 'foobar']); + + return $this->json([ + 'message' => 'Welcome to your new controller!', + 'path' => 'src/Controller/TestVoFormController.php', + ]); + } +} diff --git a/src/Form/ColorType.php b/src/Form/ColorType.php new file mode 100644 index 0000000000000000000000000000000000000000..aaea4c82a29bc128118798b39efcee55c19139f6 --- /dev/null +++ b/src/Form/ColorType.php @@ -0,0 +1,60 @@ +<?php + +namespace App\Form; + + +use App\Model\ColorVo; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\DataMapperInterface; +use Symfony\Component\Form\DataTransformerInterface; +use Symfony\Component\Form\Exception; +use Symfony\Component\Form\Exception\TransformationFailedException; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; + +class ColorType extends AbstractType implements DataTransformerInterface +{ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->addModelTransformer($this); + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'compound' => false, + ]); + } + + public function transform($value) + { + if ($value === null) { + return null; + } + return $value->getHexaColor(); + } + + public function reverseTransform($value) + { + if ($value === null) { + return null; + } + + return new ColorVo($value); + } + + public function mapDataToForms($viewData, iterable $forms) + { + // Will obviously not work but should + $forms->setData($viewData->getHexaColor()); + } + + public function mapFormsToData(iterable $forms, &$viewData) + { + $viewData = new ColorVo($forms->getData()); + } +} diff --git a/src/Model/ColorVo.php b/src/Model/ColorVo.php new file mode 100644 index 0000000000000000000000000000000000000000..832d3ce513f463a3dd13cabc9acde0a5315e79f2 --- /dev/null +++ b/src/Model/ColorVo.php @@ -0,0 +1,18 @@ +<?php + +namespace App\Model; + + +class ColorVo +{ + private $color; + public function __construct(string $color) + { + $this->color = $color; + } + + public function getHexaColor(): string + { + return $this->color; + } +} diff --git a/src/Model/ParentModel.php b/src/Model/ParentModel.php new file mode 100644 index 0000000000000000000000000000000000000000..1c548126954e0e15b2952f75d91fa70c777ef6ca --- /dev/null +++ b/src/Model/ParentModel.php @@ -0,0 +1,34 @@ +<?php + +namespace App\Model; + + +class ParentModel +{ + /** @var ColorVo */ + private $color; + /** @var string */ + private $content; + + public function __construct(string $content, ColorVo $color) + { + $this->content = $content; + $this->color = $color; + } + + /** + * @return ColorVo + */ + public function getColor(): ColorVo + { + return $this->color; + } + + /** + * @return string + */ + public function getContent(): string + { + return $this->content; + } +} diff --git a/symfony.lock b/symfony.lock index e4e3e5ee9d62496e0148e77e10bca3dbbd1b1c3c..ee44accf92fe73059b0b693c53ff19c4564110a3 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,25 @@ { + "doctrine/annotations": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "a2759dd6123694c8d901d0ec80006e044c2e6457" + }, + "files": [ + "config/routes/annotations.yaml" + ] + }, + "doctrine/inflector": { + "version": "1.3.1" + }, + "doctrine/lexer": { + "version": "1.2.0" + }, + "nikic/php-parser": { + "version": "v4.3.0" + }, "php": { "version": "7.4" }, @@ -69,6 +90,9 @@ ".env" ] }, + "symfony/form": { + "version": "v5.0.5" + }, "symfony/framework-bundle": { "version": "4.4", "recipe": { @@ -95,9 +119,30 @@ "symfony/http-kernel": { "version": "v5.0.5" }, + "symfony/inflector": { + "version": "v5.0.5" + }, + "symfony/intl": { + "version": "v5.0.5" + }, + "symfony/maker-bundle": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" + } + }, "symfony/mime": { "version": "v5.0.5" }, + "symfony/options-resolver": { + "version": "v5.0.5" + }, + "symfony/polyfill-intl-icu": { + "version": "v1.15.0" + }, "symfony/polyfill-intl-idn": { "version": "v1.15.0" }, @@ -107,6 +152,9 @@ "symfony/polyfill-php73": { "version": "v1.15.0" }, + "symfony/property-access": { + "version": "v5.0.5" + }, "symfony/routing": { "version": "4.2", "recipe": {