8000 Fixing serializer config - much is now done automatically by weaverryan · Pull Request #8710 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Fixing serializer config - much is now done automatically #8710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixing serializer config - much is now done automatically
  • Loading branch information
weaverryan committed Nov 21, 2017
commit cb319009f3bf97b8a7674d00fef7bda62293f0ab
15 changes: 0 additions & 15 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ Configuration
* `debug`_
* `serializer`_
* :ref:`enabled <reference-serializer-enabled>`
* :ref:`cache <reference-serializer-cache>`
* :ref:`enable_annotations <reference-serializer-enable_annotations>`
* :ref:`name_converter <reference-serializer-name_converter>`
* :ref:`circular_reference_handler <reference-serializer-circular_reference_handler>`
Expand Down Expand Up @@ -1656,20 +1655,6 @@ enabled

Whether to enable the ``serializer`` service or not in the service container.

.. _reference-serializer-cache:

cache
.....

**type**: ``string``

The service that is used to persist class metadata in a cache. The service
has to implement the ``Doctrine\Common\Cache\Cache`` interface.

.. seealso::

For more information, see :ref:`serializer-enabling-metadata-cache`.

.. _reference-serializer-enable_annotations:

enable_annotations
Expand Down
136 changes: 7 additions & 129 deletions serializer.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,6 @@ Before using the serializer, run this command to install it in your application:

$ composer require serializer

Then, enable the serializer in the framework config:

.. configuration-block::

.. code-block:: yaml

# config/packages/framework.yaml
framework:
# ...
serializer: { enable_annotations: true }
# Alternatively, if you don't want to use annotations
#serializer: { enabled: true }

.. code-block:: xml

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<!-- ... -->
<framework:serializer enable-annotations="true" />
<!--
Alternatively, if you don't want to use annotations
<framework:serializer enabled="true" />
-->
</framework:config>
</container>

.. code-block:: php

// config/packages/framework.php
$container->loadFromExtension('framework', array(
// ...
'serializer' => array(
'enable_annotations' => true,
// Alternatively, if you don't want to use annotations
//'enabled' => true,
),
));

Using the Serializer Service
----------------------------

Expand Down Expand Up @@ -147,46 +101,11 @@ Here is an example on how to load the
Using Serialization Groups Annotations
--------------------------------------

Enable :ref:`serialization groups annotation <component-serializer-attributes-groups>`
with the following configuration:

.. configuration-block::

.. code-block:: yaml

# config/packages/framework.yaml
framework:
# ...
serializer:
enable_annotations: true

.. code-block:: xml

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<!-- ... -->
<framework:serializer enable-annotations="true" />
</framework:config>
</container>
To use annotations, first install the annotations package:

.. code-block:: php
.. code-block:: terminal

// config/packages/framework.php
$container->loadFromExtension('framework', array(
// ...
'serializer' => array(
'enable_annotations' => true,
),
));
$ composer require annotations

Next, add the :ref:`@Groups annotations <component-serializer-attributes-groups-annotations>`
to your class and choose which groups to use when serializing::
Expand All @@ -207,52 +126,11 @@ stored in one of the following locations:

.. _serializer-enabling-metadata-cache:

Enabling the Metadata Cache
---------------------------

Metadata used by the Serializer component such as groups can be cached to
enhance application performance. Any service implementing the ``Doctrine\Common\Cache\Cache``
interface can be used.

A service leveraging `APCu`_ (and APC for PHP < 5.5) is built-in.

.. configuration-block::

.. code-block:: yaml
Configruing the Metadata Cache
Copy link
Member

Choose a reason for hiding this comment

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

Configuring

------------------------------

# config/packages/prod/framework.yaml
framework:
# ...
serializer:
cache: serializer.mapping.cache.apc

.. code-block:: xml

<!-- config/packages/prod/framework.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<!-- ... -->
<framework:serializer cache="serializer.mapping.cache.apc" />
</framework:config>
</container>

.. code-block:: php

// config/packages/prod/framework.php
$container->loadFromExtension('framework', array(
// ...
'serializer' => array(
'cache' => 'serializer.mapping.cache.apc',
),
));
The metadata for the serializer is automatically cached. To configure the cache,
configure the ``framework.cache.pools`` key in ``config/packages/framework.yaml``.
Copy link
Member

Choose a reason for hiding this comment

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

Can't we link to another document here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha! I'm happy you said that. No, there is no better link yet, because we're missing some cache docs! When I hit this, I already created #8711 and linked back to this, so we can improve it later :)


Enabling a Name Converter
-------------------------
Expand Down
0