Skip to content

Conversation

ThomasLandauer
Copy link
Contributor

@ThomasLandauer ThomasLandauer commented Jun 19, 2018

The page is still a mess, but a tried to (at least) improve it a little.

The main problem (to me) is that there a two pages for (basically) the same:

...which sometimes contradict each other, sometimes repeat each other and sometimes enhance each other. What's the advantage of having two pages at all? Why not merge them?

Some additional ideas for future improvements:

  • Show a copy-pastable example of serializing an entity from the database, since this is (probably) the most common use-case.
  • Show ->select('a.name, a.price, a.desc') together with ->getArrayResult() as an alternative to the @Groups annotation
  • When is dependency injection possible (or superior) over new Serializer(...)?
  • Error message "A circular reference has been detected (configured limit: 1)"

I edited the 4.0 version, since the page differs notably between versions, and I wasn't sure which one to take.

wiese and others added 30 commits March 23, 2018 11:22
minor doc fixes for the Message component
…(krizon) This PR was merged into the master branch. Discussion ---------- [Console] Change use statement for Process Helper Fixes the incorrect namespaces on this page. This issue was introduced in symfony#9396 Commits ------- 239f299 [Console] Change use statement for Process Helper
…r values (weaverryan) This PR was squashed before being merged into the master branch (closes symfony#9477). Discussion ---------- Removing warning about bind + controller + scalar values Docs for symfony/symfony#26658 :) Commits ------- af00dbc adding version note about scalar bind args 4312518 Removing warning about bind + controller + scalar values
…ereguiluz) This PR was squashed before being merged into the master branch (closes symfony#9490). Discussion ---------- Documented the trailing_slash_on_root option This fixes symfony#9484. @nicolas-grekas could you please verify if the config of the example is correct? I don't know if `trailing_slash_on_root` is defined for annotations. Thanks! Commits ------- b4b4954 Documented the trailing_slash_on_root option
…Form component (javiereguiluz) This PR was squashed before being merged into the master branch (closes symfony#9488). Discussion ---------- csrf_token now can be used without installing the Form component This fixes symfony#9488. @xabbuh in your original code (https://github.com/symfony/symfony/pull/25197/files) the function was added to Twig Bridge so ... could you please verify if installing just `security-csrf` is enough to use this function or if we need to install some other package? Thanks! Commits ------- 3c48a0a csrf_token now can be used without installing the Form component
* 4.0: (24 commits) added Sam in the core team minor symfony#9494 [Console] Change use statement for Process Helper (krizon) Specify how provide a high availability fixing format + language Documenting make:controller and make:crud Use FQCN as service ID Describe reliability in Lock Propose identical comparison [symfony#9195] fix a minor typo Fixed some variable names fix some security config examples Made explicit testing dependencies ...
 Please enter the commit message for your changes. Lines starting
…es (javiereguiluz) This PR was merged into the master branch. Discussion ---------- Use the new TransitionException in Workflow examples This fixes symfony#9478. I couldn't find any other usage of the old `LogicException` class. Commits ------- d1f4384 Use the new TransitionException in Workflow examples
…javiereguiluz) This PR was merged into the master branch. Discussion ---------- Documented the service locator autoconfiguration This fixes symfony#9374. Commits ------- c7ea0cf Documented the service locator autoconfiguration
* 4.0: Fixed the name of the decorating service argument Fix linebreak in Code line Fix link to Tobias' Github profile
javiereguiluz and others added 12 commits June 11, 2018 20:58
* 3.4: Use matching closing tag
The introduction states 4 big section will on the page, but the page list 1-3. (Not on 3.x)
This PR was submitted for the 4.1 branch but it was merged into the 4.0 branch instead (closes symfony#9928). Discussion ---------- Update messenger.rst <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 270b306 Update messenger.rst
…ions page (Calinou) This PR was merged into the 4.0 branch. Discussion ---------- Fix a configuration block in the Doctrine Associations page This also fixes a small typo. This issue first appeared in the `4.0` branch. Commits ------- 9a10276 Fix a configuration block in the Doctrine Associations page
This PR was merged into the 4.0 branch. Discussion ---------- Security - Fix numbering on 4.* The introduction states 4 big sections will on the page, but the page list 1-3. (not an issue on 3.x branch) Commits ------- 331a2a8 Fix numbering
…(javiereguiluz) This PR was merged into the 4.0 branch. Discussion ---------- Update Best Practices about service config format This fixes symfony#9915. @mickaelandrieu is this more clear now? Thanks! Commits ------- b08a9ca Update Best Practices about service config format
This PR was merged into the 4.0 branch. Discussion ---------- add legacy labels to keep external references for the old headlines before symfony#9921 working Commits ------- bcb2591 add legacy labels
The page is still a mess, but a tried to (at least) improve it a little. The main problem (to me) is that there a two pages for (basically) the same: * https://symfony.com/doc/4.0/serializer.html * https://symfony.com/doc/4.0/components/serializer.html ...which sometimes contradict each other, sometimes repeat each other and sometimes enhance each other. What's the advantage of having two pages at all? Why not merge them? Some additional ideas for future improvements: * Show a copy-pastable example of serializing an entity from the database, since this is (probably) the most common use-case. * Show `->select('a.name, a.price, a.desc')` together with `->getArrayResult()` as an alternative to the `@Groups` annotation * When is dependency injection possible (or superior) over `new Serializer(...)`? I edited the 4.0 version, since the page differs notably between versions, and I wasn't sure which one to take.
@javiereguiluz
Copy link
Member

/components/serializer.rst is for people using the Serializer component out of Symfony apps and /serializer.rst is when using it inside a Symfony app.

Sadly sometimes this results in some duplications. Overall, these would be the differences:

  • Components article explain the low level installation, the autoloading, etc. Main article assumes the reader is using Flex: composer require ... and done.
  • Features of the component should be explained in the component article and not in the main article...
  • ... except when using those features is different (i.e. simpler and better) when using the component inside a Symfony app. Then it's when there are some duplicated explanations.
  • The component page can't explain how to use Serializer with other components. Each component article is stand-alone, so cross-features are explained in the main article.

@ThomasLandauer is it more clear now?

@ThomasLandauer
Copy link
Contributor Author

Yeah, somewhat - thanks! :-)

Can I ask you some questions for me (or somebody else) to be able to make more improvements?

  1. So the list of available normalizers and encoders (i.e. this chapter https://symfony.com/doc/4.0/serializer.html#adding-normalizers-and-encoders ) needs to move to /components/serializer.rst? The only relevant aspect to /serializer.rst is the services.yaml part?

  2. Is dependency injection really simpler/better than $serializer = new Serializer($normalizers, $encoders);? I mean, you probably need to do some configuration anyway (i.e. DateTime export settings)...
    If YES: Include more examples on /serializer.rst on how to do the configuration in services.yaml.
    If NO: Say that instantiation is the preferred method, and only show dependency injection as a handy alternative for some (which?) cases.

  3. So everything Doctrine- or (entity-) related needs to be on /serializer.rst? Do you agree that serializing an entity from the database is the most probable use-case?

@javiereguiluz
Copy link
Member

@ThomasLandauer those are great questions ... but the Serializer component is not my strong suit so I can't answer to them.

Let's ask to our doc maintainers @wouterj and @xabbuh ... and also to Serializer and Symfony experts @dunglas and @Simperfit. Thanks!

@dunglas
Copy link
Member

dunglas commented Jun 19, 2018

For the record I'm 👍 to merge both pages, and add examples explaining how to use features using the full stack framework, then example on how to initialize the required class in component mode.

If we don't merge it:

  1. The component doc definitely more relevant
  2. I don't understand what you mean, can you detail?
  3. To me it's an important use case, but not the most relevant use case, it's one use case among a lot of others (consuming an external web API, serializing classes coming from Elastic/Mongo/Firebase/whatever
Using the Serializer Service
----------------------------
The serializer's constructor takes two arguments:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't merge both pages, it should be in the component page, not here.

public function index()
{
// keep reading for usage examples
$serializer = new Serializer(array(new DateTimeNormalizer('Y-m-d')), array(new CsvEncoder()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎, when using the full stack framework, the service registered by FrameworkBundle should alway be used. Here you don't benefit from the cache layer, groups, max depth...
Initializing the component manually belongs to the component docs.

getters (``getXxx()``), issers (``isXxx()``) or hassers (``hasXxx()``) to read
properties and setters (``setXxx()``) to change properties

And these encoders:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true, they are automatically registered (to usr the YAML encoder, the Yaml component must be installed): https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml#L112-L118


These normalizers need to be loaded manually:

* :class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer` a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not mention this normalizer here. We'll maybe deprecate it at some point.

:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`. It's also
possible to set the priority of the tag in order to decide the matching order.

Here is an example on how to load the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to drop this block, but I'll not mention it in this documentation (why not in the component one, but it's confusion for frameworkbundle users)

@ThomasLandauer
Copy link
Contributor Author

For the record I'm +1 to merge both pages

So should we wait for additional opinions or go ahead and start merging?

  1. Is basically answered by "when using the full stack framework, the service registered by FrameworkBundle should alway be used."
    But please tell me how to do configuration (e.g. the equivalent to new DateTimeNormalizer('Y-m-d')) when using the service.

I'm ignoring your other comments for now - till the big question (merge?) is answered :-)

@dunglas
Copy link
Member

dunglas commented Jun 19, 2018

But please tell me how to do configuration (e.g. the equivalent to new DateTimeNormalizer('Y-m-d')) when using the service.

To configure it globally, you have to override the service definition:

# config/services.yaml serializer.normalizer.datetime: class: Symfony\Component\Serializer\Normalizer\DateTimeNormalizer arguments: ['Y-m-d'] tags: [{name: serializer.normalizer, priority: -910}]

Alternatively, you can change the format using the datetime_format context option (a datetime_timezone context option is also available): https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php#L54

@javiereguiluz
Copy link
Member

For the record I'm +1 to merge both pages

So should we wait for additional opinions or go ahead and start merging?

If you are thinking about deleting one of the two pages, that's not possible. We must maintain the component page for sure ... and the main article too (if it's still relevant). For some components we don't have a main page: e.g. DomCrawler ... we only mention it briefly in the main testing.rst page ... but all its docs are in components/* If you think that there's nothing to say about using Serializer into Symfony, we can then remove the main page. But I highly doubt that. Thanks!

@weaverryan
Copy link
Member

Hi guys!

Thanks for the PR - let's fix this! First, I think we do need both articles. Typically, we put most of the documentation into the framework document and then only put the details about how to instantiate & setup the objects in the component documentation. To say it differently, the framework is the first class citizen. If you're using a component, we need to give you the details on how to set things up, but for usage, you will need to go look at the framework docs (which, besides how you get/instantiate the object, the usage is the same).

Translation is a pretty good example:

For the serializer, I think we should do this in 3 steps (could be 3 PRs or 1 PR):

  1. Rewrite the framework docs
  2. Move some more advanced topics from the component into sub-articles below the framework docs
  3. Refactor (remove most of) the component docs

For step (2) [rewrite the framework documentation], we should probably steal a lot from the component documentation, which is much more complete (it has a diagram, shows an example class, shows serializing/deserializing objects). For the first "draft", we should probably just include the following topics:

  • Installation
  • Fetching the service
  • showing a class
  • Showing how to serialize that class
  • Showing how to deserialize
  • Showing serialization groups

Does anyone disagree or have any thoughts? @ThomasLandauer As we're all quite busy, we would LOVE to have your help with this. It's very important - we just need more good people to help!

@javiereguiluz
Copy link
Member

@ThomasLandauer I'd love to see this pull request move forward. However, in my experience, pull requests that try to do too many things always fail: too many merge conflicts, endless discussions, etc.

So, if you have some time for this, could you send a small pull request to fix the most urgent problems of this article ... and later, if needed, submit other PRs to fix further things? Thanks!

@javiereguiluz
Copy link
Member

It's sad but I'm going to close this PR without merging because it has too many conflicts, unrelated changes, targerts an unmaintained branch, etc.

@ThomasLandauer I'm really sorry. I hope you can recover some of your commits and apply them to 4.1 branch so we can review and merge. If you do so, please try to do not many changes in order to ease reviewing it. Thanks a lot!

@ThomasLandauer ThomasLandauer deleted the patch-14 branch September 28, 2021 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment