20 Matching Annotations
- Dec 2022
-
www.zhihu.com www.zhihu.com
-
MyBatis为什么在国内相当流行?
Tags
Annotators
URL
-
-
www.zhihu.com www.zhihu.com
-
如何面试Python后端工程师?
Tags
Annotators
URL
-
- Nov 2022
-
verraes.net verraes.net
-
www.domainlanguage.com www.domainlanguage.com
-
github.com github.com
Tags
Annotators
URL
-
- Jul 2021
-
lyz-code.github.io lyz-code.github.io
-
behaviour should come first and drive our storage requirements.
-
- Nov 2020
-
dzone.com dzone.com
Tags
Annotators
URL
-
- May 2020
-
hypothes.is hypothes.is
-
Create a note by selecting some text and clicking the button
Here's an annotation I'm putting in.
-
- Mar 2020
- Dec 2019
-
github.com github.com
-
- Nov 2019
-
webmozart.io webmozart.io
-
Instead of using the empty_data option – which is only called if we create an object, but not if we update it – we will implement a custom data mapper. Symfony's data mappers are responsible for mapping the data of a form to its fields and back. For our MoneyType, Symfony's default data mapper will call the following methods when we display a form with an existing Money instance: $form->get('amount')->setData($money->getAmount()); $form->get('currency')->setData($money->getCurrency()); The properties of the Money are copied to the form simply by calling the appropriate getters. When we submit the form, the data mapper inverts that behavior: $money->setAmount($form->get('amount')->getData()); $money->setCurrency($form->get('currency')->getData()); That's where the data mapper fails. The setters setAmount() and setCurrency() don't exist. To create a custom data mapper we need to implement DataMapperInterface. Let's look at this interface: namespace Symfony\Component\Form; interface DataMapperInterface { /** * Maps properties of some data to a list of forms. * * @param mixed $data Structured data. * @param FormInterface[] $forms A list of {@link FormInterface} instances. */ public function mapDataToForms($data, $forms); /** * Maps the data of a list of forms into the properties of some data. * * @param FormInterface[] $forms A list of {@link FormInterface} instances. * @param mixed $data Structured data. */ public function mapFormsToData($forms, &$data); } These methods correspond to the two previous code blocks. The method mapDataToForms() calls setData() on all passed forms by reading the passed $data. Conversely, mapFormsToData() updates $data by reading the data of the passed forms.
This is so important & useful, when working in DDD & immutability, where setters are avoided.
-
- Apr 2017
-
www.googleapis.com www.googleapis.com
-
Google
dvsvs
-
- Jan 2016
-
www.cca.edu www.cca.edu
-
how
look at me annotating!!
-